]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.17.6-201412142110.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.17.6-201412142110.patch
CommitLineData
3050544a
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 bb43e9e..9dfc034 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..2e964a2 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 *(const volatile int *)&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 ce73ab6..7310f8a 100644
2271--- a/arch/arm/include/asm/thread_info.h
2272+++ b/arch/arm/include/asm/thread_info.h
2273@@ -78,9 +78,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@@ -154,7 +154,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@@ -168,10 +172,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 bea63f5..bc660a7 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@@ -860,7 +865,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 044b511..afd1da8 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 7eb94e6..799ad3e 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@@ -798,7 +800,7 @@ config NEED_KUSER_HELPERS
3896
3897 config KUSER_HELPERS
3898 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3899- depends on MMU
3900+ depends on MMU && (!(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND)
3901 default y
3902 help
3903 Warning: disabling this option may break user programs.
3904@@ -812,7 +814,7 @@ config KUSER_HELPERS
3905 See Documentation/arm/kernel_user_helpers.txt for details.
3906
3907 However, the fixed address nature of these helpers can be used
3908- by ROP (return orientated programming) authors when creating
3909+ by ROP (Return Oriented Programming) authors when creating
3910 exploits.
3911
3912 If all of the binaries and libraries which run on your platform
3913diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3914index 83792f4..c25d36b 100644
3915--- a/arch/arm/mm/alignment.c
3916+++ b/arch/arm/mm/alignment.c
3917@@ -216,10 +216,12 @@ union offset_union {
3918 #define __get16_unaligned_check(ins,val,addr) \
3919 do { \
3920 unsigned int err = 0, v, a = addr; \
3921+ pax_open_userland(); \
3922 __get8_unaligned_check(ins,v,a,err); \
3923 val = v << ((BE) ? 8 : 0); \
3924 __get8_unaligned_check(ins,v,a,err); \
3925 val |= v << ((BE) ? 0 : 8); \
3926+ pax_close_userland(); \
3927 if (err) \
3928 goto fault; \
3929 } while (0)
3930@@ -233,6 +235,7 @@ union offset_union {
3931 #define __get32_unaligned_check(ins,val,addr) \
3932 do { \
3933 unsigned int err = 0, v, a = addr; \
3934+ pax_open_userland(); \
3935 __get8_unaligned_check(ins,v,a,err); \
3936 val = v << ((BE) ? 24 : 0); \
3937 __get8_unaligned_check(ins,v,a,err); \
3938@@ -241,6 +244,7 @@ union offset_union {
3939 val |= v << ((BE) ? 8 : 16); \
3940 __get8_unaligned_check(ins,v,a,err); \
3941 val |= v << ((BE) ? 0 : 24); \
3942+ pax_close_userland(); \
3943 if (err) \
3944 goto fault; \
3945 } while (0)
3946@@ -254,6 +258,7 @@ union offset_union {
3947 #define __put16_unaligned_check(ins,val,addr) \
3948 do { \
3949 unsigned int err = 0, v = val, a = addr; \
3950+ pax_open_userland(); \
3951 __asm__( FIRST_BYTE_16 \
3952 ARM( "1: "ins" %1, [%2], #1\n" ) \
3953 THUMB( "1: "ins" %1, [%2]\n" ) \
3954@@ -273,6 +278,7 @@ union offset_union {
3955 " .popsection\n" \
3956 : "=r" (err), "=&r" (v), "=&r" (a) \
3957 : "0" (err), "1" (v), "2" (a)); \
3958+ pax_close_userland(); \
3959 if (err) \
3960 goto fault; \
3961 } while (0)
3962@@ -286,6 +292,7 @@ union offset_union {
3963 #define __put32_unaligned_check(ins,val,addr) \
3964 do { \
3965 unsigned int err = 0, v = val, a = addr; \
3966+ pax_open_userland(); \
3967 __asm__( FIRST_BYTE_32 \
3968 ARM( "1: "ins" %1, [%2], #1\n" ) \
3969 THUMB( "1: "ins" %1, [%2]\n" ) \
3970@@ -315,6 +322,7 @@ union offset_union {
3971 " .popsection\n" \
3972 : "=r" (err), "=&r" (v), "=&r" (a) \
3973 : "0" (err), "1" (v), "2" (a)); \
3974+ pax_close_userland(); \
3975 if (err) \
3976 goto fault; \
3977 } while (0)
3978diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3979index 5f2c988..221412d 100644
3980--- a/arch/arm/mm/cache-l2x0.c
3981+++ b/arch/arm/mm/cache-l2x0.c
3982@@ -41,7 +41,7 @@ struct l2c_init_data {
3983 void (*fixup)(void __iomem *, u32, struct outer_cache_fns *);
3984 void (*save)(void __iomem *);
3985 struct outer_cache_fns outer_cache;
3986-};
3987+} __do_const;
3988
3989 #define CACHE_LINE_SIZE 32
3990
3991diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3992index 6eb97b3..ac509f6 100644
3993--- a/arch/arm/mm/context.c
3994+++ b/arch/arm/mm/context.c
3995@@ -43,7 +43,7 @@
3996 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3997
3998 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3999-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
4000+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
4001 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
4002
4003 static DEFINE_PER_CPU(atomic64_t, active_asids);
4004@@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
4005 {
4006 static u32 cur_idx = 1;
4007 u64 asid = atomic64_read(&mm->context.id);
4008- u64 generation = atomic64_read(&asid_generation);
4009+ u64 generation = atomic64_read_unchecked(&asid_generation);
4010
4011 if (asid != 0 && is_reserved_asid(asid)) {
4012 /*
4013@@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
4014 */
4015 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
4016 if (asid == NUM_USER_ASIDS) {
4017- generation = atomic64_add_return(ASID_FIRST_VERSION,
4018+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
4019 &asid_generation);
4020 flush_context(cpu);
4021 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
4022@@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
4023 cpu_set_reserved_ttbr0();
4024
4025 asid = atomic64_read(&mm->context.id);
4026- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
4027+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
4028 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
4029 goto switch_mm_fastpath;
4030
4031 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
4032 /* Check that our ASID belongs to the current generation. */
4033 asid = atomic64_read(&mm->context.id);
4034- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
4035+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
4036 asid = new_context(mm, cpu);
4037 atomic64_set(&mm->context.id, asid);
4038 }
4039diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
4040index eb8830a..e8ff52e 100644
4041--- a/arch/arm/mm/fault.c
4042+++ b/arch/arm/mm/fault.c
4043@@ -25,6 +25,7 @@
4044 #include <asm/system_misc.h>
4045 #include <asm/system_info.h>
4046 #include <asm/tlbflush.h>
4047+#include <asm/sections.h>
4048
4049 #include "fault.h"
4050
4051@@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
4052 if (fixup_exception(regs))
4053 return;
4054
4055+#ifdef CONFIG_PAX_MEMORY_UDEREF
4056+ if (addr < TASK_SIZE) {
4057+ if (current->signal->curr_ip)
4058+ 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),
4059+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4060+ else
4061+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4062+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4063+ }
4064+#endif
4065+
4066+#ifdef CONFIG_PAX_KERNEXEC
4067+ if ((fsr & FSR_WRITE) &&
4068+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
4069+ (MODULES_VADDR <= addr && addr < MODULES_END)))
4070+ {
4071+ if (current->signal->curr_ip)
4072+ 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),
4073+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
4074+ else
4075+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
4076+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
4077+ }
4078+#endif
4079+
4080 /*
4081 * No handler, we'll have to terminate things with extreme prejudice.
4082 */
4083@@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
4084 }
4085 #endif
4086
4087+#ifdef CONFIG_PAX_PAGEEXEC
4088+ if (fsr & FSR_LNX_PF) {
4089+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
4090+ do_group_exit(SIGKILL);
4091+ }
4092+#endif
4093+
4094 tsk->thread.address = addr;
4095 tsk->thread.error_code = fsr;
4096 tsk->thread.trap_no = 14;
4097@@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4098 }
4099 #endif /* CONFIG_MMU */
4100
4101+#ifdef CONFIG_PAX_PAGEEXEC
4102+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4103+{
4104+ long i;
4105+
4106+ printk(KERN_ERR "PAX: bytes at PC: ");
4107+ for (i = 0; i < 20; i++) {
4108+ unsigned char c;
4109+ if (get_user(c, (__force unsigned char __user *)pc+i))
4110+ printk(KERN_CONT "?? ");
4111+ else
4112+ printk(KERN_CONT "%02x ", c);
4113+ }
4114+ printk("\n");
4115+
4116+ printk(KERN_ERR "PAX: bytes at SP-4: ");
4117+ for (i = -1; i < 20; i++) {
4118+ unsigned long c;
4119+ if (get_user(c, (__force unsigned long __user *)sp+i))
4120+ printk(KERN_CONT "???????? ");
4121+ else
4122+ printk(KERN_CONT "%08lx ", c);
4123+ }
4124+ printk("\n");
4125+}
4126+#endif
4127+
4128 /*
4129 * First Level Translation Fault Handler
4130 *
4131@@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4132 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
4133 struct siginfo info;
4134
4135+#ifdef CONFIG_PAX_MEMORY_UDEREF
4136+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
4137+ if (current->signal->curr_ip)
4138+ 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),
4139+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4140+ else
4141+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4142+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4143+ goto die;
4144+ }
4145+#endif
4146+
4147 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
4148 return;
4149
4150+die:
4151 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
4152 inf->name, fsr, addr);
4153
4154@@ -574,15 +647,104 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
4155 ifsr_info[nr].name = name;
4156 }
4157
4158+asmlinkage int sys_sigreturn(struct pt_regs *regs);
4159+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4160+
4161 asmlinkage void __exception
4162 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4163 {
4164 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4165 struct siginfo info;
4166+ unsigned long pc = instruction_pointer(regs);
4167+
4168+ if (user_mode(regs)) {
4169+ unsigned long sigpage = current->mm->context.sigpage;
4170+
4171+ if (sigpage <= pc && pc < sigpage + 7*4) {
4172+ if (pc < sigpage + 3*4)
4173+ sys_sigreturn(regs);
4174+ else
4175+ sys_rt_sigreturn(regs);
4176+ return;
4177+ }
4178+ if (pc == 0xffff0f60UL) {
4179+ /*
4180+ * PaX: __kuser_cmpxchg64 emulation
4181+ */
4182+ // TODO
4183+ //regs->ARM_pc = regs->ARM_lr;
4184+ //return;
4185+ }
4186+ if (pc == 0xffff0fa0UL) {
4187+ /*
4188+ * PaX: __kuser_memory_barrier emulation
4189+ */
4190+ // dmb(); implied by the exception
4191+ regs->ARM_pc = regs->ARM_lr;
4192+ return;
4193+ }
4194+ if (pc == 0xffff0fc0UL) {
4195+ /*
4196+ * PaX: __kuser_cmpxchg emulation
4197+ */
4198+ // TODO
4199+ //long new;
4200+ //int op;
4201+
4202+ //op = FUTEX_OP_SET << 28;
4203+ //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4204+ //regs->ARM_r0 = old != new;
4205+ //regs->ARM_pc = regs->ARM_lr;
4206+ //return;
4207+ }
4208+ if (pc == 0xffff0fe0UL) {
4209+ /*
4210+ * PaX: __kuser_get_tls emulation
4211+ */
4212+ regs->ARM_r0 = current_thread_info()->tp_value[0];
4213+ regs->ARM_pc = regs->ARM_lr;
4214+ return;
4215+ }
4216+ }
4217+
4218+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4219+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4220+ if (current->signal->curr_ip)
4221+ 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),
4222+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4223+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4224+ else
4225+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4226+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4227+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4228+ goto die;
4229+ }
4230+#endif
4231+
4232+#ifdef CONFIG_PAX_REFCOUNT
4233+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4234+#ifdef CONFIG_THUMB2_KERNEL
4235+ unsigned short bkpt;
4236+
4237+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le16(bkpt) == 0xbef1) {
4238+#else
4239+ unsigned int bkpt;
4240+
4241+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4242+#endif
4243+ current->thread.error_code = ifsr;
4244+ current->thread.trap_no = 0;
4245+ pax_report_refcount_overflow(regs);
4246+ fixup_exception(regs);
4247+ return;
4248+ }
4249+ }
4250+#endif
4251
4252 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4253 return;
4254
4255+die:
4256 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4257 inf->name, ifsr, addr);
4258
4259diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4260index cf08bdf..772656c 100644
4261--- a/arch/arm/mm/fault.h
4262+++ b/arch/arm/mm/fault.h
4263@@ -3,6 +3,7 @@
4264
4265 /*
4266 * Fault status register encodings. We steal bit 31 for our own purposes.
4267+ * Set when the FSR value is from an instruction fault.
4268 */
4269 #define FSR_LNX_PF (1 << 31)
4270 #define FSR_WRITE (1 << 11)
4271@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4272 }
4273 #endif
4274
4275+/* valid for LPAE and !LPAE */
4276+static inline int is_xn_fault(unsigned int fsr)
4277+{
4278+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4279+}
4280+
4281+static inline int is_domain_fault(unsigned int fsr)
4282+{
4283+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4284+}
4285+
4286 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4287 unsigned long search_exception_table(unsigned long addr);
4288
4289diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4290index 659c75d..6f8c029 100644
4291--- a/arch/arm/mm/init.c
4292+++ b/arch/arm/mm/init.c
4293@@ -31,6 +31,8 @@
4294 #include <asm/setup.h>
4295 #include <asm/tlb.h>
4296 #include <asm/fixmap.h>
4297+#include <asm/system_info.h>
4298+#include <asm/cp15.h>
4299
4300 #include <asm/mach/arch.h>
4301 #include <asm/mach/map.h>
4302@@ -619,7 +621,46 @@ void free_initmem(void)
4303 {
4304 #ifdef CONFIG_HAVE_TCM
4305 extern char __tcm_start, __tcm_end;
4306+#endif
4307
4308+#ifdef CONFIG_PAX_KERNEXEC
4309+ unsigned long addr;
4310+ pgd_t *pgd;
4311+ pud_t *pud;
4312+ pmd_t *pmd;
4313+ int cpu_arch = cpu_architecture();
4314+ unsigned int cr = get_cr();
4315+
4316+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4317+ /* make pages tables, etc before .text NX */
4318+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4319+ pgd = pgd_offset_k(addr);
4320+ pud = pud_offset(pgd, addr);
4321+ pmd = pmd_offset(pud, addr);
4322+ __section_update(pmd, addr, PMD_SECT_XN);
4323+ }
4324+ /* make init NX */
4325+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4326+ pgd = pgd_offset_k(addr);
4327+ pud = pud_offset(pgd, addr);
4328+ pmd = pmd_offset(pud, addr);
4329+ __section_update(pmd, addr, PMD_SECT_XN);
4330+ }
4331+ /* make kernel code/rodata RX */
4332+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4333+ pgd = pgd_offset_k(addr);
4334+ pud = pud_offset(pgd, addr);
4335+ pmd = pmd_offset(pud, addr);
4336+#ifdef CONFIG_ARM_LPAE
4337+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4338+#else
4339+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4340+#endif
4341+ }
4342+ }
4343+#endif
4344+
4345+#ifdef CONFIG_HAVE_TCM
4346 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4347 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4348 #endif
4349diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4350index d1e5ad7..84dcbf2 100644
4351--- a/arch/arm/mm/ioremap.c
4352+++ b/arch/arm/mm/ioremap.c
4353@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4354 unsigned int mtype;
4355
4356 if (cached)
4357- mtype = MT_MEMORY_RWX;
4358+ mtype = MT_MEMORY_RX;
4359 else
4360- mtype = MT_MEMORY_RWX_NONCACHED;
4361+ mtype = MT_MEMORY_RX_NONCACHED;
4362
4363 return __arm_ioremap_caller(phys_addr, size, mtype,
4364 __builtin_return_address(0));
4365diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4366index 5e85ed3..b10a7ed 100644
4367--- a/arch/arm/mm/mmap.c
4368+++ b/arch/arm/mm/mmap.c
4369@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4370 struct vm_area_struct *vma;
4371 int do_align = 0;
4372 int aliasing = cache_is_vipt_aliasing();
4373+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4374 struct vm_unmapped_area_info info;
4375
4376 /*
4377@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4378 if (len > TASK_SIZE)
4379 return -ENOMEM;
4380
4381+#ifdef CONFIG_PAX_RANDMMAP
4382+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4383+#endif
4384+
4385 if (addr) {
4386 if (do_align)
4387 addr = COLOUR_ALIGN(addr, pgoff);
4388@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4389 addr = PAGE_ALIGN(addr);
4390
4391 vma = find_vma(mm, addr);
4392- if (TASK_SIZE - len >= addr &&
4393- (!vma || addr + len <= vma->vm_start))
4394+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4395 return addr;
4396 }
4397
4398@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4399 info.high_limit = TASK_SIZE;
4400 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4401 info.align_offset = pgoff << PAGE_SHIFT;
4402+ info.threadstack_offset = offset;
4403 return vm_unmapped_area(&info);
4404 }
4405
4406@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4407 unsigned long addr = addr0;
4408 int do_align = 0;
4409 int aliasing = cache_is_vipt_aliasing();
4410+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4411 struct vm_unmapped_area_info info;
4412
4413 /*
4414@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4415 return addr;
4416 }
4417
4418+#ifdef CONFIG_PAX_RANDMMAP
4419+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4420+#endif
4421+
4422 /* requesting a specific address */
4423 if (addr) {
4424 if (do_align)
4425@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4426 else
4427 addr = PAGE_ALIGN(addr);
4428 vma = find_vma(mm, addr);
4429- if (TASK_SIZE - len >= addr &&
4430- (!vma || addr + len <= vma->vm_start))
4431+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4432 return addr;
4433 }
4434
4435@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4436 info.high_limit = mm->mmap_base;
4437 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4438 info.align_offset = pgoff << PAGE_SHIFT;
4439+ info.threadstack_offset = offset;
4440 addr = vm_unmapped_area(&info);
4441
4442 /*
4443@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4444 {
4445 unsigned long random_factor = 0UL;
4446
4447+#ifdef CONFIG_PAX_RANDMMAP
4448+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4449+#endif
4450+
4451 /* 8 bits of randomness in 20 address space bits */
4452 if ((current->flags & PF_RANDOMIZE) &&
4453 !(current->personality & ADDR_NO_RANDOMIZE))
4454@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4455
4456 if (mmap_is_legacy()) {
4457 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4458+
4459+#ifdef CONFIG_PAX_RANDMMAP
4460+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4461+ mm->mmap_base += mm->delta_mmap;
4462+#endif
4463+
4464 mm->get_unmapped_area = arch_get_unmapped_area;
4465 } else {
4466 mm->mmap_base = mmap_base(random_factor);
4467+
4468+#ifdef CONFIG_PAX_RANDMMAP
4469+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4470+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4471+#endif
4472+
4473 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4474 }
4475 }
4476diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4477index 8348ed6..b73a807 100644
4478--- a/arch/arm/mm/mmu.c
4479+++ b/arch/arm/mm/mmu.c
4480@@ -40,6 +40,22 @@
4481 #include "mm.h"
4482 #include "tcm.h"
4483
4484+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4485+void modify_domain(unsigned int dom, unsigned int type)
4486+{
4487+ struct thread_info *thread = current_thread_info();
4488+ unsigned int domain = thread->cpu_domain;
4489+ /*
4490+ * DOMAIN_MANAGER might be defined to some other value,
4491+ * use the arch-defined constant
4492+ */
4493+ domain &= ~domain_val(dom, 3);
4494+ thread->cpu_domain = domain | domain_val(dom, type);
4495+ set_domain(thread->cpu_domain);
4496+}
4497+EXPORT_SYMBOL(modify_domain);
4498+#endif
4499+
4500 /*
4501 * empty_zero_page is a special page that is used for
4502 * zero-initialized data and COW.
4503@@ -239,7 +255,15 @@ __setup("noalign", noalign_setup);
4504 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4505 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4506
4507-static struct mem_type mem_types[] = {
4508+#ifdef CONFIG_PAX_KERNEXEC
4509+#define L_PTE_KERNEXEC L_PTE_RDONLY
4510+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4511+#else
4512+#define L_PTE_KERNEXEC L_PTE_DIRTY
4513+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4514+#endif
4515+
4516+static struct mem_type mem_types[] __read_only = {
4517 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4518 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4519 L_PTE_SHARED,
4520@@ -268,19 +292,19 @@ static struct mem_type mem_types[] = {
4521 .prot_sect = PROT_SECT_DEVICE,
4522 .domain = DOMAIN_IO,
4523 },
4524- [MT_UNCACHED] = {
4525+ [MT_UNCACHED_RW] = {
4526 .prot_pte = PROT_PTE_DEVICE,
4527 .prot_l1 = PMD_TYPE_TABLE,
4528 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4529 .domain = DOMAIN_IO,
4530 },
4531- [MT_CACHECLEAN] = {
4532- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4533+ [MT_CACHECLEAN_RO] = {
4534+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4535 .domain = DOMAIN_KERNEL,
4536 },
4537 #ifndef CONFIG_ARM_LPAE
4538- [MT_MINICLEAN] = {
4539- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4540+ [MT_MINICLEAN_RO] = {
4541+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4542 .domain = DOMAIN_KERNEL,
4543 },
4544 #endif
4545@@ -288,15 +312,15 @@ static struct mem_type mem_types[] = {
4546 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4547 L_PTE_RDONLY,
4548 .prot_l1 = PMD_TYPE_TABLE,
4549- .domain = DOMAIN_USER,
4550+ .domain = DOMAIN_VECTORS,
4551 },
4552 [MT_HIGH_VECTORS] = {
4553 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4554 L_PTE_USER | L_PTE_RDONLY,
4555 .prot_l1 = PMD_TYPE_TABLE,
4556- .domain = DOMAIN_USER,
4557+ .domain = DOMAIN_VECTORS,
4558 },
4559- [MT_MEMORY_RWX] = {
4560+ [__MT_MEMORY_RWX] = {
4561 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4562 .prot_l1 = PMD_TYPE_TABLE,
4563 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4564@@ -309,17 +333,30 @@ static struct mem_type mem_types[] = {
4565 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4566 .domain = DOMAIN_KERNEL,
4567 },
4568- [MT_ROM] = {
4569- .prot_sect = PMD_TYPE_SECT,
4570+ [MT_MEMORY_RX] = {
4571+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4572+ .prot_l1 = PMD_TYPE_TABLE,
4573+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4574+ .domain = DOMAIN_KERNEL,
4575+ },
4576+ [MT_ROM_RX] = {
4577+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4578 .domain = DOMAIN_KERNEL,
4579 },
4580- [MT_MEMORY_RWX_NONCACHED] = {
4581+ [MT_MEMORY_RW_NONCACHED] = {
4582 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4583 L_PTE_MT_BUFFERABLE,
4584 .prot_l1 = PMD_TYPE_TABLE,
4585 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4586 .domain = DOMAIN_KERNEL,
4587 },
4588+ [MT_MEMORY_RX_NONCACHED] = {
4589+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4590+ L_PTE_MT_BUFFERABLE,
4591+ .prot_l1 = PMD_TYPE_TABLE,
4592+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4593+ .domain = DOMAIN_KERNEL,
4594+ },
4595 [MT_MEMORY_RW_DTCM] = {
4596 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4597 L_PTE_XN,
4598@@ -327,9 +364,10 @@ static struct mem_type mem_types[] = {
4599 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4600 .domain = DOMAIN_KERNEL,
4601 },
4602- [MT_MEMORY_RWX_ITCM] = {
4603- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4604+ [MT_MEMORY_RX_ITCM] = {
4605+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4606 .prot_l1 = PMD_TYPE_TABLE,
4607+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4608 .domain = DOMAIN_KERNEL,
4609 },
4610 [MT_MEMORY_RW_SO] = {
4611@@ -547,9 +585,14 @@ static void __init build_mem_type_table(void)
4612 * Mark cache clean areas and XIP ROM read only
4613 * from SVC mode and no access from userspace.
4614 */
4615- mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4616- mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4617- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4618+ mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4619+#ifdef CONFIG_PAX_KERNEXEC
4620+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4621+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4622+ mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4623+#endif
4624+ mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4625+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4626 #endif
4627
4628 /*
4629@@ -566,13 +609,17 @@ static void __init build_mem_type_table(void)
4630 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4631 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4632 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4633- mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4634- mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4635+ mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4636+ mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4637 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4638 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4639+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4640+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4641 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4642- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4643- mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4644+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4645+ mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4646+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4647+ mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4648 }
4649 }
4650
4651@@ -583,15 +630,20 @@ static void __init build_mem_type_table(void)
4652 if (cpu_arch >= CPU_ARCH_ARMv6) {
4653 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4654 /* Non-cacheable Normal is XCB = 001 */
4655- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4656+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4657+ PMD_SECT_BUFFERED;
4658+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4659 PMD_SECT_BUFFERED;
4660 } else {
4661 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4662- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4663+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4664+ PMD_SECT_TEX(1);
4665+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4666 PMD_SECT_TEX(1);
4667 }
4668 } else {
4669- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4670+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4671+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4672 }
4673
4674 #ifdef CONFIG_ARM_LPAE
4675@@ -607,6 +659,8 @@ static void __init build_mem_type_table(void)
4676 vecs_pgprot |= PTE_EXT_AF;
4677 #endif
4678
4679+ user_pgprot |= __supported_pte_mask;
4680+
4681 for (i = 0; i < 16; i++) {
4682 pteval_t v = pgprot_val(protection_map[i]);
4683 protection_map[i] = __pgprot(v | user_pgprot);
4684@@ -624,21 +678,24 @@ static void __init build_mem_type_table(void)
4685
4686 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4687 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4688- mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4689- mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4690+ mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4691+ mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4692 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4693 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4694+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4695+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4696 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4697- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4698- mem_types[MT_ROM].prot_sect |= cp->pmd;
4699+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4700+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4701+ mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4702
4703 switch (cp->pmd) {
4704 case PMD_SECT_WT:
4705- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4706+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4707 break;
4708 case PMD_SECT_WB:
4709 case PMD_SECT_WBWA:
4710- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4711+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4712 break;
4713 }
4714 pr_info("Memory policy: %sData cache %s\n",
4715@@ -856,7 +913,7 @@ static void __init create_mapping(struct map_desc *md)
4716 return;
4717 }
4718
4719- if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4720+ if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4721 md->virtual >= PAGE_OFFSET &&
4722 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4723 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4724@@ -1224,18 +1281,15 @@ void __init arm_mm_memblock_reserve(void)
4725 * called function. This means you can't use any function or debugging
4726 * method which may touch any device, otherwise the kernel _will_ crash.
4727 */
4728+
4729+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4730+
4731 static void __init devicemaps_init(const struct machine_desc *mdesc)
4732 {
4733 struct map_desc map;
4734 unsigned long addr;
4735- void *vectors;
4736
4737- /*
4738- * Allocate the vector page early.
4739- */
4740- vectors = early_alloc(PAGE_SIZE * 2);
4741-
4742- early_trap_init(vectors);
4743+ early_trap_init(&vectors);
4744
4745 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4746 pmd_clear(pmd_off_k(addr));
4747@@ -1248,7 +1302,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4748 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4749 map.virtual = MODULES_VADDR;
4750 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4751- map.type = MT_ROM;
4752+ map.type = MT_ROM_RX;
4753 create_mapping(&map);
4754 #endif
4755
4756@@ -1259,14 +1313,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4757 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4758 map.virtual = FLUSH_BASE;
4759 map.length = SZ_1M;
4760- map.type = MT_CACHECLEAN;
4761+ map.type = MT_CACHECLEAN_RO;
4762 create_mapping(&map);
4763 #endif
4764 #ifdef FLUSH_BASE_MINICACHE
4765 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4766 map.virtual = FLUSH_BASE_MINICACHE;
4767 map.length = SZ_1M;
4768- map.type = MT_MINICLEAN;
4769+ map.type = MT_MINICLEAN_RO;
4770 create_mapping(&map);
4771 #endif
4772
4773@@ -1275,7 +1329,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4774 * location (0xffff0000). If we aren't using high-vectors, also
4775 * create a mapping at the low-vectors virtual address.
4776 */
4777- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4778+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4779 map.virtual = 0xffff0000;
4780 map.length = PAGE_SIZE;
4781 #ifdef CONFIG_KUSER_HELPERS
4782@@ -1335,8 +1389,10 @@ static void __init kmap_init(void)
4783 static void __init map_lowmem(void)
4784 {
4785 struct memblock_region *reg;
4786+#ifndef CONFIG_PAX_KERNEXEC
4787 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4788 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4789+#endif
4790
4791 /* Map all the lowmem memory banks. */
4792 for_each_memblock(memory, reg) {
4793@@ -1349,11 +1405,48 @@ static void __init map_lowmem(void)
4794 if (start >= end)
4795 break;
4796
4797+#ifdef CONFIG_PAX_KERNEXEC
4798+ map.pfn = __phys_to_pfn(start);
4799+ map.virtual = __phys_to_virt(start);
4800+ map.length = end - start;
4801+
4802+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4803+ struct map_desc kernel;
4804+ struct map_desc initmap;
4805+
4806+ /* when freeing initmem we will make this RW */
4807+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4808+ initmap.virtual = (unsigned long)__init_begin;
4809+ initmap.length = _sdata - __init_begin;
4810+ initmap.type = __MT_MEMORY_RWX;
4811+ create_mapping(&initmap);
4812+
4813+ /* when freeing initmem we will make this RX */
4814+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4815+ kernel.virtual = (unsigned long)_stext;
4816+ kernel.length = __init_begin - _stext;
4817+ kernel.type = __MT_MEMORY_RWX;
4818+ create_mapping(&kernel);
4819+
4820+ if (map.virtual < (unsigned long)_stext) {
4821+ map.length = (unsigned long)_stext - map.virtual;
4822+ map.type = __MT_MEMORY_RWX;
4823+ create_mapping(&map);
4824+ }
4825+
4826+ map.pfn = __phys_to_pfn(__pa(_sdata));
4827+ map.virtual = (unsigned long)_sdata;
4828+ map.length = end - __pa(_sdata);
4829+ }
4830+
4831+ map.type = MT_MEMORY_RW;
4832+ create_mapping(&map);
4833+#else
4834 if (end < kernel_x_start || start >= kernel_x_end) {
4835 map.pfn = __phys_to_pfn(start);
4836 map.virtual = __phys_to_virt(start);
4837 map.length = end - start;
4838- map.type = MT_MEMORY_RWX;
4839+ map.type = __MT_MEMORY_RWX;
4840
4841 create_mapping(&map);
4842 } else {
4843@@ -1370,7 +1463,7 @@ static void __init map_lowmem(void)
4844 map.pfn = __phys_to_pfn(kernel_x_start);
4845 map.virtual = __phys_to_virt(kernel_x_start);
4846 map.length = kernel_x_end - kernel_x_start;
4847- map.type = MT_MEMORY_RWX;
4848+ map.type = __MT_MEMORY_RWX;
4849
4850 create_mapping(&map);
4851
4852@@ -1383,6 +1476,7 @@ static void __init map_lowmem(void)
4853 create_mapping(&map);
4854 }
4855 }
4856+#endif
4857 }
4858 }
4859
4860diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c
4861index a37b989..5c9ae75 100644
4862--- a/arch/arm/net/bpf_jit_32.c
4863+++ b/arch/arm/net/bpf_jit_32.c
4864@@ -71,7 +71,11 @@ struct jit_ctx {
4865 #endif
4866 };
4867
4868+#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
4869+int bpf_jit_enable __read_only;
4870+#else
4871 int bpf_jit_enable __read_mostly;
4872+#endif
4873
4874 static u64 jit_get_skb_b(struct sk_buff *skb, unsigned offset)
4875 {
4876@@ -930,5 +934,6 @@ void bpf_jit_free(struct bpf_prog *fp)
4877 {
4878 if (fp->jited)
4879 module_free(NULL, fp->bpf_func);
4880- kfree(fp);
4881+
4882+ bpf_prog_unlock_free(fp);
4883 }
4884diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4885index 5b217f4..c23f40e 100644
4886--- a/arch/arm/plat-iop/setup.c
4887+++ b/arch/arm/plat-iop/setup.c
4888@@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4889 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4890 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4891 .length = IOP3XX_PERIPHERAL_SIZE,
4892- .type = MT_UNCACHED,
4893+ .type = MT_UNCACHED_RW,
4894 },
4895 };
4896
4897diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4898index a5bc92d..0bb4730 100644
4899--- a/arch/arm/plat-omap/sram.c
4900+++ b/arch/arm/plat-omap/sram.c
4901@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4902 * Looks like we need to preserve some bootloader code at the
4903 * beginning of SRAM for jumping to flash for reboot to work...
4904 */
4905+ pax_open_kernel();
4906 memset_io(omap_sram_base + omap_sram_skip, 0,
4907 omap_sram_size - omap_sram_skip);
4908+ pax_close_kernel();
4909 }
4910diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4911index ce6d763..cfea917 100644
4912--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4913+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4914@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4915 int (*started)(unsigned ch);
4916 int (*flush)(unsigned ch);
4917 int (*stop)(unsigned ch);
4918-};
4919+} __no_const;
4920
4921 extern void *samsung_dmadev_get_ops(void);
4922 extern void *s3c_dma_get_ops(void);
4923diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
4924index 6389d60..b5d3bdd 100644
4925--- a/arch/arm64/include/asm/barrier.h
4926+++ b/arch/arm64/include/asm/barrier.h
4927@@ -41,7 +41,7 @@
4928 do { \
4929 compiletime_assert_atomic_type(*p); \
4930 barrier(); \
4931- ACCESS_ONCE(*p) = (v); \
4932+ ACCESS_ONCE_RW(*p) = (v); \
4933 } while (0)
4934
4935 #define smp_load_acquire(p) \
4936diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4937index 3bf8f4e..5dd5491 100644
4938--- a/arch/arm64/include/asm/uaccess.h
4939+++ b/arch/arm64/include/asm/uaccess.h
4940@@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4941 flag; \
4942 })
4943
4944+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4945 #define access_ok(type, addr, size) __range_ok(addr, size)
4946 #define user_addr_max get_fs
4947
4948diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4949index c3a58a1..78fbf54 100644
4950--- a/arch/avr32/include/asm/cache.h
4951+++ b/arch/avr32/include/asm/cache.h
4952@@ -1,8 +1,10 @@
4953 #ifndef __ASM_AVR32_CACHE_H
4954 #define __ASM_AVR32_CACHE_H
4955
4956+#include <linux/const.h>
4957+
4958 #define L1_CACHE_SHIFT 5
4959-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4960+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4961
4962 /*
4963 * Memory returned by kmalloc() may be used for DMA, so we must make
4964diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4965index d232888..87c8df1 100644
4966--- a/arch/avr32/include/asm/elf.h
4967+++ b/arch/avr32/include/asm/elf.h
4968@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4969 the loader. We need to make sure that it is out of the way of the program
4970 that it will "exec", and that there is sufficient room for the brk. */
4971
4972-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4973+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4974
4975+#ifdef CONFIG_PAX_ASLR
4976+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4977+
4978+#define PAX_DELTA_MMAP_LEN 15
4979+#define PAX_DELTA_STACK_LEN 15
4980+#endif
4981
4982 /* This yields a mask that user programs can use to figure out what
4983 instruction set this CPU supports. This could be done in user space,
4984diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4985index 479330b..53717a8 100644
4986--- a/arch/avr32/include/asm/kmap_types.h
4987+++ b/arch/avr32/include/asm/kmap_types.h
4988@@ -2,9 +2,9 @@
4989 #define __ASM_AVR32_KMAP_TYPES_H
4990
4991 #ifdef CONFIG_DEBUG_HIGHMEM
4992-# define KM_TYPE_NR 29
4993+# define KM_TYPE_NR 30
4994 #else
4995-# define KM_TYPE_NR 14
4996+# define KM_TYPE_NR 15
4997 #endif
4998
4999 #endif /* __ASM_AVR32_KMAP_TYPES_H */
5000diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
5001index 0eca933..eb78c7b 100644
5002--- a/arch/avr32/mm/fault.c
5003+++ b/arch/avr32/mm/fault.c
5004@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
5005
5006 int exception_trace = 1;
5007
5008+#ifdef CONFIG_PAX_PAGEEXEC
5009+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5010+{
5011+ unsigned long i;
5012+
5013+ printk(KERN_ERR "PAX: bytes at PC: ");
5014+ for (i = 0; i < 20; i++) {
5015+ unsigned char c;
5016+ if (get_user(c, (unsigned char *)pc+i))
5017+ printk(KERN_CONT "???????? ");
5018+ else
5019+ printk(KERN_CONT "%02x ", c);
5020+ }
5021+ printk("\n");
5022+}
5023+#endif
5024+
5025 /*
5026 * This routine handles page faults. It determines the address and the
5027 * problem, and then passes it off to one of the appropriate routines.
5028@@ -176,6 +193,16 @@ bad_area:
5029 up_read(&mm->mmap_sem);
5030
5031 if (user_mode(regs)) {
5032+
5033+#ifdef CONFIG_PAX_PAGEEXEC
5034+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
5035+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
5036+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
5037+ do_group_exit(SIGKILL);
5038+ }
5039+ }
5040+#endif
5041+
5042 if (exception_trace && printk_ratelimit())
5043 printk("%s%s[%d]: segfault at %08lx pc %08lx "
5044 "sp %08lx ecr %lu\n",
5045diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
5046index 568885a..f8008df 100644
5047--- a/arch/blackfin/include/asm/cache.h
5048+++ b/arch/blackfin/include/asm/cache.h
5049@@ -7,6 +7,7 @@
5050 #ifndef __ARCH_BLACKFIN_CACHE_H
5051 #define __ARCH_BLACKFIN_CACHE_H
5052
5053+#include <linux/const.h>
5054 #include <linux/linkage.h> /* for asmlinkage */
5055
5056 /*
5057@@ -14,7 +15,7 @@
5058 * Blackfin loads 32 bytes for cache
5059 */
5060 #define L1_CACHE_SHIFT 5
5061-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5062+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5063 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5064
5065 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5066diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
5067index aea2718..3639a60 100644
5068--- a/arch/cris/include/arch-v10/arch/cache.h
5069+++ b/arch/cris/include/arch-v10/arch/cache.h
5070@@ -1,8 +1,9 @@
5071 #ifndef _ASM_ARCH_CACHE_H
5072 #define _ASM_ARCH_CACHE_H
5073
5074+#include <linux/const.h>
5075 /* Etrax 100LX have 32-byte cache-lines. */
5076-#define L1_CACHE_BYTES 32
5077 #define L1_CACHE_SHIFT 5
5078+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5079
5080 #endif /* _ASM_ARCH_CACHE_H */
5081diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
5082index 7caf25d..ee65ac5 100644
5083--- a/arch/cris/include/arch-v32/arch/cache.h
5084+++ b/arch/cris/include/arch-v32/arch/cache.h
5085@@ -1,11 +1,12 @@
5086 #ifndef _ASM_CRIS_ARCH_CACHE_H
5087 #define _ASM_CRIS_ARCH_CACHE_H
5088
5089+#include <linux/const.h>
5090 #include <arch/hwregs/dma.h>
5091
5092 /* A cache-line is 32 bytes. */
5093-#define L1_CACHE_BYTES 32
5094 #define L1_CACHE_SHIFT 5
5095+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5096
5097 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5098
5099diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
5100index f6c3a16..cd422a4 100644
5101--- a/arch/frv/include/asm/atomic.h
5102+++ b/arch/frv/include/asm/atomic.h
5103@@ -181,6 +181,16 @@ static inline void atomic64_dec(atomic64_t *v)
5104 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
5105 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
5106
5107+#define atomic64_read_unchecked(v) atomic64_read(v)
5108+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5109+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5110+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5111+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5112+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5113+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5114+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5115+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5116+
5117 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5118 {
5119 int c, old;
5120diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
5121index 2797163..c2a401df9 100644
5122--- a/arch/frv/include/asm/cache.h
5123+++ b/arch/frv/include/asm/cache.h
5124@@ -12,10 +12,11 @@
5125 #ifndef __ASM_CACHE_H
5126 #define __ASM_CACHE_H
5127
5128+#include <linux/const.h>
5129
5130 /* bytes per L1 cache line */
5131 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
5132-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5133+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5134
5135 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5136 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5137diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
5138index 43901f2..0d8b865 100644
5139--- a/arch/frv/include/asm/kmap_types.h
5140+++ b/arch/frv/include/asm/kmap_types.h
5141@@ -2,6 +2,6 @@
5142 #ifndef _ASM_KMAP_TYPES_H
5143 #define _ASM_KMAP_TYPES_H
5144
5145-#define KM_TYPE_NR 17
5146+#define KM_TYPE_NR 18
5147
5148 #endif
5149diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
5150index 836f147..4cf23f5 100644
5151--- a/arch/frv/mm/elf-fdpic.c
5152+++ b/arch/frv/mm/elf-fdpic.c
5153@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5154 {
5155 struct vm_area_struct *vma;
5156 struct vm_unmapped_area_info info;
5157+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5158
5159 if (len > TASK_SIZE)
5160 return -ENOMEM;
5161@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5162 if (addr) {
5163 addr = PAGE_ALIGN(addr);
5164 vma = find_vma(current->mm, addr);
5165- if (TASK_SIZE - len >= addr &&
5166- (!vma || addr + len <= vma->vm_start))
5167+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5168 goto success;
5169 }
5170
5171@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5172 info.high_limit = (current->mm->start_stack - 0x00200000);
5173 info.align_mask = 0;
5174 info.align_offset = 0;
5175+ info.threadstack_offset = offset;
5176 addr = vm_unmapped_area(&info);
5177 if (!(addr & ~PAGE_MASK))
5178 goto success;
5179diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
5180index 2635117..fa223cb 100644
5181--- a/arch/hexagon/include/asm/cache.h
5182+++ b/arch/hexagon/include/asm/cache.h
5183@@ -21,9 +21,11 @@
5184 #ifndef __ASM_CACHE_H
5185 #define __ASM_CACHE_H
5186
5187+#include <linux/const.h>
5188+
5189 /* Bytes per L1 cache line */
5190-#define L1_CACHE_SHIFT (5)
5191-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5192+#define L1_CACHE_SHIFT 5
5193+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5194
5195 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5196 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5197diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5198index c84c88b..2a6e1ba 100644
5199--- a/arch/ia64/Kconfig
5200+++ b/arch/ia64/Kconfig
5201@@ -549,6 +549,7 @@ source "drivers/sn/Kconfig"
5202 config KEXEC
5203 bool "kexec system call"
5204 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5205+ depends on !GRKERNSEC_KMEM
5206 help
5207 kexec is a system call that implements the ability to shutdown your
5208 current kernel, and to start another kernel. It is like a reboot
5209diff --git a/arch/ia64/Makefile b/arch/ia64/Makefile
5210index 5441b14..039a446 100644
5211--- a/arch/ia64/Makefile
5212+++ b/arch/ia64/Makefile
5213@@ -99,5 +99,6 @@ endef
5214 archprepare: make_nr_irqs_h FORCE
5215 PHONY += make_nr_irqs_h FORCE
5216
5217+make_nr_irqs_h: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
5218 make_nr_irqs_h: FORCE
5219 $(Q)$(MAKE) $(build)=arch/ia64/kernel include/generated/nr-irqs.h
5220diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5221index 0f8bf48..40ea950 100644
5222--- a/arch/ia64/include/asm/atomic.h
5223+++ b/arch/ia64/include/asm/atomic.h
5224@@ -209,4 +209,14 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5225 #define atomic64_inc(v) atomic64_add(1, (v))
5226 #define atomic64_dec(v) atomic64_sub(1, (v))
5227
5228+#define atomic64_read_unchecked(v) atomic64_read(v)
5229+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5230+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5231+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5232+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5233+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5234+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5235+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5236+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5237+
5238 #endif /* _ASM_IA64_ATOMIC_H */
5239diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5240index a48957c..e097b56 100644
5241--- a/arch/ia64/include/asm/barrier.h
5242+++ b/arch/ia64/include/asm/barrier.h
5243@@ -67,7 +67,7 @@
5244 do { \
5245 compiletime_assert_atomic_type(*p); \
5246 barrier(); \
5247- ACCESS_ONCE(*p) = (v); \
5248+ ACCESS_ONCE_RW(*p) = (v); \
5249 } while (0)
5250
5251 #define smp_load_acquire(p) \
5252diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5253index 988254a..e1ee885 100644
5254--- a/arch/ia64/include/asm/cache.h
5255+++ b/arch/ia64/include/asm/cache.h
5256@@ -1,6 +1,7 @@
5257 #ifndef _ASM_IA64_CACHE_H
5258 #define _ASM_IA64_CACHE_H
5259
5260+#include <linux/const.h>
5261
5262 /*
5263 * Copyright (C) 1998-2000 Hewlett-Packard Co
5264@@ -9,7 +10,7 @@
5265
5266 /* Bytes per L1 (data) cache line. */
5267 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5268-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5269+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5270
5271 #ifdef CONFIG_SMP
5272 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5273diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5274index 5a83c5c..4d7f553 100644
5275--- a/arch/ia64/include/asm/elf.h
5276+++ b/arch/ia64/include/asm/elf.h
5277@@ -42,6 +42,13 @@
5278 */
5279 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5280
5281+#ifdef CONFIG_PAX_ASLR
5282+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5283+
5284+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5285+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5286+#endif
5287+
5288 #define PT_IA_64_UNWIND 0x70000001
5289
5290 /* IA-64 relocations: */
5291diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5292index 5767cdf..7462574 100644
5293--- a/arch/ia64/include/asm/pgalloc.h
5294+++ b/arch/ia64/include/asm/pgalloc.h
5295@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5296 pgd_val(*pgd_entry) = __pa(pud);
5297 }
5298
5299+static inline void
5300+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5301+{
5302+ pgd_populate(mm, pgd_entry, pud);
5303+}
5304+
5305 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5306 {
5307 return quicklist_alloc(0, GFP_KERNEL, NULL);
5308@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5309 pud_val(*pud_entry) = __pa(pmd);
5310 }
5311
5312+static inline void
5313+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5314+{
5315+ pud_populate(mm, pud_entry, pmd);
5316+}
5317+
5318 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5319 {
5320 return quicklist_alloc(0, GFP_KERNEL, NULL);
5321diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5322index 7935115..c0eca6a 100644
5323--- a/arch/ia64/include/asm/pgtable.h
5324+++ b/arch/ia64/include/asm/pgtable.h
5325@@ -12,7 +12,7 @@
5326 * David Mosberger-Tang <davidm@hpl.hp.com>
5327 */
5328
5329-
5330+#include <linux/const.h>
5331 #include <asm/mman.h>
5332 #include <asm/page.h>
5333 #include <asm/processor.h>
5334@@ -142,6 +142,17 @@
5335 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5336 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5337 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5338+
5339+#ifdef CONFIG_PAX_PAGEEXEC
5340+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5341+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5342+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5343+#else
5344+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5345+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5346+# define PAGE_COPY_NOEXEC PAGE_COPY
5347+#endif
5348+
5349 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5350 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5351 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5352diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5353index 45698cd..e8e2dbc 100644
5354--- a/arch/ia64/include/asm/spinlock.h
5355+++ b/arch/ia64/include/asm/spinlock.h
5356@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5357 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5358
5359 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5360- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5361+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5362 }
5363
5364 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5365diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5366index 449c8c0..3d4b1e9 100644
5367--- a/arch/ia64/include/asm/uaccess.h
5368+++ b/arch/ia64/include/asm/uaccess.h
5369@@ -70,6 +70,7 @@
5370 && ((segment).seg == KERNEL_DS.seg \
5371 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5372 })
5373+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5374 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5375
5376 /*
5377@@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5378 static inline unsigned long
5379 __copy_to_user (void __user *to, const void *from, unsigned long count)
5380 {
5381+ if (count > INT_MAX)
5382+ return count;
5383+
5384+ if (!__builtin_constant_p(count))
5385+ check_object_size(from, count, true);
5386+
5387 return __copy_user(to, (__force void __user *) from, count);
5388 }
5389
5390 static inline unsigned long
5391 __copy_from_user (void *to, const void __user *from, unsigned long count)
5392 {
5393+ if (count > INT_MAX)
5394+ return count;
5395+
5396+ if (!__builtin_constant_p(count))
5397+ check_object_size(to, count, false);
5398+
5399 return __copy_user((__force void __user *) to, from, count);
5400 }
5401
5402@@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5403 ({ \
5404 void __user *__cu_to = (to); \
5405 const void *__cu_from = (from); \
5406- long __cu_len = (n); \
5407+ unsigned long __cu_len = (n); \
5408 \
5409- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5410+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5411+ if (!__builtin_constant_p(n)) \
5412+ check_object_size(__cu_from, __cu_len, true); \
5413 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5414+ } \
5415 __cu_len; \
5416 })
5417
5418@@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5419 ({ \
5420 void *__cu_to = (to); \
5421 const void __user *__cu_from = (from); \
5422- long __cu_len = (n); \
5423+ unsigned long __cu_len = (n); \
5424 \
5425 __chk_user_ptr(__cu_from); \
5426- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5427+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5428+ if (!__builtin_constant_p(n)) \
5429+ check_object_size(__cu_to, __cu_len, false); \
5430 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5431+ } \
5432 __cu_len; \
5433 })
5434
5435diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5436index 24603be..948052d 100644
5437--- a/arch/ia64/kernel/module.c
5438+++ b/arch/ia64/kernel/module.c
5439@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5440 void
5441 module_free (struct module *mod, void *module_region)
5442 {
5443- if (mod && mod->arch.init_unw_table &&
5444- module_region == mod->module_init) {
5445+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5446 unw_remove_unwind_table(mod->arch.init_unw_table);
5447 mod->arch.init_unw_table = NULL;
5448 }
5449@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5450 }
5451
5452 static inline int
5453+in_init_rx (const struct module *mod, uint64_t addr)
5454+{
5455+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5456+}
5457+
5458+static inline int
5459+in_init_rw (const struct module *mod, uint64_t addr)
5460+{
5461+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5462+}
5463+
5464+static inline int
5465 in_init (const struct module *mod, uint64_t addr)
5466 {
5467- return addr - (uint64_t) mod->module_init < mod->init_size;
5468+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5469+}
5470+
5471+static inline int
5472+in_core_rx (const struct module *mod, uint64_t addr)
5473+{
5474+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5475+}
5476+
5477+static inline int
5478+in_core_rw (const struct module *mod, uint64_t addr)
5479+{
5480+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5481 }
5482
5483 static inline int
5484 in_core (const struct module *mod, uint64_t addr)
5485 {
5486- return addr - (uint64_t) mod->module_core < mod->core_size;
5487+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5488 }
5489
5490 static inline int
5491@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5492 break;
5493
5494 case RV_BDREL:
5495- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5496+ if (in_init_rx(mod, val))
5497+ val -= (uint64_t) mod->module_init_rx;
5498+ else if (in_init_rw(mod, val))
5499+ val -= (uint64_t) mod->module_init_rw;
5500+ else if (in_core_rx(mod, val))
5501+ val -= (uint64_t) mod->module_core_rx;
5502+ else if (in_core_rw(mod, val))
5503+ val -= (uint64_t) mod->module_core_rw;
5504 break;
5505
5506 case RV_LTV:
5507@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5508 * addresses have been selected...
5509 */
5510 uint64_t gp;
5511- if (mod->core_size > MAX_LTOFF)
5512+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5513 /*
5514 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5515 * at the end of the module.
5516 */
5517- gp = mod->core_size - MAX_LTOFF / 2;
5518+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5519 else
5520- gp = mod->core_size / 2;
5521- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5522+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5523+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5524 mod->arch.gp = gp;
5525 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5526 }
5527diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5528index c39c3cd..3c77738 100644
5529--- a/arch/ia64/kernel/palinfo.c
5530+++ b/arch/ia64/kernel/palinfo.c
5531@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5532 return NOTIFY_OK;
5533 }
5534
5535-static struct notifier_block __refdata palinfo_cpu_notifier =
5536+static struct notifier_block palinfo_cpu_notifier =
5537 {
5538 .notifier_call = palinfo_cpu_callback,
5539 .priority = 0,
5540diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5541index 41e33f8..65180b2a 100644
5542--- a/arch/ia64/kernel/sys_ia64.c
5543+++ b/arch/ia64/kernel/sys_ia64.c
5544@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5545 unsigned long align_mask = 0;
5546 struct mm_struct *mm = current->mm;
5547 struct vm_unmapped_area_info info;
5548+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5549
5550 if (len > RGN_MAP_LIMIT)
5551 return -ENOMEM;
5552@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5553 if (REGION_NUMBER(addr) == RGN_HPAGE)
5554 addr = 0;
5555 #endif
5556+
5557+#ifdef CONFIG_PAX_RANDMMAP
5558+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5559+ addr = mm->free_area_cache;
5560+ else
5561+#endif
5562+
5563 if (!addr)
5564 addr = TASK_UNMAPPED_BASE;
5565
5566@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5567 info.high_limit = TASK_SIZE;
5568 info.align_mask = align_mask;
5569 info.align_offset = 0;
5570+ info.threadstack_offset = offset;
5571 return vm_unmapped_area(&info);
5572 }
5573
5574diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5575index 84f8a52..7c76178 100644
5576--- a/arch/ia64/kernel/vmlinux.lds.S
5577+++ b/arch/ia64/kernel/vmlinux.lds.S
5578@@ -192,7 +192,7 @@ SECTIONS {
5579 /* Per-cpu data: */
5580 . = ALIGN(PERCPU_PAGE_SIZE);
5581 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5582- __phys_per_cpu_start = __per_cpu_load;
5583+ __phys_per_cpu_start = per_cpu_load;
5584 /*
5585 * ensure percpu data fits
5586 * into percpu page size
5587diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5588index 7225dad..2a7c8256 100644
5589--- a/arch/ia64/mm/fault.c
5590+++ b/arch/ia64/mm/fault.c
5591@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5592 return pte_present(pte);
5593 }
5594
5595+#ifdef CONFIG_PAX_PAGEEXEC
5596+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5597+{
5598+ unsigned long i;
5599+
5600+ printk(KERN_ERR "PAX: bytes at PC: ");
5601+ for (i = 0; i < 8; i++) {
5602+ unsigned int c;
5603+ if (get_user(c, (unsigned int *)pc+i))
5604+ printk(KERN_CONT "???????? ");
5605+ else
5606+ printk(KERN_CONT "%08x ", c);
5607+ }
5608+ printk("\n");
5609+}
5610+#endif
5611+
5612 # define VM_READ_BIT 0
5613 # define VM_WRITE_BIT 1
5614 # define VM_EXEC_BIT 2
5615@@ -151,8 +168,21 @@ retry:
5616 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5617 goto bad_area;
5618
5619- if ((vma->vm_flags & mask) != mask)
5620+ if ((vma->vm_flags & mask) != mask) {
5621+
5622+#ifdef CONFIG_PAX_PAGEEXEC
5623+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5624+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5625+ goto bad_area;
5626+
5627+ up_read(&mm->mmap_sem);
5628+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5629+ do_group_exit(SIGKILL);
5630+ }
5631+#endif
5632+
5633 goto bad_area;
5634+ }
5635
5636 /*
5637 * If for any reason at all we couldn't handle the fault, make
5638diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5639index 76069c1..c2aa816 100644
5640--- a/arch/ia64/mm/hugetlbpage.c
5641+++ b/arch/ia64/mm/hugetlbpage.c
5642@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5643 unsigned long pgoff, unsigned long flags)
5644 {
5645 struct vm_unmapped_area_info info;
5646+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5647
5648 if (len > RGN_MAP_LIMIT)
5649 return -ENOMEM;
5650@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5651 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5652 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5653 info.align_offset = 0;
5654+ info.threadstack_offset = offset;
5655 return vm_unmapped_area(&info);
5656 }
5657
5658diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5659index 6b33457..88b5124 100644
5660--- a/arch/ia64/mm/init.c
5661+++ b/arch/ia64/mm/init.c
5662@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5663 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5664 vma->vm_end = vma->vm_start + PAGE_SIZE;
5665 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5666+
5667+#ifdef CONFIG_PAX_PAGEEXEC
5668+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5669+ vma->vm_flags &= ~VM_EXEC;
5670+
5671+#ifdef CONFIG_PAX_MPROTECT
5672+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5673+ vma->vm_flags &= ~VM_MAYEXEC;
5674+#endif
5675+
5676+ }
5677+#endif
5678+
5679 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5680 down_write(&current->mm->mmap_sem);
5681 if (insert_vm_struct(current->mm, vma)) {
5682@@ -286,7 +299,7 @@ static int __init gate_vma_init(void)
5683 gate_vma.vm_start = FIXADDR_USER_START;
5684 gate_vma.vm_end = FIXADDR_USER_END;
5685 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
5686- gate_vma.vm_page_prot = __P101;
5687+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
5688
5689 return 0;
5690 }
5691diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5692index 40b3ee9..8c2c112 100644
5693--- a/arch/m32r/include/asm/cache.h
5694+++ b/arch/m32r/include/asm/cache.h
5695@@ -1,8 +1,10 @@
5696 #ifndef _ASM_M32R_CACHE_H
5697 #define _ASM_M32R_CACHE_H
5698
5699+#include <linux/const.h>
5700+
5701 /* L1 cache line size */
5702 #define L1_CACHE_SHIFT 4
5703-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5704+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5705
5706 #endif /* _ASM_M32R_CACHE_H */
5707diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5708index 82abd15..d95ae5d 100644
5709--- a/arch/m32r/lib/usercopy.c
5710+++ b/arch/m32r/lib/usercopy.c
5711@@ -14,6 +14,9 @@
5712 unsigned long
5713 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5714 {
5715+ if ((long)n < 0)
5716+ return n;
5717+
5718 prefetch(from);
5719 if (access_ok(VERIFY_WRITE, to, n))
5720 __copy_user(to,from,n);
5721@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5722 unsigned long
5723 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5724 {
5725+ if ((long)n < 0)
5726+ return n;
5727+
5728 prefetchw(to);
5729 if (access_ok(VERIFY_READ, from, n))
5730 __copy_user_zeroing(to,from,n);
5731diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5732index 0395c51..5f26031 100644
5733--- a/arch/m68k/include/asm/cache.h
5734+++ b/arch/m68k/include/asm/cache.h
5735@@ -4,9 +4,11 @@
5736 #ifndef __ARCH_M68K_CACHE_H
5737 #define __ARCH_M68K_CACHE_H
5738
5739+#include <linux/const.h>
5740+
5741 /* bytes per L1 cache line */
5742 #define L1_CACHE_SHIFT 4
5743-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5744+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5745
5746 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5747
5748diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
5749index c7591e8..ecef036 100644
5750--- a/arch/metag/include/asm/barrier.h
5751+++ b/arch/metag/include/asm/barrier.h
5752@@ -89,7 +89,7 @@ static inline void fence(void)
5753 do { \
5754 compiletime_assert_atomic_type(*p); \
5755 smp_mb(); \
5756- ACCESS_ONCE(*p) = (v); \
5757+ ACCESS_ONCE_RW(*p) = (v); \
5758 } while (0)
5759
5760 #define smp_load_acquire(p) \
5761diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5762index 3c32075..ae0ae75 100644
5763--- a/arch/metag/mm/hugetlbpage.c
5764+++ b/arch/metag/mm/hugetlbpage.c
5765@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5766 info.high_limit = TASK_SIZE;
5767 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5768 info.align_offset = 0;
5769+ info.threadstack_offset = 0;
5770 return vm_unmapped_area(&info);
5771 }
5772
5773diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5774index 4efe96a..60e8699 100644
5775--- a/arch/microblaze/include/asm/cache.h
5776+++ b/arch/microblaze/include/asm/cache.h
5777@@ -13,11 +13,12 @@
5778 #ifndef _ASM_MICROBLAZE_CACHE_H
5779 #define _ASM_MICROBLAZE_CACHE_H
5780
5781+#include <linux/const.h>
5782 #include <asm/registers.h>
5783
5784 #define L1_CACHE_SHIFT 5
5785 /* word-granular cache in microblaze */
5786-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5787+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5788
5789 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5790
5791diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5792index 574c430..470200d 100644
5793--- a/arch/mips/Kconfig
5794+++ b/arch/mips/Kconfig
5795@@ -2399,6 +2399,7 @@ source "kernel/Kconfig.preempt"
5796
5797 config KEXEC
5798 bool "Kexec system call"
5799+ depends on !GRKERNSEC_KMEM
5800 help
5801 kexec is a system call that implements the ability to shutdown your
5802 current kernel, and to start another kernel. It is like a reboot
5803diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5804index 02f2444..506969c 100644
5805--- a/arch/mips/cavium-octeon/dma-octeon.c
5806+++ b/arch/mips/cavium-octeon/dma-octeon.c
5807@@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5808 if (dma_release_from_coherent(dev, order, vaddr))
5809 return;
5810
5811- swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5812+ swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5813 }
5814
5815 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5816diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5817index 37b2bef..02122b8 100644
5818--- a/arch/mips/include/asm/atomic.h
5819+++ b/arch/mips/include/asm/atomic.h
5820@@ -21,15 +21,39 @@
5821 #include <asm/cmpxchg.h>
5822 #include <asm/war.h>
5823
5824+#ifdef CONFIG_GENERIC_ATOMIC64
5825+#include <asm-generic/atomic64.h>
5826+#endif
5827+
5828 #define ATOMIC_INIT(i) { (i) }
5829
5830+#ifdef CONFIG_64BIT
5831+#define _ASM_EXTABLE(from, to) \
5832+" .section __ex_table,\"a\"\n" \
5833+" .dword " #from ", " #to"\n" \
5834+" .previous\n"
5835+#else
5836+#define _ASM_EXTABLE(from, to) \
5837+" .section __ex_table,\"a\"\n" \
5838+" .word " #from ", " #to"\n" \
5839+" .previous\n"
5840+#endif
5841+
5842 /*
5843 * atomic_read - read atomic variable
5844 * @v: pointer of type atomic_t
5845 *
5846 * Atomically reads the value of @v.
5847 */
5848-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5849+static inline int atomic_read(const atomic_t *v)
5850+{
5851+ return (*(volatile const int *) &v->counter);
5852+}
5853+
5854+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5855+{
5856+ return (*(volatile const int *) &v->counter);
5857+}
5858
5859 /*
5860 * atomic_set - set atomic variable
5861@@ -38,7 +62,15 @@
5862 *
5863 * Atomically sets the value of @v to @i.
5864 */
5865-#define atomic_set(v, i) ((v)->counter = (i))
5866+static inline void atomic_set(atomic_t *v, int i)
5867+{
5868+ v->counter = i;
5869+}
5870+
5871+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5872+{
5873+ v->counter = i;
5874+}
5875
5876 /*
5877 * atomic_add - add integer to atomic variable
5878@@ -47,7 +79,67 @@
5879 *
5880 * Atomically adds @i to @v.
5881 */
5882-static __inline__ void atomic_add(int i, atomic_t * v)
5883+static __inline__ void atomic_add(int i, atomic_t *v)
5884+{
5885+ int temp;
5886+
5887+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5888+ __asm__ __volatile__(
5889+ " .set mips3 \n"
5890+ "1: ll %0, %1 # atomic_add \n"
5891+#ifdef CONFIG_PAX_REFCOUNT
5892+ /* Exception on overflow. */
5893+ "2: add %0, %2 \n"
5894+#else
5895+ " addu %0, %2 \n"
5896+#endif
5897+ " sc %0, %1 \n"
5898+ " beqzl %0, 1b \n"
5899+#ifdef CONFIG_PAX_REFCOUNT
5900+ "3: \n"
5901+ _ASM_EXTABLE(2b, 3b)
5902+#endif
5903+ " .set mips0 \n"
5904+ : "=&r" (temp), "+m" (v->counter)
5905+ : "Ir" (i));
5906+ } else if (kernel_uses_llsc) {
5907+ __asm__ __volatile__(
5908+ " .set mips3 \n"
5909+ "1: ll %0, %1 # atomic_add \n"
5910+#ifdef CONFIG_PAX_REFCOUNT
5911+ /* Exception on overflow. */
5912+ "2: add %0, %2 \n"
5913+#else
5914+ " addu %0, %2 \n"
5915+#endif
5916+ " sc %0, %1 \n"
5917+ " beqz %0, 1b \n"
5918+#ifdef CONFIG_PAX_REFCOUNT
5919+ "3: \n"
5920+ _ASM_EXTABLE(2b, 3b)
5921+#endif
5922+ " .set mips0 \n"
5923+ : "=&r" (temp), "+m" (v->counter)
5924+ : "Ir" (i));
5925+ } else {
5926+ unsigned long flags;
5927+
5928+ raw_local_irq_save(flags);
5929+ __asm__ __volatile__(
5930+#ifdef CONFIG_PAX_REFCOUNT
5931+ /* Exception on overflow. */
5932+ "1: add %0, %1 \n"
5933+ "2: \n"
5934+ _ASM_EXTABLE(1b, 2b)
5935+#else
5936+ " addu %0, %1 \n"
5937+#endif
5938+ : "+r" (v->counter) : "Ir" (i));
5939+ raw_local_irq_restore(flags);
5940+ }
5941+}
5942+
5943+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5944 {
5945 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5946 int temp;
5947@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5948 *
5949 * Atomically subtracts @i from @v.
5950 */
5951-static __inline__ void atomic_sub(int i, atomic_t * v)
5952+static __inline__ void atomic_sub(int i, atomic_t *v)
5953+{
5954+ int temp;
5955+
5956+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5957+ __asm__ __volatile__(
5958+ " .set mips3 \n"
5959+ "1: ll %0, %1 # atomic64_sub \n"
5960+#ifdef CONFIG_PAX_REFCOUNT
5961+ /* Exception on overflow. */
5962+ "2: sub %0, %2 \n"
5963+#else
5964+ " subu %0, %2 \n"
5965+#endif
5966+ " sc %0, %1 \n"
5967+ " beqzl %0, 1b \n"
5968+#ifdef CONFIG_PAX_REFCOUNT
5969+ "3: \n"
5970+ _ASM_EXTABLE(2b, 3b)
5971+#endif
5972+ " .set mips0 \n"
5973+ : "=&r" (temp), "+m" (v->counter)
5974+ : "Ir" (i));
5975+ } else if (kernel_uses_llsc) {
5976+ __asm__ __volatile__(
5977+ " .set mips3 \n"
5978+ "1: ll %0, %1 # atomic64_sub \n"
5979+#ifdef CONFIG_PAX_REFCOUNT
5980+ /* Exception on overflow. */
5981+ "2: sub %0, %2 \n"
5982+#else
5983+ " subu %0, %2 \n"
5984+#endif
5985+ " sc %0, %1 \n"
5986+ " beqz %0, 1b \n"
5987+#ifdef CONFIG_PAX_REFCOUNT
5988+ "3: \n"
5989+ _ASM_EXTABLE(2b, 3b)
5990+#endif
5991+ " .set mips0 \n"
5992+ : "=&r" (temp), "+m" (v->counter)
5993+ : "Ir" (i));
5994+ } else {
5995+ unsigned long flags;
5996+
5997+ raw_local_irq_save(flags);
5998+ __asm__ __volatile__(
5999+#ifdef CONFIG_PAX_REFCOUNT
6000+ /* Exception on overflow. */
6001+ "1: sub %0, %1 \n"
6002+ "2: \n"
6003+ _ASM_EXTABLE(1b, 2b)
6004+#else
6005+ " subu %0, %1 \n"
6006+#endif
6007+ : "+r" (v->counter) : "Ir" (i));
6008+ raw_local_irq_restore(flags);
6009+ }
6010+}
6011+
6012+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
6013 {
6014 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6015 int temp;
6016@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
6017 /*
6018 * Same as above, but return the result value
6019 */
6020-static __inline__ int atomic_add_return(int i, atomic_t * v)
6021+static __inline__ int atomic_add_return(int i, atomic_t *v)
6022+{
6023+ int result;
6024+ int temp;
6025+
6026+ smp_mb__before_llsc();
6027+
6028+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6029+ __asm__ __volatile__(
6030+ " .set mips3 \n"
6031+ "1: ll %1, %2 # atomic_add_return \n"
6032+#ifdef CONFIG_PAX_REFCOUNT
6033+ "2: add %0, %1, %3 \n"
6034+#else
6035+ " addu %0, %1, %3 \n"
6036+#endif
6037+ " sc %0, %2 \n"
6038+ " beqzl %0, 1b \n"
6039+#ifdef CONFIG_PAX_REFCOUNT
6040+ " b 4f \n"
6041+ " .set noreorder \n"
6042+ "3: b 5f \n"
6043+ " move %0, %1 \n"
6044+ " .set reorder \n"
6045+ _ASM_EXTABLE(2b, 3b)
6046+#endif
6047+ "4: addu %0, %1, %3 \n"
6048+#ifdef CONFIG_PAX_REFCOUNT
6049+ "5: \n"
6050+#endif
6051+ " .set mips0 \n"
6052+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6053+ : "Ir" (i));
6054+ } else if (kernel_uses_llsc) {
6055+ __asm__ __volatile__(
6056+ " .set mips3 \n"
6057+ "1: ll %1, %2 # atomic_add_return \n"
6058+#ifdef CONFIG_PAX_REFCOUNT
6059+ "2: add %0, %1, %3 \n"
6060+#else
6061+ " addu %0, %1, %3 \n"
6062+#endif
6063+ " sc %0, %2 \n"
6064+ " bnez %0, 4f \n"
6065+ " b 1b \n"
6066+#ifdef CONFIG_PAX_REFCOUNT
6067+ " .set noreorder \n"
6068+ "3: b 5f \n"
6069+ " move %0, %1 \n"
6070+ " .set reorder \n"
6071+ _ASM_EXTABLE(2b, 3b)
6072+#endif
6073+ "4: addu %0, %1, %3 \n"
6074+#ifdef CONFIG_PAX_REFCOUNT
6075+ "5: \n"
6076+#endif
6077+ " .set mips0 \n"
6078+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6079+ : "Ir" (i));
6080+ } else {
6081+ unsigned long flags;
6082+
6083+ raw_local_irq_save(flags);
6084+ __asm__ __volatile__(
6085+ " lw %0, %1 \n"
6086+#ifdef CONFIG_PAX_REFCOUNT
6087+ /* Exception on overflow. */
6088+ "1: add %0, %2 \n"
6089+#else
6090+ " addu %0, %2 \n"
6091+#endif
6092+ " sw %0, %1 \n"
6093+#ifdef CONFIG_PAX_REFCOUNT
6094+ /* Note: Dest reg is not modified on overflow */
6095+ "2: \n"
6096+ _ASM_EXTABLE(1b, 2b)
6097+#endif
6098+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6099+ raw_local_irq_restore(flags);
6100+ }
6101+
6102+ smp_llsc_mb();
6103+
6104+ return result;
6105+}
6106+
6107+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
6108 {
6109 int result;
6110
6111@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
6112 return result;
6113 }
6114
6115-static __inline__ int atomic_sub_return(int i, atomic_t * v)
6116+static __inline__ int atomic_sub_return(int i, atomic_t *v)
6117+{
6118+ int result;
6119+ int temp;
6120+
6121+ smp_mb__before_llsc();
6122+
6123+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6124+ __asm__ __volatile__(
6125+ " .set mips3 \n"
6126+ "1: ll %1, %2 # atomic_sub_return \n"
6127+#ifdef CONFIG_PAX_REFCOUNT
6128+ "2: sub %0, %1, %3 \n"
6129+#else
6130+ " subu %0, %1, %3 \n"
6131+#endif
6132+ " sc %0, %2 \n"
6133+ " beqzl %0, 1b \n"
6134+#ifdef CONFIG_PAX_REFCOUNT
6135+ " b 4f \n"
6136+ " .set noreorder \n"
6137+ "3: b 5f \n"
6138+ " move %0, %1 \n"
6139+ " .set reorder \n"
6140+ _ASM_EXTABLE(2b, 3b)
6141+#endif
6142+ "4: subu %0, %1, %3 \n"
6143+#ifdef CONFIG_PAX_REFCOUNT
6144+ "5: \n"
6145+#endif
6146+ " .set mips0 \n"
6147+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6148+ : "Ir" (i), "m" (v->counter)
6149+ : "memory");
6150+ } else if (kernel_uses_llsc) {
6151+ __asm__ __volatile__(
6152+ " .set mips3 \n"
6153+ "1: ll %1, %2 # atomic_sub_return \n"
6154+#ifdef CONFIG_PAX_REFCOUNT
6155+ "2: sub %0, %1, %3 \n"
6156+#else
6157+ " subu %0, %1, %3 \n"
6158+#endif
6159+ " sc %0, %2 \n"
6160+ " bnez %0, 4f \n"
6161+ " b 1b \n"
6162+#ifdef CONFIG_PAX_REFCOUNT
6163+ " .set noreorder \n"
6164+ "3: b 5f \n"
6165+ " move %0, %1 \n"
6166+ " .set reorder \n"
6167+ _ASM_EXTABLE(2b, 3b)
6168+#endif
6169+ "4: subu %0, %1, %3 \n"
6170+#ifdef CONFIG_PAX_REFCOUNT
6171+ "5: \n"
6172+#endif
6173+ " .set mips0 \n"
6174+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6175+ : "Ir" (i));
6176+ } else {
6177+ unsigned long flags;
6178+
6179+ raw_local_irq_save(flags);
6180+ __asm__ __volatile__(
6181+ " lw %0, %1 \n"
6182+#ifdef CONFIG_PAX_REFCOUNT
6183+ /* Exception on overflow. */
6184+ "1: sub %0, %2 \n"
6185+#else
6186+ " subu %0, %2 \n"
6187+#endif
6188+ " sw %0, %1 \n"
6189+#ifdef CONFIG_PAX_REFCOUNT
6190+ /* Note: Dest reg is not modified on overflow */
6191+ "2: \n"
6192+ _ASM_EXTABLE(1b, 2b)
6193+#endif
6194+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6195+ raw_local_irq_restore(flags);
6196+ }
6197+
6198+ smp_llsc_mb();
6199+
6200+ return result;
6201+}
6202+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
6203 {
6204 int result;
6205
6206@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
6207 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6208 * The function returns the old value of @v minus @i.
6209 */
6210-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6211+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
6212 {
6213 int result;
6214
6215@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6216 return result;
6217 }
6218
6219-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6220-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
6221+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
6222+{
6223+ return cmpxchg(&v->counter, old, new);
6224+}
6225+
6226+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
6227+ int new)
6228+{
6229+ return cmpxchg(&(v->counter), old, new);
6230+}
6231+
6232+static inline int atomic_xchg(atomic_t *v, int new)
6233+{
6234+ return xchg(&v->counter, new);
6235+}
6236+
6237+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6238+{
6239+ return xchg(&(v->counter), new);
6240+}
6241
6242 /**
6243 * __atomic_add_unless - add unless the number is a given value
6244@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6245
6246 #define atomic_dec_return(v) atomic_sub_return(1, (v))
6247 #define atomic_inc_return(v) atomic_add_return(1, (v))
6248+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6249+{
6250+ return atomic_add_return_unchecked(1, v);
6251+}
6252
6253 /*
6254 * atomic_sub_and_test - subtract value from variable and test result
6255@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6256 * other cases.
6257 */
6258 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6259+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6260+{
6261+ return atomic_add_return_unchecked(1, v) == 0;
6262+}
6263
6264 /*
6265 * atomic_dec_and_test - decrement by 1 and test
6266@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6267 * Atomically increments @v by 1.
6268 */
6269 #define atomic_inc(v) atomic_add(1, (v))
6270+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6271+{
6272+ atomic_add_unchecked(1, v);
6273+}
6274
6275 /*
6276 * atomic_dec - decrement and test
6277@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6278 * Atomically decrements @v by 1.
6279 */
6280 #define atomic_dec(v) atomic_sub(1, (v))
6281+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6282+{
6283+ atomic_sub_unchecked(1, v);
6284+}
6285
6286 /*
6287 * atomic_add_negative - add and test if negative
6288@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6289 * @v: pointer of type atomic64_t
6290 *
6291 */
6292-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6293+static inline long atomic64_read(const atomic64_t *v)
6294+{
6295+ return (*(volatile const long *) &v->counter);
6296+}
6297+
6298+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6299+{
6300+ return (*(volatile const long *) &v->counter);
6301+}
6302
6303 /*
6304 * atomic64_set - set atomic variable
6305 * @v: pointer of type atomic64_t
6306 * @i: required value
6307 */
6308-#define atomic64_set(v, i) ((v)->counter = (i))
6309+static inline void atomic64_set(atomic64_t *v, long i)
6310+{
6311+ v->counter = i;
6312+}
6313+
6314+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6315+{
6316+ v->counter = i;
6317+}
6318
6319 /*
6320 * atomic64_add - add integer to atomic variable
6321@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6322 *
6323 * Atomically adds @i to @v.
6324 */
6325-static __inline__ void atomic64_add(long i, atomic64_t * v)
6326+static __inline__ void atomic64_add(long i, atomic64_t *v)
6327+{
6328+ long temp;
6329+
6330+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6331+ __asm__ __volatile__(
6332+ " .set mips3 \n"
6333+ "1: lld %0, %1 # atomic64_add \n"
6334+#ifdef CONFIG_PAX_REFCOUNT
6335+ /* Exception on overflow. */
6336+ "2: dadd %0, %2 \n"
6337+#else
6338+ " daddu %0, %2 \n"
6339+#endif
6340+ " scd %0, %1 \n"
6341+ " beqzl %0, 1b \n"
6342+#ifdef CONFIG_PAX_REFCOUNT
6343+ "3: \n"
6344+ _ASM_EXTABLE(2b, 3b)
6345+#endif
6346+ " .set mips0 \n"
6347+ : "=&r" (temp), "+m" (v->counter)
6348+ : "Ir" (i));
6349+ } else if (kernel_uses_llsc) {
6350+ __asm__ __volatile__(
6351+ " .set mips3 \n"
6352+ "1: lld %0, %1 # atomic64_add \n"
6353+#ifdef CONFIG_PAX_REFCOUNT
6354+ /* Exception on overflow. */
6355+ "2: dadd %0, %2 \n"
6356+#else
6357+ " daddu %0, %2 \n"
6358+#endif
6359+ " scd %0, %1 \n"
6360+ " beqz %0, 1b \n"
6361+#ifdef CONFIG_PAX_REFCOUNT
6362+ "3: \n"
6363+ _ASM_EXTABLE(2b, 3b)
6364+#endif
6365+ " .set mips0 \n"
6366+ : "=&r" (temp), "+m" (v->counter)
6367+ : "Ir" (i));
6368+ } else {
6369+ unsigned long flags;
6370+
6371+ raw_local_irq_save(flags);
6372+ __asm__ __volatile__(
6373+#ifdef CONFIG_PAX_REFCOUNT
6374+ /* Exception on overflow. */
6375+ "1: dadd %0, %1 \n"
6376+ "2: \n"
6377+ _ASM_EXTABLE(1b, 2b)
6378+#else
6379+ " daddu %0, %1 \n"
6380+#endif
6381+ : "+r" (v->counter) : "Ir" (i));
6382+ raw_local_irq_restore(flags);
6383+ }
6384+}
6385+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6386 {
6387 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6388 long temp;
6389@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6390 *
6391 * Atomically subtracts @i from @v.
6392 */
6393-static __inline__ void atomic64_sub(long i, atomic64_t * v)
6394+static __inline__ void atomic64_sub(long i, atomic64_t *v)
6395+{
6396+ long temp;
6397+
6398+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6399+ __asm__ __volatile__(
6400+ " .set mips3 \n"
6401+ "1: lld %0, %1 # atomic64_sub \n"
6402+#ifdef CONFIG_PAX_REFCOUNT
6403+ /* Exception on overflow. */
6404+ "2: dsub %0, %2 \n"
6405+#else
6406+ " dsubu %0, %2 \n"
6407+#endif
6408+ " scd %0, %1 \n"
6409+ " beqzl %0, 1b \n"
6410+#ifdef CONFIG_PAX_REFCOUNT
6411+ "3: \n"
6412+ _ASM_EXTABLE(2b, 3b)
6413+#endif
6414+ " .set mips0 \n"
6415+ : "=&r" (temp), "+m" (v->counter)
6416+ : "Ir" (i));
6417+ } else if (kernel_uses_llsc) {
6418+ __asm__ __volatile__(
6419+ " .set mips3 \n"
6420+ "1: lld %0, %1 # atomic64_sub \n"
6421+#ifdef CONFIG_PAX_REFCOUNT
6422+ /* Exception on overflow. */
6423+ "2: dsub %0, %2 \n"
6424+#else
6425+ " dsubu %0, %2 \n"
6426+#endif
6427+ " scd %0, %1 \n"
6428+ " beqz %0, 1b \n"
6429+#ifdef CONFIG_PAX_REFCOUNT
6430+ "3: \n"
6431+ _ASM_EXTABLE(2b, 3b)
6432+#endif
6433+ " .set mips0 \n"
6434+ : "=&r" (temp), "+m" (v->counter)
6435+ : "Ir" (i));
6436+ } else {
6437+ unsigned long flags;
6438+
6439+ raw_local_irq_save(flags);
6440+ __asm__ __volatile__(
6441+#ifdef CONFIG_PAX_REFCOUNT
6442+ /* Exception on overflow. */
6443+ "1: dsub %0, %1 \n"
6444+ "2: \n"
6445+ _ASM_EXTABLE(1b, 2b)
6446+#else
6447+ " dsubu %0, %1 \n"
6448+#endif
6449+ : "+r" (v->counter) : "Ir" (i));
6450+ raw_local_irq_restore(flags);
6451+ }
6452+}
6453+
6454+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6455 {
6456 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6457 long temp;
6458@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6459 /*
6460 * Same as above, but return the result value
6461 */
6462-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6463+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6464+{
6465+ long result;
6466+ long temp;
6467+
6468+ smp_mb__before_llsc();
6469+
6470+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6471+ __asm__ __volatile__(
6472+ " .set mips3 \n"
6473+ "1: lld %1, %2 # atomic64_add_return \n"
6474+#ifdef CONFIG_PAX_REFCOUNT
6475+ "2: dadd %0, %1, %3 \n"
6476+#else
6477+ " daddu %0, %1, %3 \n"
6478+#endif
6479+ " scd %0, %2 \n"
6480+ " beqzl %0, 1b \n"
6481+#ifdef CONFIG_PAX_REFCOUNT
6482+ " b 4f \n"
6483+ " .set noreorder \n"
6484+ "3: b 5f \n"
6485+ " move %0, %1 \n"
6486+ " .set reorder \n"
6487+ _ASM_EXTABLE(2b, 3b)
6488+#endif
6489+ "4: daddu %0, %1, %3 \n"
6490+#ifdef CONFIG_PAX_REFCOUNT
6491+ "5: \n"
6492+#endif
6493+ " .set mips0 \n"
6494+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6495+ : "Ir" (i));
6496+ } else if (kernel_uses_llsc) {
6497+ __asm__ __volatile__(
6498+ " .set mips3 \n"
6499+ "1: lld %1, %2 # atomic64_add_return \n"
6500+#ifdef CONFIG_PAX_REFCOUNT
6501+ "2: dadd %0, %1, %3 \n"
6502+#else
6503+ " daddu %0, %1, %3 \n"
6504+#endif
6505+ " scd %0, %2 \n"
6506+ " bnez %0, 4f \n"
6507+ " b 1b \n"
6508+#ifdef CONFIG_PAX_REFCOUNT
6509+ " .set noreorder \n"
6510+ "3: b 5f \n"
6511+ " move %0, %1 \n"
6512+ " .set reorder \n"
6513+ _ASM_EXTABLE(2b, 3b)
6514+#endif
6515+ "4: daddu %0, %1, %3 \n"
6516+#ifdef CONFIG_PAX_REFCOUNT
6517+ "5: \n"
6518+#endif
6519+ " .set mips0 \n"
6520+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6521+ : "Ir" (i), "m" (v->counter)
6522+ : "memory");
6523+ } else {
6524+ unsigned long flags;
6525+
6526+ raw_local_irq_save(flags);
6527+ __asm__ __volatile__(
6528+ " ld %0, %1 \n"
6529+#ifdef CONFIG_PAX_REFCOUNT
6530+ /* Exception on overflow. */
6531+ "1: dadd %0, %2 \n"
6532+#else
6533+ " daddu %0, %2 \n"
6534+#endif
6535+ " sd %0, %1 \n"
6536+#ifdef CONFIG_PAX_REFCOUNT
6537+ /* Note: Dest reg is not modified on overflow */
6538+ "2: \n"
6539+ _ASM_EXTABLE(1b, 2b)
6540+#endif
6541+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6542+ raw_local_irq_restore(flags);
6543+ }
6544+
6545+ smp_llsc_mb();
6546+
6547+ return result;
6548+}
6549+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6550 {
6551 long result;
6552
6553@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6554 return result;
6555 }
6556
6557-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6558+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6559+{
6560+ long result;
6561+ long temp;
6562+
6563+ smp_mb__before_llsc();
6564+
6565+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6566+ long temp;
6567+
6568+ __asm__ __volatile__(
6569+ " .set mips3 \n"
6570+ "1: lld %1, %2 # atomic64_sub_return \n"
6571+#ifdef CONFIG_PAX_REFCOUNT
6572+ "2: dsub %0, %1, %3 \n"
6573+#else
6574+ " dsubu %0, %1, %3 \n"
6575+#endif
6576+ " scd %0, %2 \n"
6577+ " beqzl %0, 1b \n"
6578+#ifdef CONFIG_PAX_REFCOUNT
6579+ " b 4f \n"
6580+ " .set noreorder \n"
6581+ "3: b 5f \n"
6582+ " move %0, %1 \n"
6583+ " .set reorder \n"
6584+ _ASM_EXTABLE(2b, 3b)
6585+#endif
6586+ "4: dsubu %0, %1, %3 \n"
6587+#ifdef CONFIG_PAX_REFCOUNT
6588+ "5: \n"
6589+#endif
6590+ " .set mips0 \n"
6591+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6592+ : "Ir" (i), "m" (v->counter)
6593+ : "memory");
6594+ } else if (kernel_uses_llsc) {
6595+ __asm__ __volatile__(
6596+ " .set mips3 \n"
6597+ "1: lld %1, %2 # atomic64_sub_return \n"
6598+#ifdef CONFIG_PAX_REFCOUNT
6599+ "2: dsub %0, %1, %3 \n"
6600+#else
6601+ " dsubu %0, %1, %3 \n"
6602+#endif
6603+ " scd %0, %2 \n"
6604+ " bnez %0, 4f \n"
6605+ " b 1b \n"
6606+#ifdef CONFIG_PAX_REFCOUNT
6607+ " .set noreorder \n"
6608+ "3: b 5f \n"
6609+ " move %0, %1 \n"
6610+ " .set reorder \n"
6611+ _ASM_EXTABLE(2b, 3b)
6612+#endif
6613+ "4: dsubu %0, %1, %3 \n"
6614+#ifdef CONFIG_PAX_REFCOUNT
6615+ "5: \n"
6616+#endif
6617+ " .set mips0 \n"
6618+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6619+ : "Ir" (i), "m" (v->counter)
6620+ : "memory");
6621+ } else {
6622+ unsigned long flags;
6623+
6624+ raw_local_irq_save(flags);
6625+ __asm__ __volatile__(
6626+ " ld %0, %1 \n"
6627+#ifdef CONFIG_PAX_REFCOUNT
6628+ /* Exception on overflow. */
6629+ "1: dsub %0, %2 \n"
6630+#else
6631+ " dsubu %0, %2 \n"
6632+#endif
6633+ " sd %0, %1 \n"
6634+#ifdef CONFIG_PAX_REFCOUNT
6635+ /* Note: Dest reg is not modified on overflow */
6636+ "2: \n"
6637+ _ASM_EXTABLE(1b, 2b)
6638+#endif
6639+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6640+ raw_local_irq_restore(flags);
6641+ }
6642+
6643+ smp_llsc_mb();
6644+
6645+ return result;
6646+}
6647+
6648+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6649 {
6650 long result;
6651
6652@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6653 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6654 * The function returns the old value of @v minus @i.
6655 */
6656-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6657+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6658 {
6659 long result;
6660
6661@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6662 return result;
6663 }
6664
6665-#define atomic64_cmpxchg(v, o, n) \
6666- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6667-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6668+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6669+{
6670+ return cmpxchg(&v->counter, old, new);
6671+}
6672+
6673+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6674+ long new)
6675+{
6676+ return cmpxchg(&(v->counter), old, new);
6677+}
6678+
6679+static inline long atomic64_xchg(atomic64_t *v, long new)
6680+{
6681+ return xchg(&v->counter, new);
6682+}
6683+
6684+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6685+{
6686+ return xchg(&(v->counter), new);
6687+}
6688
6689 /**
6690 * atomic64_add_unless - add unless the number is a given value
6691@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6692
6693 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6694 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6695+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6696
6697 /*
6698 * atomic64_sub_and_test - subtract value from variable and test result
6699@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6700 * other cases.
6701 */
6702 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6703+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6704
6705 /*
6706 * atomic64_dec_and_test - decrement by 1 and test
6707@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6708 * Atomically increments @v by 1.
6709 */
6710 #define atomic64_inc(v) atomic64_add(1, (v))
6711+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6712
6713 /*
6714 * atomic64_dec - decrement and test
6715@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6716 * Atomically decrements @v by 1.
6717 */
6718 #define atomic64_dec(v) atomic64_sub(1, (v))
6719+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6720
6721 /*
6722 * atomic64_add_negative - add and test if negative
6723diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
6724index d0101dd..266982c 100644
6725--- a/arch/mips/include/asm/barrier.h
6726+++ b/arch/mips/include/asm/barrier.h
6727@@ -184,7 +184,7 @@
6728 do { \
6729 compiletime_assert_atomic_type(*p); \
6730 smp_mb(); \
6731- ACCESS_ONCE(*p) = (v); \
6732+ ACCESS_ONCE_RW(*p) = (v); \
6733 } while (0)
6734
6735 #define smp_load_acquire(p) \
6736diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6737index b4db69f..8f3b093 100644
6738--- a/arch/mips/include/asm/cache.h
6739+++ b/arch/mips/include/asm/cache.h
6740@@ -9,10 +9,11 @@
6741 #ifndef _ASM_CACHE_H
6742 #define _ASM_CACHE_H
6743
6744+#include <linux/const.h>
6745 #include <kmalloc.h>
6746
6747 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6748-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6749+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6750
6751 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6752 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6753diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6754index 1d38fe0..9beabc9 100644
6755--- a/arch/mips/include/asm/elf.h
6756+++ b/arch/mips/include/asm/elf.h
6757@@ -381,13 +381,16 @@ extern const char *__elf_platform;
6758 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6759 #endif
6760
6761+#ifdef CONFIG_PAX_ASLR
6762+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6763+
6764+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6765+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6766+#endif
6767+
6768 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6769 struct linux_binprm;
6770 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6771 int uses_interp);
6772
6773-struct mm_struct;
6774-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6775-#define arch_randomize_brk arch_randomize_brk
6776-
6777 #endif /* _ASM_ELF_H */
6778diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6779index c1f6afa..38cc6e9 100644
6780--- a/arch/mips/include/asm/exec.h
6781+++ b/arch/mips/include/asm/exec.h
6782@@ -12,6 +12,6 @@
6783 #ifndef _ASM_EXEC_H
6784 #define _ASM_EXEC_H
6785
6786-extern unsigned long arch_align_stack(unsigned long sp);
6787+#define arch_align_stack(x) ((x) & ~0xfUL)
6788
6789 #endif /* _ASM_EXEC_H */
6790diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6791index 9e8ef59..1139d6b 100644
6792--- a/arch/mips/include/asm/hw_irq.h
6793+++ b/arch/mips/include/asm/hw_irq.h
6794@@ -10,7 +10,7 @@
6795
6796 #include <linux/atomic.h>
6797
6798-extern atomic_t irq_err_count;
6799+extern atomic_unchecked_t irq_err_count;
6800
6801 /*
6802 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6803diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6804index 46dfc3c..a16b13a 100644
6805--- a/arch/mips/include/asm/local.h
6806+++ b/arch/mips/include/asm/local.h
6807@@ -12,15 +12,25 @@ typedef struct
6808 atomic_long_t a;
6809 } local_t;
6810
6811+typedef struct {
6812+ atomic_long_unchecked_t a;
6813+} local_unchecked_t;
6814+
6815 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6816
6817 #define local_read(l) atomic_long_read(&(l)->a)
6818+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6819 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6820+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6821
6822 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6823+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6824 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6825+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6826 #define local_inc(l) atomic_long_inc(&(l)->a)
6827+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6828 #define local_dec(l) atomic_long_dec(&(l)->a)
6829+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6830
6831 /*
6832 * Same as above, but return the result value
6833@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6834 return result;
6835 }
6836
6837+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6838+{
6839+ unsigned long result;
6840+
6841+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6842+ unsigned long temp;
6843+
6844+ __asm__ __volatile__(
6845+ " .set mips3 \n"
6846+ "1:" __LL "%1, %2 # local_add_return \n"
6847+ " addu %0, %1, %3 \n"
6848+ __SC "%0, %2 \n"
6849+ " beqzl %0, 1b \n"
6850+ " addu %0, %1, %3 \n"
6851+ " .set mips0 \n"
6852+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6853+ : "Ir" (i), "m" (l->a.counter)
6854+ : "memory");
6855+ } else if (kernel_uses_llsc) {
6856+ unsigned long temp;
6857+
6858+ __asm__ __volatile__(
6859+ " .set mips3 \n"
6860+ "1:" __LL "%1, %2 # local_add_return \n"
6861+ " addu %0, %1, %3 \n"
6862+ __SC "%0, %2 \n"
6863+ " beqz %0, 1b \n"
6864+ " addu %0, %1, %3 \n"
6865+ " .set mips0 \n"
6866+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6867+ : "Ir" (i), "m" (l->a.counter)
6868+ : "memory");
6869+ } else {
6870+ unsigned long flags;
6871+
6872+ local_irq_save(flags);
6873+ result = l->a.counter;
6874+ result += i;
6875+ l->a.counter = result;
6876+ local_irq_restore(flags);
6877+ }
6878+
6879+ return result;
6880+}
6881+
6882 static __inline__ long local_sub_return(long i, local_t * l)
6883 {
6884 unsigned long result;
6885@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6886
6887 #define local_cmpxchg(l, o, n) \
6888 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6889+#define local_cmpxchg_unchecked(l, o, n) \
6890+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6891 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6892
6893 /**
6894diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6895index 3be8180..c4798d5 100644
6896--- a/arch/mips/include/asm/page.h
6897+++ b/arch/mips/include/asm/page.h
6898@@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6899 #ifdef CONFIG_CPU_MIPS32
6900 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6901 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6902- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6903+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6904 #else
6905 typedef struct { unsigned long long pte; } pte_t;
6906 #define pte_val(x) ((x).pte)
6907diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6908index b336037..5b874cc 100644
6909--- a/arch/mips/include/asm/pgalloc.h
6910+++ b/arch/mips/include/asm/pgalloc.h
6911@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6912 {
6913 set_pud(pud, __pud((unsigned long)pmd));
6914 }
6915+
6916+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6917+{
6918+ pud_populate(mm, pud, pmd);
6919+}
6920 #endif
6921
6922 /*
6923diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6924index df49a30..c0d3dd6 100644
6925--- a/arch/mips/include/asm/pgtable.h
6926+++ b/arch/mips/include/asm/pgtable.h
6927@@ -20,6 +20,9 @@
6928 #include <asm/io.h>
6929 #include <asm/pgtable-bits.h>
6930
6931+#define ktla_ktva(addr) (addr)
6932+#define ktva_ktla(addr) (addr)
6933+
6934 struct mm_struct;
6935 struct vm_area_struct;
6936
6937diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6938index 7de8658..c109224 100644
6939--- a/arch/mips/include/asm/thread_info.h
6940+++ b/arch/mips/include/asm/thread_info.h
6941@@ -105,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6942 #define TIF_SECCOMP 4 /* secure computing */
6943 #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
6944 #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
6945+/* li takes a 32bit immediate */
6946+#define TIF_GRSEC_SETXID 10 /* update credentials on syscall entry/exit */
6947+
6948 #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
6949 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
6950 #define TIF_NOHZ 19 /* in adaptive nohz mode */
6951@@ -138,14 +141,16 @@ static inline struct thread_info *current_thread_info(void)
6952 #define _TIF_USEDMSA (1<<TIF_USEDMSA)
6953 #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
6954 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6955+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6956
6957 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6958 _TIF_SYSCALL_AUDIT | \
6959- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
6960+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
6961+ _TIF_GRSEC_SETXID)
6962
6963 /* work to do in syscall_trace_leave() */
6964 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6965- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6966+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6967
6968 /* work to do on interrupt/exception return */
6969 #define _TIF_WORK_MASK \
6970@@ -153,7 +158,7 @@ static inline struct thread_info *current_thread_info(void)
6971 /* work to do on any return to u-space */
6972 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6973 _TIF_WORK_SYSCALL_EXIT | \
6974- _TIF_SYSCALL_TRACEPOINT)
6975+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6976
6977 /*
6978 * We stash processor id into a COP0 register to retrieve it fast
6979diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6980index b9ab717..3a15c28 100644
6981--- a/arch/mips/include/asm/uaccess.h
6982+++ b/arch/mips/include/asm/uaccess.h
6983@@ -130,6 +130,7 @@ extern u64 __ua_limit;
6984 __ok == 0; \
6985 })
6986
6987+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6988 #define access_ok(type, addr, size) \
6989 likely(__access_ok((addr), (size), __access_mask))
6990
6991@@ -301,7 +302,8 @@ do { \
6992 __get_kernel_common((x), size, __gu_ptr); \
6993 else \
6994 __get_user_common((x), size, __gu_ptr); \
6995- } \
6996+ } else \
6997+ (x) = 0; \
6998 \
6999 __gu_err; \
7000 })
7001@@ -316,6 +318,7 @@ do { \
7002 " .insn \n" \
7003 " .section .fixup,\"ax\" \n" \
7004 "3: li %0, %4 \n" \
7005+ " move %1, $0 \n" \
7006 " j 2b \n" \
7007 " .previous \n" \
7008 " .section __ex_table,\"a\" \n" \
7009@@ -630,6 +633,7 @@ do { \
7010 " .insn \n" \
7011 " .section .fixup,\"ax\" \n" \
7012 "3: li %0, %4 \n" \
7013+ " move %1, $0 \n" \
7014 " j 2b \n" \
7015 " .previous \n" \
7016 " .section __ex_table,\"a\" \n" \
7017diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
7018index 1188e00..41cf144 100644
7019--- a/arch/mips/kernel/binfmt_elfn32.c
7020+++ b/arch/mips/kernel/binfmt_elfn32.c
7021@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
7022 #undef ELF_ET_DYN_BASE
7023 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
7024
7025+#ifdef CONFIG_PAX_ASLR
7026+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
7027+
7028+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7029+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7030+#endif
7031+
7032 #include <asm/processor.h>
7033 #include <linux/module.h>
7034 #include <linux/elfcore.h>
7035diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
7036index 9287678..f870e47 100644
7037--- a/arch/mips/kernel/binfmt_elfo32.c
7038+++ b/arch/mips/kernel/binfmt_elfo32.c
7039@@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
7040 #undef ELF_ET_DYN_BASE
7041 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
7042
7043+#ifdef CONFIG_PAX_ASLR
7044+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
7045+
7046+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7047+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7048+#endif
7049+
7050 #include <asm/processor.h>
7051
7052 #include <linux/module.h>
7053diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
7054index 50b3648..c2f3cec 100644
7055--- a/arch/mips/kernel/i8259.c
7056+++ b/arch/mips/kernel/i8259.c
7057@@ -201,7 +201,7 @@ spurious_8259A_irq:
7058 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
7059 spurious_irq_mask |= irqmask;
7060 }
7061- atomic_inc(&irq_err_count);
7062+ atomic_inc_unchecked(&irq_err_count);
7063 /*
7064 * Theoretically we do not have to handle this IRQ,
7065 * but in Linux this does not cause problems and is
7066diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
7067index 44a1f79..2bd6aa3 100644
7068--- a/arch/mips/kernel/irq-gt641xx.c
7069+++ b/arch/mips/kernel/irq-gt641xx.c
7070@@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
7071 }
7072 }
7073
7074- atomic_inc(&irq_err_count);
7075+ atomic_inc_unchecked(&irq_err_count);
7076 }
7077
7078 void __init gt641xx_irq_init(void)
7079diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
7080index d2bfbc2..a8eacd2 100644
7081--- a/arch/mips/kernel/irq.c
7082+++ b/arch/mips/kernel/irq.c
7083@@ -76,17 +76,17 @@ void ack_bad_irq(unsigned int irq)
7084 printk("unexpected IRQ # %d\n", irq);
7085 }
7086
7087-atomic_t irq_err_count;
7088+atomic_unchecked_t irq_err_count;
7089
7090 int arch_show_interrupts(struct seq_file *p, int prec)
7091 {
7092- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
7093+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
7094 return 0;
7095 }
7096
7097 asmlinkage void spurious_interrupt(void)
7098 {
7099- atomic_inc(&irq_err_count);
7100+ atomic_inc_unchecked(&irq_err_count);
7101 }
7102
7103 void __init init_IRQ(void)
7104@@ -109,7 +109,10 @@ void __init init_IRQ(void)
7105 #endif
7106 }
7107
7108+
7109 #ifdef DEBUG_STACKOVERFLOW
7110+extern void gr_handle_kernel_exploit(void);
7111+
7112 static inline void check_stack_overflow(void)
7113 {
7114 unsigned long sp;
7115@@ -125,6 +128,7 @@ static inline void check_stack_overflow(void)
7116 printk("do_IRQ: stack overflow: %ld\n",
7117 sp - sizeof(struct thread_info));
7118 dump_stack();
7119+ gr_handle_kernel_exploit();
7120 }
7121 }
7122 #else
7123diff --git a/arch/mips/kernel/pm-cps.c b/arch/mips/kernel/pm-cps.c
7124index 0614717..002fa43 100644
7125--- a/arch/mips/kernel/pm-cps.c
7126+++ b/arch/mips/kernel/pm-cps.c
7127@@ -172,7 +172,7 @@ int cps_pm_enter_state(enum cps_pm_state state)
7128 nc_core_ready_count = nc_addr;
7129
7130 /* Ensure ready_count is zero-initialised before the assembly runs */
7131- ACCESS_ONCE(*nc_core_ready_count) = 0;
7132+ ACCESS_ONCE_RW(*nc_core_ready_count) = 0;
7133 coupled_barrier(&per_cpu(pm_barrier, core), online);
7134
7135 /* Run the generated entry code */
7136diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
7137index 636b074..8fbb91f 100644
7138--- a/arch/mips/kernel/process.c
7139+++ b/arch/mips/kernel/process.c
7140@@ -520,15 +520,3 @@ unsigned long get_wchan(struct task_struct *task)
7141 out:
7142 return pc;
7143 }
7144-
7145-/*
7146- * Don't forget that the stack pointer must be aligned on a 8 bytes
7147- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
7148- */
7149-unsigned long arch_align_stack(unsigned long sp)
7150-{
7151- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7152- sp -= get_random_int() & ~PAGE_MASK;
7153-
7154- return sp & ALMASK;
7155-}
7156diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
7157index 645b3c4..909c75a 100644
7158--- a/arch/mips/kernel/ptrace.c
7159+++ b/arch/mips/kernel/ptrace.c
7160@@ -761,6 +761,10 @@ long arch_ptrace(struct task_struct *child, long request,
7161 return ret;
7162 }
7163
7164+#ifdef CONFIG_GRKERNSEC_SETXID
7165+extern void gr_delayed_cred_worker(void);
7166+#endif
7167+
7168 /*
7169 * Notification of system call entry/exit
7170 * - triggered by current->work.syscall_trace
7171@@ -777,6 +781,11 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
7172 tracehook_report_syscall_entry(regs))
7173 ret = -1;
7174
7175+#ifdef CONFIG_GRKERNSEC_SETXID
7176+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
7177+ gr_delayed_cred_worker();
7178+#endif
7179+
7180 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
7181 trace_sys_enter(regs, regs->regs[2]);
7182
7183diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
7184index 07fc524..b9d7f28 100644
7185--- a/arch/mips/kernel/reset.c
7186+++ b/arch/mips/kernel/reset.c
7187@@ -13,6 +13,7 @@
7188 #include <linux/reboot.h>
7189
7190 #include <asm/reboot.h>
7191+#include <asm/bug.h>
7192
7193 /*
7194 * Urgs ... Too many MIPS machines to handle this in a generic way.
7195@@ -29,16 +30,19 @@ void machine_restart(char *command)
7196 {
7197 if (_machine_restart)
7198 _machine_restart(command);
7199+ BUG();
7200 }
7201
7202 void machine_halt(void)
7203 {
7204 if (_machine_halt)
7205 _machine_halt();
7206+ BUG();
7207 }
7208
7209 void machine_power_off(void)
7210 {
7211 if (pm_power_off)
7212 pm_power_off();
7213+ BUG();
7214 }
7215diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
7216index 2242bdd..b284048 100644
7217--- a/arch/mips/kernel/sync-r4k.c
7218+++ b/arch/mips/kernel/sync-r4k.c
7219@@ -18,8 +18,8 @@
7220 #include <asm/mipsregs.h>
7221
7222 static atomic_t count_start_flag = ATOMIC_INIT(0);
7223-static atomic_t count_count_start = ATOMIC_INIT(0);
7224-static atomic_t count_count_stop = ATOMIC_INIT(0);
7225+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
7226+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
7227 static atomic_t count_reference = ATOMIC_INIT(0);
7228
7229 #define COUNTON 100
7230@@ -58,13 +58,13 @@ void synchronise_count_master(int cpu)
7231
7232 for (i = 0; i < NR_LOOPS; i++) {
7233 /* slaves loop on '!= 2' */
7234- while (atomic_read(&count_count_start) != 1)
7235+ while (atomic_read_unchecked(&count_count_start) != 1)
7236 mb();
7237- atomic_set(&count_count_stop, 0);
7238+ atomic_set_unchecked(&count_count_stop, 0);
7239 smp_wmb();
7240
7241 /* this lets the slaves write their count register */
7242- atomic_inc(&count_count_start);
7243+ atomic_inc_unchecked(&count_count_start);
7244
7245 /*
7246 * Everyone initialises count in the last loop:
7247@@ -75,11 +75,11 @@ void synchronise_count_master(int cpu)
7248 /*
7249 * Wait for all slaves to leave the synchronization point:
7250 */
7251- while (atomic_read(&count_count_stop) != 1)
7252+ while (atomic_read_unchecked(&count_count_stop) != 1)
7253 mb();
7254- atomic_set(&count_count_start, 0);
7255+ atomic_set_unchecked(&count_count_start, 0);
7256 smp_wmb();
7257- atomic_inc(&count_count_stop);
7258+ atomic_inc_unchecked(&count_count_stop);
7259 }
7260 /* Arrange for an interrupt in a short while */
7261 write_c0_compare(read_c0_count() + COUNTON);
7262@@ -112,8 +112,8 @@ void synchronise_count_slave(int cpu)
7263 initcount = atomic_read(&count_reference);
7264
7265 for (i = 0; i < NR_LOOPS; i++) {
7266- atomic_inc(&count_count_start);
7267- while (atomic_read(&count_count_start) != 2)
7268+ atomic_inc_unchecked(&count_count_start);
7269+ while (atomic_read_unchecked(&count_count_start) != 2)
7270 mb();
7271
7272 /*
7273@@ -122,8 +122,8 @@ void synchronise_count_slave(int cpu)
7274 if (i == NR_LOOPS-1)
7275 write_c0_count(initcount);
7276
7277- atomic_inc(&count_count_stop);
7278- while (atomic_read(&count_count_stop) != 2)
7279+ atomic_inc_unchecked(&count_count_stop);
7280+ while (atomic_read_unchecked(&count_count_stop) != 2)
7281 mb();
7282 }
7283 /* Arrange for an interrupt in a short while */
7284diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7285index 22b19c2..c5cc8c4 100644
7286--- a/arch/mips/kernel/traps.c
7287+++ b/arch/mips/kernel/traps.c
7288@@ -688,7 +688,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7289 siginfo_t info;
7290
7291 prev_state = exception_enter();
7292- die_if_kernel("Integer overflow", regs);
7293+ if (unlikely(!user_mode(regs))) {
7294+
7295+#ifdef CONFIG_PAX_REFCOUNT
7296+ if (fixup_exception(regs)) {
7297+ pax_report_refcount_overflow(regs);
7298+ exception_exit(prev_state);
7299+ return;
7300+ }
7301+#endif
7302+
7303+ die("Integer overflow", regs);
7304+ }
7305
7306 info.si_code = FPE_INTOVF;
7307 info.si_signo = SIGFPE;
7308diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
7309index cd71141..e02c4df 100644
7310--- a/arch/mips/kvm/mips.c
7311+++ b/arch/mips/kvm/mips.c
7312@@ -839,7 +839,7 @@ long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
7313 return r;
7314 }
7315
7316-int kvm_arch_init(void *opaque)
7317+int kvm_arch_init(const void *opaque)
7318 {
7319 if (kvm_mips_callbacks) {
7320 kvm_err("kvm: module already exists\n");
7321diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7322index becc42b..9e43d4b 100644
7323--- a/arch/mips/mm/fault.c
7324+++ b/arch/mips/mm/fault.c
7325@@ -28,6 +28,23 @@
7326 #include <asm/highmem.h> /* For VMALLOC_END */
7327 #include <linux/kdebug.h>
7328
7329+#ifdef CONFIG_PAX_PAGEEXEC
7330+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7331+{
7332+ unsigned long i;
7333+
7334+ printk(KERN_ERR "PAX: bytes at PC: ");
7335+ for (i = 0; i < 5; i++) {
7336+ unsigned int c;
7337+ if (get_user(c, (unsigned int *)pc+i))
7338+ printk(KERN_CONT "???????? ");
7339+ else
7340+ printk(KERN_CONT "%08x ", c);
7341+ }
7342+ printk("\n");
7343+}
7344+#endif
7345+
7346 /*
7347 * This routine handles page faults. It determines the address,
7348 * and the problem, and then passes it off to one of the appropriate
7349@@ -199,6 +216,14 @@ bad_area:
7350 bad_area_nosemaphore:
7351 /* User mode accesses just cause a SIGSEGV */
7352 if (user_mode(regs)) {
7353+
7354+#ifdef CONFIG_PAX_PAGEEXEC
7355+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7356+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7357+ do_group_exit(SIGKILL);
7358+ }
7359+#endif
7360+
7361 tsk->thread.cp0_badvaddr = address;
7362 tsk->thread.error_code = write;
7363 #if 0
7364diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7365index f1baadd..5472dca 100644
7366--- a/arch/mips/mm/mmap.c
7367+++ b/arch/mips/mm/mmap.c
7368@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7369 struct vm_area_struct *vma;
7370 unsigned long addr = addr0;
7371 int do_color_align;
7372+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7373 struct vm_unmapped_area_info info;
7374
7375 if (unlikely(len > TASK_SIZE))
7376@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7377 do_color_align = 1;
7378
7379 /* requesting a specific address */
7380+
7381+#ifdef CONFIG_PAX_RANDMMAP
7382+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7383+#endif
7384+
7385 if (addr) {
7386 if (do_color_align)
7387 addr = COLOUR_ALIGN(addr, pgoff);
7388@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7389 addr = PAGE_ALIGN(addr);
7390
7391 vma = find_vma(mm, addr);
7392- if (TASK_SIZE - len >= addr &&
7393- (!vma || addr + len <= vma->vm_start))
7394+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7395 return addr;
7396 }
7397
7398 info.length = len;
7399 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7400 info.align_offset = pgoff << PAGE_SHIFT;
7401+ info.threadstack_offset = offset;
7402
7403 if (dir == DOWN) {
7404 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7405@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7406 {
7407 unsigned long random_factor = 0UL;
7408
7409+#ifdef CONFIG_PAX_RANDMMAP
7410+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7411+#endif
7412+
7413 if (current->flags & PF_RANDOMIZE) {
7414 random_factor = get_random_int();
7415 random_factor = random_factor << PAGE_SHIFT;
7416@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7417
7418 if (mmap_is_legacy()) {
7419 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7420+
7421+#ifdef CONFIG_PAX_RANDMMAP
7422+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7423+ mm->mmap_base += mm->delta_mmap;
7424+#endif
7425+
7426 mm->get_unmapped_area = arch_get_unmapped_area;
7427 } else {
7428 mm->mmap_base = mmap_base(random_factor);
7429+
7430+#ifdef CONFIG_PAX_RANDMMAP
7431+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7432+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7433+#endif
7434+
7435 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7436 }
7437 }
7438
7439-static inline unsigned long brk_rnd(void)
7440-{
7441- unsigned long rnd = get_random_int();
7442-
7443- rnd = rnd << PAGE_SHIFT;
7444- /* 8MB for 32bit, 256MB for 64bit */
7445- if (TASK_IS_32BIT_ADDR)
7446- rnd = rnd & 0x7ffffful;
7447- else
7448- rnd = rnd & 0xffffffful;
7449-
7450- return rnd;
7451-}
7452-
7453-unsigned long arch_randomize_brk(struct mm_struct *mm)
7454-{
7455- unsigned long base = mm->brk;
7456- unsigned long ret;
7457-
7458- ret = PAGE_ALIGN(base + brk_rnd());
7459-
7460- if (ret < mm->brk)
7461- return mm->brk;
7462-
7463- return ret;
7464-}
7465-
7466 int __virt_addr_valid(const volatile void *kaddr)
7467 {
7468 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7469diff --git a/arch/mips/net/bpf_jit.c b/arch/mips/net/bpf_jit.c
7470index 9f7ecbd..6e370fc 100644
7471--- a/arch/mips/net/bpf_jit.c
7472+++ b/arch/mips/net/bpf_jit.c
7473@@ -1428,5 +1428,6 @@ void bpf_jit_free(struct bpf_prog *fp)
7474 {
7475 if (fp->jited)
7476 module_free(NULL, fp->bpf_func);
7477- kfree(fp);
7478+
7479+ bpf_prog_unlock_free(fp);
7480 }
7481diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7482index 59cccd9..f39ac2f 100644
7483--- a/arch/mips/pci/pci-octeon.c
7484+++ b/arch/mips/pci/pci-octeon.c
7485@@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7486
7487
7488 static struct pci_ops octeon_pci_ops = {
7489- octeon_read_config,
7490- octeon_write_config,
7491+ .read = octeon_read_config,
7492+ .write = octeon_write_config,
7493 };
7494
7495 static struct resource octeon_pci_mem_resource = {
7496diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7497index 5e36c33..eb4a17b 100644
7498--- a/arch/mips/pci/pcie-octeon.c
7499+++ b/arch/mips/pci/pcie-octeon.c
7500@@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7501 }
7502
7503 static struct pci_ops octeon_pcie0_ops = {
7504- octeon_pcie0_read_config,
7505- octeon_pcie0_write_config,
7506+ .read = octeon_pcie0_read_config,
7507+ .write = octeon_pcie0_write_config,
7508 };
7509
7510 static struct resource octeon_pcie0_mem_resource = {
7511@@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7512 };
7513
7514 static struct pci_ops octeon_pcie1_ops = {
7515- octeon_pcie1_read_config,
7516- octeon_pcie1_write_config,
7517+ .read = octeon_pcie1_read_config,
7518+ .write = octeon_pcie1_write_config,
7519 };
7520
7521 static struct resource octeon_pcie1_mem_resource = {
7522@@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7523 };
7524
7525 static struct pci_ops octeon_dummy_ops = {
7526- octeon_dummy_read_config,
7527- octeon_dummy_write_config,
7528+ .read = octeon_dummy_read_config,
7529+ .write = octeon_dummy_write_config,
7530 };
7531
7532 static struct resource octeon_dummy_mem_resource = {
7533diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7534index a2358b4..7cead4f 100644
7535--- a/arch/mips/sgi-ip27/ip27-nmi.c
7536+++ b/arch/mips/sgi-ip27/ip27-nmi.c
7537@@ -187,9 +187,9 @@ void
7538 cont_nmi_dump(void)
7539 {
7540 #ifndef REAL_NMI_SIGNAL
7541- static atomic_t nmied_cpus = ATOMIC_INIT(0);
7542+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7543
7544- atomic_inc(&nmied_cpus);
7545+ atomic_inc_unchecked(&nmied_cpus);
7546 #endif
7547 /*
7548 * Only allow 1 cpu to proceed
7549@@ -233,7 +233,7 @@ cont_nmi_dump(void)
7550 udelay(10000);
7551 }
7552 #else
7553- while (atomic_read(&nmied_cpus) != num_online_cpus());
7554+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7555 #endif
7556
7557 /*
7558diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7559index a046b30..6799527 100644
7560--- a/arch/mips/sni/rm200.c
7561+++ b/arch/mips/sni/rm200.c
7562@@ -270,7 +270,7 @@ spurious_8259A_irq:
7563 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7564 spurious_irq_mask |= irqmask;
7565 }
7566- atomic_inc(&irq_err_count);
7567+ atomic_inc_unchecked(&irq_err_count);
7568 /*
7569 * Theoretically we do not have to handle this IRQ,
7570 * but in Linux this does not cause problems and is
7571diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7572index 41e873b..34d33a7 100644
7573--- a/arch/mips/vr41xx/common/icu.c
7574+++ b/arch/mips/vr41xx/common/icu.c
7575@@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7576
7577 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7578
7579- atomic_inc(&irq_err_count);
7580+ atomic_inc_unchecked(&irq_err_count);
7581
7582 return -1;
7583 }
7584diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7585index ae0e4ee..e8f0692 100644
7586--- a/arch/mips/vr41xx/common/irq.c
7587+++ b/arch/mips/vr41xx/common/irq.c
7588@@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7589 irq_cascade_t *cascade;
7590
7591 if (irq >= NR_IRQS) {
7592- atomic_inc(&irq_err_count);
7593+ atomic_inc_unchecked(&irq_err_count);
7594 return;
7595 }
7596
7597@@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7598 ret = cascade->get_irq(irq);
7599 irq = ret;
7600 if (ret < 0)
7601- atomic_inc(&irq_err_count);
7602+ atomic_inc_unchecked(&irq_err_count);
7603 else
7604 irq_dispatch(irq);
7605 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7606diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7607index 967d144..db12197 100644
7608--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7609+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7610@@ -11,12 +11,14 @@
7611 #ifndef _ASM_PROC_CACHE_H
7612 #define _ASM_PROC_CACHE_H
7613
7614+#include <linux/const.h>
7615+
7616 /* L1 cache */
7617
7618 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7619 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7620-#define L1_CACHE_BYTES 16 /* bytes per entry */
7621 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7622+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7623 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7624
7625 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7626diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7627index bcb5df2..84fabd2 100644
7628--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7629+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7630@@ -16,13 +16,15 @@
7631 #ifndef _ASM_PROC_CACHE_H
7632 #define _ASM_PROC_CACHE_H
7633
7634+#include <linux/const.h>
7635+
7636 /*
7637 * L1 cache
7638 */
7639 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7640 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7641-#define L1_CACHE_BYTES 32 /* bytes per entry */
7642 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7643+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7644 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7645
7646 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7647diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7648index 4ce7a01..449202a 100644
7649--- a/arch/openrisc/include/asm/cache.h
7650+++ b/arch/openrisc/include/asm/cache.h
7651@@ -19,11 +19,13 @@
7652 #ifndef __ASM_OPENRISC_CACHE_H
7653 #define __ASM_OPENRISC_CACHE_H
7654
7655+#include <linux/const.h>
7656+
7657 /* FIXME: How can we replace these with values from the CPU...
7658 * they shouldn't be hard-coded!
7659 */
7660
7661-#define L1_CACHE_BYTES 16
7662 #define L1_CACHE_SHIFT 4
7663+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7664
7665 #endif /* __ASM_OPENRISC_CACHE_H */
7666diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7667index 0be2db2..1b0f26d 100644
7668--- a/arch/parisc/include/asm/atomic.h
7669+++ b/arch/parisc/include/asm/atomic.h
7670@@ -248,6 +248,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7671 return dec;
7672 }
7673
7674+#define atomic64_read_unchecked(v) atomic64_read(v)
7675+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7676+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7677+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7678+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7679+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7680+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7681+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7682+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7683+
7684 #endif /* !CONFIG_64BIT */
7685
7686
7687diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7688index 47f11c7..3420df2 100644
7689--- a/arch/parisc/include/asm/cache.h
7690+++ b/arch/parisc/include/asm/cache.h
7691@@ -5,6 +5,7 @@
7692 #ifndef __ARCH_PARISC_CACHE_H
7693 #define __ARCH_PARISC_CACHE_H
7694
7695+#include <linux/const.h>
7696
7697 /*
7698 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7699@@ -15,13 +16,13 @@
7700 * just ruin performance.
7701 */
7702 #ifdef CONFIG_PA20
7703-#define L1_CACHE_BYTES 64
7704 #define L1_CACHE_SHIFT 6
7705 #else
7706-#define L1_CACHE_BYTES 32
7707 #define L1_CACHE_SHIFT 5
7708 #endif
7709
7710+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7711+
7712 #ifndef __ASSEMBLY__
7713
7714 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7715diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7716index 3391d06..c23a2cc 100644
7717--- a/arch/parisc/include/asm/elf.h
7718+++ b/arch/parisc/include/asm/elf.h
7719@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7720
7721 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7722
7723+#ifdef CONFIG_PAX_ASLR
7724+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7725+
7726+#define PAX_DELTA_MMAP_LEN 16
7727+#define PAX_DELTA_STACK_LEN 16
7728+#endif
7729+
7730 /* This yields a mask that user programs can use to figure out what
7731 instruction set this CPU supports. This could be done in user space,
7732 but it's not easy, and we've already done it here. */
7733diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7734index f213f5b..0af3e8e 100644
7735--- a/arch/parisc/include/asm/pgalloc.h
7736+++ b/arch/parisc/include/asm/pgalloc.h
7737@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7738 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7739 }
7740
7741+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7742+{
7743+ pgd_populate(mm, pgd, pmd);
7744+}
7745+
7746 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7747 {
7748 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7749@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7750 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7751 #define pmd_free(mm, x) do { } while (0)
7752 #define pgd_populate(mm, pmd, pte) BUG()
7753+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7754
7755 #endif
7756
7757diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7758index 22b89d1..ce34230 100644
7759--- a/arch/parisc/include/asm/pgtable.h
7760+++ b/arch/parisc/include/asm/pgtable.h
7761@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7762 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7763 #define PAGE_COPY PAGE_EXECREAD
7764 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7765+
7766+#ifdef CONFIG_PAX_PAGEEXEC
7767+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7768+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7769+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7770+#else
7771+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7772+# define PAGE_COPY_NOEXEC PAGE_COPY
7773+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7774+#endif
7775+
7776 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7777 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7778 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7779diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7780index 4006964..fcb3cc2 100644
7781--- a/arch/parisc/include/asm/uaccess.h
7782+++ b/arch/parisc/include/asm/uaccess.h
7783@@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7784 const void __user *from,
7785 unsigned long n)
7786 {
7787- int sz = __compiletime_object_size(to);
7788+ size_t sz = __compiletime_object_size(to);
7789 int ret = -EFAULT;
7790
7791- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7792+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7793 ret = __copy_from_user(to, from, n);
7794 else
7795 copy_from_user_overflow();
7796diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7797index 50dfafc..b9fc230 100644
7798--- a/arch/parisc/kernel/module.c
7799+++ b/arch/parisc/kernel/module.c
7800@@ -98,16 +98,38 @@
7801
7802 /* three functions to determine where in the module core
7803 * or init pieces the location is */
7804+static inline int in_init_rx(struct module *me, void *loc)
7805+{
7806+ return (loc >= me->module_init_rx &&
7807+ loc < (me->module_init_rx + me->init_size_rx));
7808+}
7809+
7810+static inline int in_init_rw(struct module *me, void *loc)
7811+{
7812+ return (loc >= me->module_init_rw &&
7813+ loc < (me->module_init_rw + me->init_size_rw));
7814+}
7815+
7816 static inline int in_init(struct module *me, void *loc)
7817 {
7818- return (loc >= me->module_init &&
7819- loc <= (me->module_init + me->init_size));
7820+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7821+}
7822+
7823+static inline int in_core_rx(struct module *me, void *loc)
7824+{
7825+ return (loc >= me->module_core_rx &&
7826+ loc < (me->module_core_rx + me->core_size_rx));
7827+}
7828+
7829+static inline int in_core_rw(struct module *me, void *loc)
7830+{
7831+ return (loc >= me->module_core_rw &&
7832+ loc < (me->module_core_rw + me->core_size_rw));
7833 }
7834
7835 static inline int in_core(struct module *me, void *loc)
7836 {
7837- return (loc >= me->module_core &&
7838- loc <= (me->module_core + me->core_size));
7839+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7840 }
7841
7842 static inline int in_local(struct module *me, void *loc)
7843@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7844 }
7845
7846 /* align things a bit */
7847- me->core_size = ALIGN(me->core_size, 16);
7848- me->arch.got_offset = me->core_size;
7849- me->core_size += gots * sizeof(struct got_entry);
7850+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7851+ me->arch.got_offset = me->core_size_rw;
7852+ me->core_size_rw += gots * sizeof(struct got_entry);
7853
7854- me->core_size = ALIGN(me->core_size, 16);
7855- me->arch.fdesc_offset = me->core_size;
7856- me->core_size += fdescs * sizeof(Elf_Fdesc);
7857+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7858+ me->arch.fdesc_offset = me->core_size_rw;
7859+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7860
7861 me->arch.got_max = gots;
7862 me->arch.fdesc_max = fdescs;
7863@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7864
7865 BUG_ON(value == 0);
7866
7867- got = me->module_core + me->arch.got_offset;
7868+ got = me->module_core_rw + me->arch.got_offset;
7869 for (i = 0; got[i].addr; i++)
7870 if (got[i].addr == value)
7871 goto out;
7872@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7873 #ifdef CONFIG_64BIT
7874 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7875 {
7876- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7877+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7878
7879 if (!value) {
7880 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7881@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7882
7883 /* Create new one */
7884 fdesc->addr = value;
7885- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7886+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7887 return (Elf_Addr)fdesc;
7888 }
7889 #endif /* CONFIG_64BIT */
7890@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7891
7892 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7893 end = table + sechdrs[me->arch.unwind_section].sh_size;
7894- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7895+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7896
7897 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7898 me->arch.unwind_section, table, end, gp);
7899diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7900index e1ffea2..46ed66e 100644
7901--- a/arch/parisc/kernel/sys_parisc.c
7902+++ b/arch/parisc/kernel/sys_parisc.c
7903@@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7904 unsigned long task_size = TASK_SIZE;
7905 int do_color_align, last_mmap;
7906 struct vm_unmapped_area_info info;
7907+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7908
7909 if (len > task_size)
7910 return -ENOMEM;
7911@@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7912 goto found_addr;
7913 }
7914
7915+#ifdef CONFIG_PAX_RANDMMAP
7916+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7917+#endif
7918+
7919 if (addr) {
7920 if (do_color_align && last_mmap)
7921 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7922@@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7923 info.high_limit = mmap_upper_limit();
7924 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7925 info.align_offset = shared_align_offset(last_mmap, pgoff);
7926+ info.threadstack_offset = offset;
7927 addr = vm_unmapped_area(&info);
7928
7929 found_addr:
7930@@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7931 unsigned long addr = addr0;
7932 int do_color_align, last_mmap;
7933 struct vm_unmapped_area_info info;
7934+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7935
7936 #ifdef CONFIG_64BIT
7937 /* This should only ever run for 32-bit processes. */
7938@@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7939 }
7940
7941 /* requesting a specific address */
7942+#ifdef CONFIG_PAX_RANDMMAP
7943+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7944+#endif
7945+
7946 if (addr) {
7947 if (do_color_align && last_mmap)
7948 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7949@@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7950 info.high_limit = mm->mmap_base;
7951 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7952 info.align_offset = shared_align_offset(last_mmap, pgoff);
7953+ info.threadstack_offset = offset;
7954 addr = vm_unmapped_area(&info);
7955 if (!(addr & ~PAGE_MASK))
7956 goto found_addr;
7957@@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7958 mm->mmap_legacy_base = mmap_legacy_base();
7959 mm->mmap_base = mmap_upper_limit();
7960
7961+#ifdef CONFIG_PAX_RANDMMAP
7962+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
7963+ mm->mmap_legacy_base += mm->delta_mmap;
7964+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7965+ }
7966+#endif
7967+
7968 if (mmap_is_legacy()) {
7969 mm->mmap_base = mm->mmap_legacy_base;
7970 mm->get_unmapped_area = arch_get_unmapped_area;
7971diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7972index 47ee620..1107387 100644
7973--- a/arch/parisc/kernel/traps.c
7974+++ b/arch/parisc/kernel/traps.c
7975@@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7976
7977 down_read(&current->mm->mmap_sem);
7978 vma = find_vma(current->mm,regs->iaoq[0]);
7979- if (vma && (regs->iaoq[0] >= vma->vm_start)
7980- && (vma->vm_flags & VM_EXEC)) {
7981-
7982+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7983 fault_address = regs->iaoq[0];
7984 fault_space = regs->iasq[0];
7985
7986diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7987index 3ca9c11..d163ef7 100644
7988--- a/arch/parisc/mm/fault.c
7989+++ b/arch/parisc/mm/fault.c
7990@@ -15,6 +15,7 @@
7991 #include <linux/sched.h>
7992 #include <linux/interrupt.h>
7993 #include <linux/module.h>
7994+#include <linux/unistd.h>
7995
7996 #include <asm/uaccess.h>
7997 #include <asm/traps.h>
7998@@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
7999 static unsigned long
8000 parisc_acctyp(unsigned long code, unsigned int inst)
8001 {
8002- if (code == 6 || code == 16)
8003+ if (code == 6 || code == 7 || code == 16)
8004 return VM_EXEC;
8005
8006 switch (inst & 0xf0000000) {
8007@@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
8008 }
8009 #endif
8010
8011+#ifdef CONFIG_PAX_PAGEEXEC
8012+/*
8013+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
8014+ *
8015+ * returns 1 when task should be killed
8016+ * 2 when rt_sigreturn trampoline was detected
8017+ * 3 when unpatched PLT trampoline was detected
8018+ */
8019+static int pax_handle_fetch_fault(struct pt_regs *regs)
8020+{
8021+
8022+#ifdef CONFIG_PAX_EMUPLT
8023+ int err;
8024+
8025+ do { /* PaX: unpatched PLT emulation */
8026+ unsigned int bl, depwi;
8027+
8028+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
8029+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
8030+
8031+ if (err)
8032+ break;
8033+
8034+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
8035+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
8036+
8037+ err = get_user(ldw, (unsigned int *)addr);
8038+ err |= get_user(bv, (unsigned int *)(addr+4));
8039+ err |= get_user(ldw2, (unsigned int *)(addr+8));
8040+
8041+ if (err)
8042+ break;
8043+
8044+ if (ldw == 0x0E801096U &&
8045+ bv == 0xEAC0C000U &&
8046+ ldw2 == 0x0E881095U)
8047+ {
8048+ unsigned int resolver, map;
8049+
8050+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
8051+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
8052+ if (err)
8053+ break;
8054+
8055+ regs->gr[20] = instruction_pointer(regs)+8;
8056+ regs->gr[21] = map;
8057+ regs->gr[22] = resolver;
8058+ regs->iaoq[0] = resolver | 3UL;
8059+ regs->iaoq[1] = regs->iaoq[0] + 4;
8060+ return 3;
8061+ }
8062+ }
8063+ } while (0);
8064+#endif
8065+
8066+#ifdef CONFIG_PAX_EMUTRAMP
8067+
8068+#ifndef CONFIG_PAX_EMUSIGRT
8069+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
8070+ return 1;
8071+#endif
8072+
8073+ do { /* PaX: rt_sigreturn emulation */
8074+ unsigned int ldi1, ldi2, bel, nop;
8075+
8076+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
8077+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
8078+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
8079+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
8080+
8081+ if (err)
8082+ break;
8083+
8084+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
8085+ ldi2 == 0x3414015AU &&
8086+ bel == 0xE4008200U &&
8087+ nop == 0x08000240U)
8088+ {
8089+ regs->gr[25] = (ldi1 & 2) >> 1;
8090+ regs->gr[20] = __NR_rt_sigreturn;
8091+ regs->gr[31] = regs->iaoq[1] + 16;
8092+ regs->sr[0] = regs->iasq[1];
8093+ regs->iaoq[0] = 0x100UL;
8094+ regs->iaoq[1] = regs->iaoq[0] + 4;
8095+ regs->iasq[0] = regs->sr[2];
8096+ regs->iasq[1] = regs->sr[2];
8097+ return 2;
8098+ }
8099+ } while (0);
8100+#endif
8101+
8102+ return 1;
8103+}
8104+
8105+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8106+{
8107+ unsigned long i;
8108+
8109+ printk(KERN_ERR "PAX: bytes at PC: ");
8110+ for (i = 0; i < 5; i++) {
8111+ unsigned int c;
8112+ if (get_user(c, (unsigned int *)pc+i))
8113+ printk(KERN_CONT "???????? ");
8114+ else
8115+ printk(KERN_CONT "%08x ", c);
8116+ }
8117+ printk("\n");
8118+}
8119+#endif
8120+
8121 int fixup_exception(struct pt_regs *regs)
8122 {
8123 const struct exception_table_entry *fix;
8124@@ -234,8 +345,33 @@ retry:
8125
8126 good_area:
8127
8128- if ((vma->vm_flags & acc_type) != acc_type)
8129+ if ((vma->vm_flags & acc_type) != acc_type) {
8130+
8131+#ifdef CONFIG_PAX_PAGEEXEC
8132+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
8133+ (address & ~3UL) == instruction_pointer(regs))
8134+ {
8135+ up_read(&mm->mmap_sem);
8136+ switch (pax_handle_fetch_fault(regs)) {
8137+
8138+#ifdef CONFIG_PAX_EMUPLT
8139+ case 3:
8140+ return;
8141+#endif
8142+
8143+#ifdef CONFIG_PAX_EMUTRAMP
8144+ case 2:
8145+ return;
8146+#endif
8147+
8148+ }
8149+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
8150+ do_group_exit(SIGKILL);
8151+ }
8152+#endif
8153+
8154 goto bad_area;
8155+ }
8156
8157 /*
8158 * If for any reason at all we couldn't handle the fault, make
8159diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
8160index 4bc7b62..107e0b2 100644
8161--- a/arch/powerpc/Kconfig
8162+++ b/arch/powerpc/Kconfig
8163@@ -399,6 +399,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
8164 config KEXEC
8165 bool "kexec system call"
8166 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
8167+ depends on !GRKERNSEC_KMEM
8168 help
8169 kexec is a system call that implements the ability to shutdown your
8170 current kernel, and to start another kernel. It is like a reboot
8171diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
8172index 28992d0..bbbff7e 100644
8173--- a/arch/powerpc/include/asm/atomic.h
8174+++ b/arch/powerpc/include/asm/atomic.h
8175@@ -12,6 +12,11 @@
8176
8177 #define ATOMIC_INIT(i) { (i) }
8178
8179+#define _ASM_EXTABLE(from, to) \
8180+" .section __ex_table,\"a\"\n" \
8181+ PPC_LONG" " #from ", " #to"\n" \
8182+" .previous\n"
8183+
8184 static __inline__ int atomic_read(const atomic_t *v)
8185 {
8186 int t;
8187@@ -21,16 +26,61 @@ static __inline__ int atomic_read(const atomic_t *v)
8188 return t;
8189 }
8190
8191+static __inline__ int atomic_read_unchecked(const atomic_unchecked_t *v)
8192+{
8193+ int t;
8194+
8195+ __asm__ __volatile__("lwz%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
8196+
8197+ return t;
8198+}
8199+
8200 static __inline__ void atomic_set(atomic_t *v, int i)
8201 {
8202 __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8203 }
8204
8205+static __inline__ void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8206+{
8207+ __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8208+}
8209+
8210 static __inline__ void atomic_add(int a, atomic_t *v)
8211 {
8212 int t;
8213
8214 __asm__ __volatile__(
8215+"1: lwarx %0,0,%3 # atomic_add\n"
8216+
8217+#ifdef CONFIG_PAX_REFCOUNT
8218+" mcrxr cr0\n"
8219+" addo. %0,%2,%0\n"
8220+" bf 4*cr0+so, 3f\n"
8221+"2:.long " "0x00c00b00""\n"
8222+#else
8223+" add %0,%2,%0\n"
8224+#endif
8225+
8226+"3:\n"
8227+ PPC405_ERR77(0,%3)
8228+" stwcx. %0,0,%3 \n\
8229+ bne- 1b"
8230+
8231+#ifdef CONFIG_PAX_REFCOUNT
8232+"\n4:\n"
8233+ _ASM_EXTABLE(2b, 4b)
8234+#endif
8235+
8236+ : "=&r" (t), "+m" (v->counter)
8237+ : "r" (a), "r" (&v->counter)
8238+ : "cc");
8239+}
8240+
8241+static __inline__ void atomic_add_unchecked(int a, atomic_unchecked_t *v)
8242+{
8243+ int t;
8244+
8245+ __asm__ __volatile__(
8246 "1: lwarx %0,0,%3 # atomic_add\n\
8247 add %0,%2,%0\n"
8248 PPC405_ERR77(0,%3)
8249@@ -41,12 +91,49 @@ static __inline__ void atomic_add(int a, atomic_t *v)
8250 : "cc");
8251 }
8252
8253+/* Same as atomic_add but return the value */
8254 static __inline__ int atomic_add_return(int a, atomic_t *v)
8255 {
8256 int t;
8257
8258 __asm__ __volatile__(
8259 PPC_ATOMIC_ENTRY_BARRIER
8260+"1: lwarx %0,0,%2 # atomic_add_return\n"
8261+
8262+#ifdef CONFIG_PAX_REFCOUNT
8263+" mcrxr cr0\n"
8264+" addo. %0,%1,%0\n"
8265+" bf 4*cr0+so, 3f\n"
8266+"2:.long " "0x00c00b00""\n"
8267+#else
8268+" add %0,%1,%0\n"
8269+#endif
8270+
8271+"3:\n"
8272+ PPC405_ERR77(0,%2)
8273+" stwcx. %0,0,%2 \n\
8274+ bne- 1b\n"
8275+"4:"
8276+
8277+#ifdef CONFIG_PAX_REFCOUNT
8278+ _ASM_EXTABLE(2b, 4b)
8279+#endif
8280+
8281+ PPC_ATOMIC_EXIT_BARRIER
8282+ : "=&r" (t)
8283+ : "r" (a), "r" (&v->counter)
8284+ : "cc", "memory");
8285+
8286+ return t;
8287+}
8288+
8289+/* Same as atomic_add_unchecked but return the value */
8290+static __inline__ int atomic_add_return_unchecked(int a, atomic_unchecked_t *v)
8291+{
8292+ int t;
8293+
8294+ __asm__ __volatile__(
8295+ PPC_ATOMIC_ENTRY_BARRIER
8296 "1: lwarx %0,0,%2 # atomic_add_return\n\
8297 add %0,%1,%0\n"
8298 PPC405_ERR77(0,%2)
8299@@ -67,6 +154,37 @@ static __inline__ void atomic_sub(int a, atomic_t *v)
8300 int t;
8301
8302 __asm__ __volatile__(
8303+"1: lwarx %0,0,%3 # atomic_sub\n"
8304+
8305+#ifdef CONFIG_PAX_REFCOUNT
8306+" mcrxr cr0\n"
8307+" subfo. %0,%2,%0\n"
8308+" bf 4*cr0+so, 3f\n"
8309+"2:.long " "0x00c00b00""\n"
8310+#else
8311+" subf %0,%2,%0\n"
8312+#endif
8313+
8314+"3:\n"
8315+ PPC405_ERR77(0,%3)
8316+" stwcx. %0,0,%3 \n\
8317+ bne- 1b\n"
8318+"4:"
8319+
8320+#ifdef CONFIG_PAX_REFCOUNT
8321+ _ASM_EXTABLE(2b, 4b)
8322+#endif
8323+
8324+ : "=&r" (t), "+m" (v->counter)
8325+ : "r" (a), "r" (&v->counter)
8326+ : "cc");
8327+}
8328+
8329+static __inline__ void atomic_sub_unchecked(int a, atomic_unchecked_t *v)
8330+{
8331+ int t;
8332+
8333+ __asm__ __volatile__(
8334 "1: lwarx %0,0,%3 # atomic_sub\n\
8335 subf %0,%2,%0\n"
8336 PPC405_ERR77(0,%3)
8337@@ -77,12 +195,49 @@ static __inline__ void atomic_sub(int a, atomic_t *v)
8338 : "cc");
8339 }
8340
8341+/* Same as atomic_sub but return the value */
8342 static __inline__ int atomic_sub_return(int a, atomic_t *v)
8343 {
8344 int t;
8345
8346 __asm__ __volatile__(
8347 PPC_ATOMIC_ENTRY_BARRIER
8348+"1: lwarx %0,0,%2 # atomic_sub_return\n"
8349+
8350+#ifdef CONFIG_PAX_REFCOUNT
8351+" mcrxr cr0\n"
8352+" subfo. %0,%1,%0\n"
8353+" bf 4*cr0+so, 3f\n"
8354+"2:.long " "0x00c00b00""\n"
8355+#else
8356+" subf %0,%1,%0\n"
8357+#endif
8358+
8359+"3:\n"
8360+ PPC405_ERR77(0,%2)
8361+" stwcx. %0,0,%2 \n\
8362+ bne- 1b\n"
8363+ PPC_ATOMIC_EXIT_BARRIER
8364+"4:"
8365+
8366+#ifdef CONFIG_PAX_REFCOUNT
8367+ _ASM_EXTABLE(2b, 4b)
8368+#endif
8369+
8370+ : "=&r" (t)
8371+ : "r" (a), "r" (&v->counter)
8372+ : "cc", "memory");
8373+
8374+ return t;
8375+}
8376+
8377+/* Same as atomic_sub_unchecked but return the value */
8378+static __inline__ int atomic_sub_return_unchecked(int a, atomic_unchecked_t *v)
8379+{
8380+ int t;
8381+
8382+ __asm__ __volatile__(
8383+ PPC_ATOMIC_ENTRY_BARRIER
8384 "1: lwarx %0,0,%2 # atomic_sub_return\n\
8385 subf %0,%1,%0\n"
8386 PPC405_ERR77(0,%2)
8387@@ -96,38 +251,23 @@ static __inline__ int atomic_sub_return(int a, atomic_t *v)
8388 return t;
8389 }
8390
8391-static __inline__ void atomic_inc(atomic_t *v)
8392-{
8393- int t;
8394+/*
8395+ * atomic_inc - increment atomic variable
8396+ * @v: pointer of type atomic_t
8397+ *
8398+ * Automatically increments @v by 1
8399+ */
8400+#define atomic_inc(v) atomic_add(1, (v))
8401+#define atomic_inc_return(v) atomic_add_return(1, (v))
8402
8403- __asm__ __volatile__(
8404-"1: lwarx %0,0,%2 # atomic_inc\n\
8405- addic %0,%0,1\n"
8406- PPC405_ERR77(0,%2)
8407-" stwcx. %0,0,%2 \n\
8408- bne- 1b"
8409- : "=&r" (t), "+m" (v->counter)
8410- : "r" (&v->counter)
8411- : "cc", "xer");
8412+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
8413+{
8414+ atomic_add_unchecked(1, v);
8415 }
8416
8417-static __inline__ int atomic_inc_return(atomic_t *v)
8418+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8419 {
8420- int t;
8421-
8422- __asm__ __volatile__(
8423- PPC_ATOMIC_ENTRY_BARRIER
8424-"1: lwarx %0,0,%1 # atomic_inc_return\n\
8425- addic %0,%0,1\n"
8426- PPC405_ERR77(0,%1)
8427-" stwcx. %0,0,%1 \n\
8428- bne- 1b"
8429- PPC_ATOMIC_EXIT_BARRIER
8430- : "=&r" (t)
8431- : "r" (&v->counter)
8432- : "cc", "xer", "memory");
8433-
8434- return t;
8435+ return atomic_add_return_unchecked(1, v);
8436 }
8437
8438 /*
8439@@ -140,43 +280,38 @@ static __inline__ int atomic_inc_return(atomic_t *v)
8440 */
8441 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
8442
8443-static __inline__ void atomic_dec(atomic_t *v)
8444+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8445 {
8446- int t;
8447-
8448- __asm__ __volatile__(
8449-"1: lwarx %0,0,%2 # atomic_dec\n\
8450- addic %0,%0,-1\n"
8451- PPC405_ERR77(0,%2)\
8452-" stwcx. %0,0,%2\n\
8453- bne- 1b"
8454- : "=&r" (t), "+m" (v->counter)
8455- : "r" (&v->counter)
8456- : "cc", "xer");
8457+ return atomic_add_return_unchecked(1, v) == 0;
8458 }
8459
8460-static __inline__ int atomic_dec_return(atomic_t *v)
8461+/*
8462+ * atomic_dec - decrement atomic variable
8463+ * @v: pointer of type atomic_t
8464+ *
8465+ * Atomically decrements @v by 1
8466+ */
8467+#define atomic_dec(v) atomic_sub(1, (v))
8468+#define atomic_dec_return(v) atomic_sub_return(1, (v))
8469+
8470+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
8471 {
8472- int t;
8473-
8474- __asm__ __volatile__(
8475- PPC_ATOMIC_ENTRY_BARRIER
8476-"1: lwarx %0,0,%1 # atomic_dec_return\n\
8477- addic %0,%0,-1\n"
8478- PPC405_ERR77(0,%1)
8479-" stwcx. %0,0,%1\n\
8480- bne- 1b"
8481- PPC_ATOMIC_EXIT_BARRIER
8482- : "=&r" (t)
8483- : "r" (&v->counter)
8484- : "cc", "xer", "memory");
8485-
8486- return t;
8487+ atomic_sub_unchecked(1, v);
8488 }
8489
8490 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8491 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
8492
8493+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8494+{
8495+ return cmpxchg(&(v->counter), old, new);
8496+}
8497+
8498+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8499+{
8500+ return xchg(&(v->counter), new);
8501+}
8502+
8503 /**
8504 * __atomic_add_unless - add unless the number is a given value
8505 * @v: pointer of type atomic_t
8506@@ -194,11 +329,27 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
8507 PPC_ATOMIC_ENTRY_BARRIER
8508 "1: lwarx %0,0,%1 # __atomic_add_unless\n\
8509 cmpw 0,%0,%3 \n\
8510- beq- 2f \n\
8511- add %0,%2,%0 \n"
8512+ beq- 2f \n"
8513+
8514+#ifdef CONFIG_PAX_REFCOUNT
8515+" mcrxr cr0\n"
8516+" addo. %0,%2,%0\n"
8517+" bf 4*cr0+so, 4f\n"
8518+"3:.long " "0x00c00b00""\n"
8519+"4:\n"
8520+#else
8521+ "add %0,%2,%0 \n"
8522+#endif
8523+
8524 PPC405_ERR77(0,%2)
8525 " stwcx. %0,0,%1 \n\
8526 bne- 1b \n"
8527+"5:"
8528+
8529+#ifdef CONFIG_PAX_REFCOUNT
8530+ _ASM_EXTABLE(3b, 5b)
8531+#endif
8532+
8533 PPC_ATOMIC_EXIT_BARRIER
8534 " subf %0,%2,%0 \n\
8535 2:"
8536@@ -271,6 +422,11 @@ static __inline__ int atomic_dec_if_positive(atomic_t *v)
8537 }
8538 #define atomic_dec_if_positive atomic_dec_if_positive
8539
8540+#define smp_mb__before_atomic_dec() smp_mb()
8541+#define smp_mb__after_atomic_dec() smp_mb()
8542+#define smp_mb__before_atomic_inc() smp_mb()
8543+#define smp_mb__after_atomic_inc() smp_mb()
8544+
8545 #ifdef __powerpc64__
8546
8547 #define ATOMIC64_INIT(i) { (i) }
8548@@ -284,11 +440,25 @@ static __inline__ long atomic64_read(const atomic64_t *v)
8549 return t;
8550 }
8551
8552+static __inline__ long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8553+{
8554+ long t;
8555+
8556+ __asm__ __volatile__("ld%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
8557+
8558+ return t;
8559+}
8560+
8561 static __inline__ void atomic64_set(atomic64_t *v, long i)
8562 {
8563 __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8564 }
8565
8566+static __inline__ void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8567+{
8568+ __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8569+}
8570+
8571 static __inline__ void atomic64_add(long a, atomic64_t *v)
8572 {
8573 long t;
8574@@ -303,12 +473,76 @@ static __inline__ void atomic64_add(long a, atomic64_t *v)
8575 : "cc");
8576 }
8577
8578+static __inline__ void atomic64_add_unchecked(long a, atomic64_unchecked_t *v)
8579+{
8580+ long t;
8581+
8582+ __asm__ __volatile__(
8583+"1: ldarx %0,0,%3 # atomic64_add\n"
8584+
8585+#ifdef CONFIG_PAX_REFCOUNT
8586+" mcrxr cr0\n"
8587+" addo. %0,%2,%0\n"
8588+" bf 4*cr0+so, 3f\n"
8589+"2:.long " "0x00c00b00""\n"
8590+#else
8591+" add %0,%2,%0\n"
8592+#endif
8593+
8594+"3:\n"
8595+" stdcx. %0,0,%3 \n\
8596+ bne- 1b\n"
8597+"4:"
8598+
8599+#ifdef CONFIG_PAX_REFCOUNT
8600+ _ASM_EXTABLE(2b, 4b)
8601+#endif
8602+
8603+ : "=&r" (t), "+m" (v->counter)
8604+ : "r" (a), "r" (&v->counter)
8605+ : "cc");
8606+}
8607+
8608 static __inline__ long atomic64_add_return(long a, atomic64_t *v)
8609 {
8610 long t;
8611
8612 __asm__ __volatile__(
8613 PPC_ATOMIC_ENTRY_BARRIER
8614+"1: ldarx %0,0,%2 # atomic64_add_return\n"
8615+
8616+#ifdef CONFIG_PAX_REFCOUNT
8617+" mcrxr cr0\n"
8618+" addo. %0,%1,%0\n"
8619+" bf 4*cr0+so, 3f\n"
8620+"2:.long " "0x00c00b00""\n"
8621+#else
8622+" add %0,%1,%0\n"
8623+#endif
8624+
8625+"3:\n"
8626+" stdcx. %0,0,%2 \n\
8627+ bne- 1b\n"
8628+ PPC_ATOMIC_EXIT_BARRIER
8629+"4:"
8630+
8631+#ifdef CONFIG_PAX_REFCOUNT
8632+ _ASM_EXTABLE(2b, 4b)
8633+#endif
8634+
8635+ : "=&r" (t)
8636+ : "r" (a), "r" (&v->counter)
8637+ : "cc", "memory");
8638+
8639+ return t;
8640+}
8641+
8642+static __inline__ long atomic64_add_return_unchecked(long a, atomic64_unchecked_t *v)
8643+{
8644+ long t;
8645+
8646+ __asm__ __volatile__(
8647+ PPC_ATOMIC_ENTRY_BARRIER
8648 "1: ldarx %0,0,%2 # atomic64_add_return\n\
8649 add %0,%1,%0\n\
8650 stdcx. %0,0,%2 \n\
8651@@ -328,6 +562,36 @@ static __inline__ void atomic64_sub(long a, atomic64_t *v)
8652 long t;
8653
8654 __asm__ __volatile__(
8655+"1: ldarx %0,0,%3 # atomic64_sub\n"
8656+
8657+#ifdef CONFIG_PAX_REFCOUNT
8658+" mcrxr cr0\n"
8659+" subfo. %0,%2,%0\n"
8660+" bf 4*cr0+so, 3f\n"
8661+"2:.long " "0x00c00b00""\n"
8662+#else
8663+" subf %0,%2,%0\n"
8664+#endif
8665+
8666+"3:\n"
8667+" stdcx. %0,0,%3 \n\
8668+ bne- 1b"
8669+"4:"
8670+
8671+#ifdef CONFIG_PAX_REFCOUNT
8672+ _ASM_EXTABLE(2b, 4b)
8673+#endif
8674+
8675+ : "=&r" (t), "+m" (v->counter)
8676+ : "r" (a), "r" (&v->counter)
8677+ : "cc");
8678+}
8679+
8680+static __inline__ void atomic64_sub_unchecked(long a, atomic64_unchecked_t *v)
8681+{
8682+ long t;
8683+
8684+ __asm__ __volatile__(
8685 "1: ldarx %0,0,%3 # atomic64_sub\n\
8686 subf %0,%2,%0\n\
8687 stdcx. %0,0,%3 \n\
8688@@ -343,6 +607,40 @@ static __inline__ long atomic64_sub_return(long a, atomic64_t *v)
8689
8690 __asm__ __volatile__(
8691 PPC_ATOMIC_ENTRY_BARRIER
8692+"1: ldarx %0,0,%2 # atomic64_sub_return\n"
8693+
8694+#ifdef CONFIG_PAX_REFCOUNT
8695+" mcrxr cr0\n"
8696+" subfo. %0,%1,%0\n"
8697+" bf 4*cr0+so, 3f\n"
8698+"2:.long " "0x00c00b00""\n"
8699+#else
8700+" subf %0,%1,%0\n"
8701+#endif
8702+
8703+"3:\n"
8704+" stdcx. %0,0,%2 \n\
8705+ bne- 1b\n"
8706+ PPC_ATOMIC_EXIT_BARRIER
8707+"4:"
8708+
8709+#ifdef CONFIG_PAX_REFCOUNT
8710+ _ASM_EXTABLE(2b, 4b)
8711+#endif
8712+
8713+ : "=&r" (t)
8714+ : "r" (a), "r" (&v->counter)
8715+ : "cc", "memory");
8716+
8717+ return t;
8718+}
8719+
8720+static __inline__ long atomic64_sub_return_unchecked(long a, atomic64_unchecked_t *v)
8721+{
8722+ long t;
8723+
8724+ __asm__ __volatile__(
8725+ PPC_ATOMIC_ENTRY_BARRIER
8726 "1: ldarx %0,0,%2 # atomic64_sub_return\n\
8727 subf %0,%1,%0\n\
8728 stdcx. %0,0,%2 \n\
8729@@ -355,36 +653,23 @@ static __inline__ long atomic64_sub_return(long a, atomic64_t *v)
8730 return t;
8731 }
8732
8733-static __inline__ void atomic64_inc(atomic64_t *v)
8734-{
8735- long t;
8736+/*
8737+ * atomic64_inc - increment atomic variable
8738+ * @v: pointer of type atomic64_t
8739+ *
8740+ * Automatically increments @v by 1
8741+ */
8742+#define atomic64_inc(v) atomic64_add(1, (v))
8743+#define atomic64_inc_return(v) atomic64_add_return(1, (v))
8744
8745- __asm__ __volatile__(
8746-"1: ldarx %0,0,%2 # atomic64_inc\n\
8747- addic %0,%0,1\n\
8748- stdcx. %0,0,%2 \n\
8749- bne- 1b"
8750- : "=&r" (t), "+m" (v->counter)
8751- : "r" (&v->counter)
8752- : "cc", "xer");
8753+static __inline__ void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8754+{
8755+ atomic64_add_unchecked(1, v);
8756 }
8757
8758-static __inline__ long atomic64_inc_return(atomic64_t *v)
8759+static __inline__ long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8760 {
8761- long t;
8762-
8763- __asm__ __volatile__(
8764- PPC_ATOMIC_ENTRY_BARRIER
8765-"1: ldarx %0,0,%1 # atomic64_inc_return\n\
8766- addic %0,%0,1\n\
8767- stdcx. %0,0,%1 \n\
8768- bne- 1b"
8769- PPC_ATOMIC_EXIT_BARRIER
8770- : "=&r" (t)
8771- : "r" (&v->counter)
8772- : "cc", "xer", "memory");
8773-
8774- return t;
8775+ return atomic64_add_return_unchecked(1, v);
8776 }
8777
8778 /*
8779@@ -397,36 +682,18 @@ static __inline__ long atomic64_inc_return(atomic64_t *v)
8780 */
8781 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8782
8783-static __inline__ void atomic64_dec(atomic64_t *v)
8784+/*
8785+ * atomic64_dec - decrement atomic variable
8786+ * @v: pointer of type atomic64_t
8787+ *
8788+ * Atomically decrements @v by 1
8789+ */
8790+#define atomic64_dec(v) atomic64_sub(1, (v))
8791+#define atomic64_dec_return(v) atomic64_sub_return(1, (v))
8792+
8793+static __inline__ void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8794 {
8795- long t;
8796-
8797- __asm__ __volatile__(
8798-"1: ldarx %0,0,%2 # atomic64_dec\n\
8799- addic %0,%0,-1\n\
8800- stdcx. %0,0,%2\n\
8801- bne- 1b"
8802- : "=&r" (t), "+m" (v->counter)
8803- : "r" (&v->counter)
8804- : "cc", "xer");
8805-}
8806-
8807-static __inline__ long atomic64_dec_return(atomic64_t *v)
8808-{
8809- long t;
8810-
8811- __asm__ __volatile__(
8812- PPC_ATOMIC_ENTRY_BARRIER
8813-"1: ldarx %0,0,%1 # atomic64_dec_return\n\
8814- addic %0,%0,-1\n\
8815- stdcx. %0,0,%1\n\
8816- bne- 1b"
8817- PPC_ATOMIC_EXIT_BARRIER
8818- : "=&r" (t)
8819- : "r" (&v->counter)
8820- : "cc", "xer", "memory");
8821-
8822- return t;
8823+ atomic64_sub_unchecked(1, v);
8824 }
8825
8826 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
8827@@ -459,6 +726,16 @@ static __inline__ long atomic64_dec_if_positive(atomic64_t *v)
8828 #define atomic64_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8829 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
8830
8831+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
8832+{
8833+ return cmpxchg(&(v->counter), old, new);
8834+}
8835+
8836+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
8837+{
8838+ return xchg(&(v->counter), new);
8839+}
8840+
8841 /**
8842 * atomic64_add_unless - add unless the number is a given value
8843 * @v: pointer of type atomic64_t
8844@@ -474,13 +751,29 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
8845
8846 __asm__ __volatile__ (
8847 PPC_ATOMIC_ENTRY_BARRIER
8848-"1: ldarx %0,0,%1 # __atomic_add_unless\n\
8849+"1: ldarx %0,0,%1 # atomic64_add_unless\n\
8850 cmpd 0,%0,%3 \n\
8851- beq- 2f \n\
8852- add %0,%2,%0 \n"
8853+ beq- 2f \n"
8854+
8855+#ifdef CONFIG_PAX_REFCOUNT
8856+" mcrxr cr0\n"
8857+" addo. %0,%2,%0\n"
8858+" bf 4*cr0+so, 4f\n"
8859+"3:.long " "0x00c00b00""\n"
8860+"4:\n"
8861+#else
8862+ "add %0,%2,%0 \n"
8863+#endif
8864+
8865 " stdcx. %0,0,%1 \n\
8866 bne- 1b \n"
8867 PPC_ATOMIC_EXIT_BARRIER
8868+"5:"
8869+
8870+#ifdef CONFIG_PAX_REFCOUNT
8871+ _ASM_EXTABLE(3b, 5b)
8872+#endif
8873+
8874 " subf %0,%2,%0 \n\
8875 2:"
8876 : "=&r" (t)
8877diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8878index bab79a1..4a3eabc 100644
8879--- a/arch/powerpc/include/asm/barrier.h
8880+++ b/arch/powerpc/include/asm/barrier.h
8881@@ -73,7 +73,7 @@
8882 do { \
8883 compiletime_assert_atomic_type(*p); \
8884 __lwsync(); \
8885- ACCESS_ONCE(*p) = (v); \
8886+ ACCESS_ONCE_RW(*p) = (v); \
8887 } while (0)
8888
8889 #define smp_load_acquire(p) \
8890diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8891index 34a05a1..a1f2c67 100644
8892--- a/arch/powerpc/include/asm/cache.h
8893+++ b/arch/powerpc/include/asm/cache.h
8894@@ -4,6 +4,7 @@
8895 #ifdef __KERNEL__
8896
8897 #include <asm/reg.h>
8898+#include <linux/const.h>
8899
8900 /* bytes per L1 cache line */
8901 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8902@@ -23,7 +24,7 @@
8903 #define L1_CACHE_SHIFT 7
8904 #endif
8905
8906-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8907+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8908
8909 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8910
8911diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8912index 888d8f3..66f581c 100644
8913--- a/arch/powerpc/include/asm/elf.h
8914+++ b/arch/powerpc/include/asm/elf.h
8915@@ -28,8 +28,19 @@
8916 the loader. We need to make sure that it is out of the way of the program
8917 that it will "exec", and that there is sufficient room for the brk. */
8918
8919-extern unsigned long randomize_et_dyn(unsigned long base);
8920-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8921+#define ELF_ET_DYN_BASE (0x20000000)
8922+
8923+#ifdef CONFIG_PAX_ASLR
8924+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8925+
8926+#ifdef __powerpc64__
8927+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8928+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8929+#else
8930+#define PAX_DELTA_MMAP_LEN 15
8931+#define PAX_DELTA_STACK_LEN 15
8932+#endif
8933+#endif
8934
8935 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8936
8937@@ -129,10 +140,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8938 (0x7ff >> (PAGE_SHIFT - 12)) : \
8939 (0x3ffff >> (PAGE_SHIFT - 12)))
8940
8941-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8942-#define arch_randomize_brk arch_randomize_brk
8943-
8944-
8945 #ifdef CONFIG_SPU_BASE
8946 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8947 #define NT_SPU 1
8948diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8949index 8196e9c..d83a9f3 100644
8950--- a/arch/powerpc/include/asm/exec.h
8951+++ b/arch/powerpc/include/asm/exec.h
8952@@ -4,6 +4,6 @@
8953 #ifndef _ASM_POWERPC_EXEC_H
8954 #define _ASM_POWERPC_EXEC_H
8955
8956-extern unsigned long arch_align_stack(unsigned long sp);
8957+#define arch_align_stack(x) ((x) & ~0xfUL)
8958
8959 #endif /* _ASM_POWERPC_EXEC_H */
8960diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8961index 5acabbd..7ea14fa 100644
8962--- a/arch/powerpc/include/asm/kmap_types.h
8963+++ b/arch/powerpc/include/asm/kmap_types.h
8964@@ -10,7 +10,7 @@
8965 * 2 of the License, or (at your option) any later version.
8966 */
8967
8968-#define KM_TYPE_NR 16
8969+#define KM_TYPE_NR 17
8970
8971 #endif /* __KERNEL__ */
8972 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8973diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8974index b8da913..c02b593 100644
8975--- a/arch/powerpc/include/asm/local.h
8976+++ b/arch/powerpc/include/asm/local.h
8977@@ -9,21 +9,65 @@ typedef struct
8978 atomic_long_t a;
8979 } local_t;
8980
8981+typedef struct
8982+{
8983+ atomic_long_unchecked_t a;
8984+} local_unchecked_t;
8985+
8986 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8987
8988 #define local_read(l) atomic_long_read(&(l)->a)
8989+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8990 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8991+#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8992
8993 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8994+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8995 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8996+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8997 #define local_inc(l) atomic_long_inc(&(l)->a)
8998+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8999 #define local_dec(l) atomic_long_dec(&(l)->a)
9000+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
9001
9002 static __inline__ long local_add_return(long a, local_t *l)
9003 {
9004 long t;
9005
9006 __asm__ __volatile__(
9007+"1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n"
9008+
9009+#ifdef CONFIG_PAX_REFCOUNT
9010+" mcrxr cr0\n"
9011+" addo. %0,%1,%0\n"
9012+" bf 4*cr0+so, 3f\n"
9013+"2:.long " "0x00c00b00""\n"
9014+#else
9015+" add %0,%1,%0\n"
9016+#endif
9017+
9018+"3:\n"
9019+ PPC405_ERR77(0,%2)
9020+ PPC_STLCX "%0,0,%2 \n\
9021+ bne- 1b"
9022+
9023+#ifdef CONFIG_PAX_REFCOUNT
9024+"\n4:\n"
9025+ _ASM_EXTABLE(2b, 4b)
9026+#endif
9027+
9028+ : "=&r" (t)
9029+ : "r" (a), "r" (&(l->a.counter))
9030+ : "cc", "memory");
9031+
9032+ return t;
9033+}
9034+
9035+static __inline__ long local_add_return_unchecked(long a, local_unchecked_t *l)
9036+{
9037+ long t;
9038+
9039+ __asm__ __volatile__(
9040 "1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n\
9041 add %0,%1,%0\n"
9042 PPC405_ERR77(0,%2)
9043@@ -101,6 +145,8 @@ static __inline__ long local_dec_return(local_t *l)
9044
9045 #define local_cmpxchg(l, o, n) \
9046 (cmpxchg_local(&((l)->a.counter), (o), (n)))
9047+#define local_cmpxchg_unchecked(l, o, n) \
9048+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
9049 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
9050
9051 /**
9052diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
9053index 8565c25..2865190 100644
9054--- a/arch/powerpc/include/asm/mman.h
9055+++ b/arch/powerpc/include/asm/mman.h
9056@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
9057 }
9058 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
9059
9060-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
9061+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
9062 {
9063 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
9064 }
9065diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
9066index 26fe1ae..987ffc5 100644
9067--- a/arch/powerpc/include/asm/page.h
9068+++ b/arch/powerpc/include/asm/page.h
9069@@ -227,8 +227,9 @@ extern long long virt_phys_offset;
9070 * and needs to be executable. This means the whole heap ends
9071 * up being executable.
9072 */
9073-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
9074- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9075+#define VM_DATA_DEFAULT_FLAGS32 \
9076+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
9077+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9078
9079 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
9080 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9081@@ -256,6 +257,9 @@ extern long long virt_phys_offset;
9082 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
9083 #endif
9084
9085+#define ktla_ktva(addr) (addr)
9086+#define ktva_ktla(addr) (addr)
9087+
9088 #ifndef CONFIG_PPC_BOOK3S_64
9089 /*
9090 * Use the top bit of the higher-level page table entries to indicate whether
9091diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
9092index 88693ce..ac6f9ab 100644
9093--- a/arch/powerpc/include/asm/page_64.h
9094+++ b/arch/powerpc/include/asm/page_64.h
9095@@ -153,15 +153,18 @@ do { \
9096 * stack by default, so in the absence of a PT_GNU_STACK program header
9097 * we turn execute permission off.
9098 */
9099-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
9100- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9101+#define VM_STACK_DEFAULT_FLAGS32 \
9102+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
9103+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9104
9105 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
9106 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9107
9108+#ifndef CONFIG_PAX_PAGEEXEC
9109 #define VM_STACK_DEFAULT_FLAGS \
9110 (is_32bit_task() ? \
9111 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
9112+#endif
9113
9114 #include <asm-generic/getorder.h>
9115
9116diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
9117index 4b0be20..c15a27d 100644
9118--- a/arch/powerpc/include/asm/pgalloc-64.h
9119+++ b/arch/powerpc/include/asm/pgalloc-64.h
9120@@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9121 #ifndef CONFIG_PPC_64K_PAGES
9122
9123 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
9124+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
9125
9126 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
9127 {
9128@@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
9129 pud_set(pud, (unsigned long)pmd);
9130 }
9131
9132+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
9133+{
9134+ pud_populate(mm, pud, pmd);
9135+}
9136+
9137 #define pmd_populate(mm, pmd, pte_page) \
9138 pmd_populate_kernel(mm, pmd, page_address(pte_page))
9139 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
9140@@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
9141 #endif
9142
9143 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
9144+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
9145
9146 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
9147 pte_t *pte)
9148diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
9149index d98c1ec..9f61569 100644
9150--- a/arch/powerpc/include/asm/pgtable.h
9151+++ b/arch/powerpc/include/asm/pgtable.h
9152@@ -2,6 +2,7 @@
9153 #define _ASM_POWERPC_PGTABLE_H
9154 #ifdef __KERNEL__
9155
9156+#include <linux/const.h>
9157 #ifndef __ASSEMBLY__
9158 #include <linux/mmdebug.h>
9159 #include <asm/processor.h> /* For TASK_SIZE */
9160diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
9161index 4aad413..85d86bf 100644
9162--- a/arch/powerpc/include/asm/pte-hash32.h
9163+++ b/arch/powerpc/include/asm/pte-hash32.h
9164@@ -21,6 +21,7 @@
9165 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
9166 #define _PAGE_USER 0x004 /* usermode access allowed */
9167 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
9168+#define _PAGE_EXEC _PAGE_GUARDED
9169 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
9170 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
9171 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
9172diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
9173index 0c05059..7e056e4 100644
9174--- a/arch/powerpc/include/asm/reg.h
9175+++ b/arch/powerpc/include/asm/reg.h
9176@@ -251,6 +251,7 @@
9177 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
9178 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
9179 #define DSISR_NOHPTE 0x40000000 /* no translation found */
9180+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
9181 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
9182 #define DSISR_ISSTORE 0x02000000 /* access was a store */
9183 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
9184diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
9185index 5a6614a..d89995d1 100644
9186--- a/arch/powerpc/include/asm/smp.h
9187+++ b/arch/powerpc/include/asm/smp.h
9188@@ -51,7 +51,7 @@ struct smp_ops_t {
9189 int (*cpu_disable)(void);
9190 void (*cpu_die)(unsigned int nr);
9191 int (*cpu_bootable)(unsigned int nr);
9192-};
9193+} __no_const;
9194
9195 extern void smp_send_debugger_break(void);
9196 extern void start_secondary_resume(void);
9197diff --git a/arch/powerpc/include/asm/spinlock.h b/arch/powerpc/include/asm/spinlock.h
9198index 4dbe072..b803275 100644
9199--- a/arch/powerpc/include/asm/spinlock.h
9200+++ b/arch/powerpc/include/asm/spinlock.h
9201@@ -204,13 +204,29 @@ static inline long __arch_read_trylock(arch_rwlock_t *rw)
9202 __asm__ __volatile__(
9203 "1: " PPC_LWARX(%0,0,%1,1) "\n"
9204 __DO_SIGN_EXTEND
9205-" addic. %0,%0,1\n\
9206- ble- 2f\n"
9207+
9208+#ifdef CONFIG_PAX_REFCOUNT
9209+" mcrxr cr0\n"
9210+" addico. %0,%0,1\n"
9211+" bf 4*cr0+so, 3f\n"
9212+"2:.long " "0x00c00b00""\n"
9213+#else
9214+" addic. %0,%0,1\n"
9215+#endif
9216+
9217+"3:\n"
9218+ "ble- 4f\n"
9219 PPC405_ERR77(0,%1)
9220 " stwcx. %0,0,%1\n\
9221 bne- 1b\n"
9222 PPC_ACQUIRE_BARRIER
9223-"2:" : "=&r" (tmp)
9224+"4:"
9225+
9226+#ifdef CONFIG_PAX_REFCOUNT
9227+ _ASM_EXTABLE(2b,4b)
9228+#endif
9229+
9230+ : "=&r" (tmp)
9231 : "r" (&rw->lock)
9232 : "cr0", "xer", "memory");
9233
9234@@ -286,11 +302,27 @@ static inline void arch_read_unlock(arch_rwlock_t *rw)
9235 __asm__ __volatile__(
9236 "# read_unlock\n\t"
9237 PPC_RELEASE_BARRIER
9238-"1: lwarx %0,0,%1\n\
9239- addic %0,%0,-1\n"
9240+"1: lwarx %0,0,%1\n"
9241+
9242+#ifdef CONFIG_PAX_REFCOUNT
9243+" mcrxr cr0\n"
9244+" addico. %0,%0,-1\n"
9245+" bf 4*cr0+so, 3f\n"
9246+"2:.long " "0x00c00b00""\n"
9247+#else
9248+" addic. %0,%0,-1\n"
9249+#endif
9250+
9251+"3:\n"
9252 PPC405_ERR77(0,%1)
9253 " stwcx. %0,0,%1\n\
9254 bne- 1b"
9255+
9256+#ifdef CONFIG_PAX_REFCOUNT
9257+"\n4:\n"
9258+ _ASM_EXTABLE(2b, 4b)
9259+#endif
9260+
9261 : "=&r"(tmp)
9262 : "r"(&rw->lock)
9263 : "cr0", "xer", "memory");
9264diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
9265index b034ecd..af7e31f 100644
9266--- a/arch/powerpc/include/asm/thread_info.h
9267+++ b/arch/powerpc/include/asm/thread_info.h
9268@@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
9269 #if defined(CONFIG_PPC64)
9270 #define TIF_ELF2ABI 18 /* function descriptors must die! */
9271 #endif
9272+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
9273+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
9274
9275 /* as above, but as bit values */
9276 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
9277@@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
9278 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9279 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
9280 #define _TIF_NOHZ (1<<TIF_NOHZ)
9281+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9282 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
9283 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
9284- _TIF_NOHZ)
9285+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
9286
9287 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
9288 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
9289diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
9290index 9485b43..3bd3c16 100644
9291--- a/arch/powerpc/include/asm/uaccess.h
9292+++ b/arch/powerpc/include/asm/uaccess.h
9293@@ -58,6 +58,7 @@
9294
9295 #endif
9296
9297+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9298 #define access_ok(type, addr, size) \
9299 (__chk_user_ptr(addr), \
9300 __access_ok((__force unsigned long)(addr), (size), get_fs()))
9301@@ -318,52 +319,6 @@ do { \
9302 extern unsigned long __copy_tofrom_user(void __user *to,
9303 const void __user *from, unsigned long size);
9304
9305-#ifndef __powerpc64__
9306-
9307-static inline unsigned long copy_from_user(void *to,
9308- const void __user *from, unsigned long n)
9309-{
9310- unsigned long over;
9311-
9312- if (access_ok(VERIFY_READ, from, n))
9313- return __copy_tofrom_user((__force void __user *)to, from, n);
9314- if ((unsigned long)from < TASK_SIZE) {
9315- over = (unsigned long)from + n - TASK_SIZE;
9316- return __copy_tofrom_user((__force void __user *)to, from,
9317- n - over) + over;
9318- }
9319- return n;
9320-}
9321-
9322-static inline unsigned long copy_to_user(void __user *to,
9323- const void *from, unsigned long n)
9324-{
9325- unsigned long over;
9326-
9327- if (access_ok(VERIFY_WRITE, to, n))
9328- return __copy_tofrom_user(to, (__force void __user *)from, n);
9329- if ((unsigned long)to < TASK_SIZE) {
9330- over = (unsigned long)to + n - TASK_SIZE;
9331- return __copy_tofrom_user(to, (__force void __user *)from,
9332- n - over) + over;
9333- }
9334- return n;
9335-}
9336-
9337-#else /* __powerpc64__ */
9338-
9339-#define __copy_in_user(to, from, size) \
9340- __copy_tofrom_user((to), (from), (size))
9341-
9342-extern unsigned long copy_from_user(void *to, const void __user *from,
9343- unsigned long n);
9344-extern unsigned long copy_to_user(void __user *to, const void *from,
9345- unsigned long n);
9346-extern unsigned long copy_in_user(void __user *to, const void __user *from,
9347- unsigned long n);
9348-
9349-#endif /* __powerpc64__ */
9350-
9351 static inline unsigned long __copy_from_user_inatomic(void *to,
9352 const void __user *from, unsigned long n)
9353 {
9354@@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
9355 if (ret == 0)
9356 return 0;
9357 }
9358+
9359+ if (!__builtin_constant_p(n))
9360+ check_object_size(to, n, false);
9361+
9362 return __copy_tofrom_user((__force void __user *)to, from, n);
9363 }
9364
9365@@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
9366 if (ret == 0)
9367 return 0;
9368 }
9369+
9370+ if (!__builtin_constant_p(n))
9371+ check_object_size(from, n, true);
9372+
9373 return __copy_tofrom_user(to, (__force const void __user *)from, n);
9374 }
9375
9376@@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
9377 return __copy_to_user_inatomic(to, from, size);
9378 }
9379
9380+#ifndef __powerpc64__
9381+
9382+static inline unsigned long __must_check copy_from_user(void *to,
9383+ const void __user *from, unsigned long n)
9384+{
9385+ unsigned long over;
9386+
9387+ if ((long)n < 0)
9388+ return n;
9389+
9390+ if (access_ok(VERIFY_READ, from, n)) {
9391+ if (!__builtin_constant_p(n))
9392+ check_object_size(to, n, false);
9393+ return __copy_tofrom_user((__force void __user *)to, from, n);
9394+ }
9395+ if ((unsigned long)from < TASK_SIZE) {
9396+ over = (unsigned long)from + n - TASK_SIZE;
9397+ if (!__builtin_constant_p(n - over))
9398+ check_object_size(to, n - over, false);
9399+ return __copy_tofrom_user((__force void __user *)to, from,
9400+ n - over) + over;
9401+ }
9402+ return n;
9403+}
9404+
9405+static inline unsigned long __must_check copy_to_user(void __user *to,
9406+ const void *from, unsigned long n)
9407+{
9408+ unsigned long over;
9409+
9410+ if ((long)n < 0)
9411+ return n;
9412+
9413+ if (access_ok(VERIFY_WRITE, to, n)) {
9414+ if (!__builtin_constant_p(n))
9415+ check_object_size(from, n, true);
9416+ return __copy_tofrom_user(to, (__force void __user *)from, n);
9417+ }
9418+ if ((unsigned long)to < TASK_SIZE) {
9419+ over = (unsigned long)to + n - TASK_SIZE;
9420+ if (!__builtin_constant_p(n))
9421+ check_object_size(from, n - over, true);
9422+ return __copy_tofrom_user(to, (__force void __user *)from,
9423+ n - over) + over;
9424+ }
9425+ return n;
9426+}
9427+
9428+#else /* __powerpc64__ */
9429+
9430+#define __copy_in_user(to, from, size) \
9431+ __copy_tofrom_user((to), (from), (size))
9432+
9433+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
9434+{
9435+ if ((long)n < 0 || n > INT_MAX)
9436+ return n;
9437+
9438+ if (!__builtin_constant_p(n))
9439+ check_object_size(to, n, false);
9440+
9441+ if (likely(access_ok(VERIFY_READ, from, n)))
9442+ n = __copy_from_user(to, from, n);
9443+ else
9444+ memset(to, 0, n);
9445+ return n;
9446+}
9447+
9448+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
9449+{
9450+ if ((long)n < 0 || n > INT_MAX)
9451+ return n;
9452+
9453+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
9454+ if (!__builtin_constant_p(n))
9455+ check_object_size(from, n, true);
9456+ n = __copy_to_user(to, from, n);
9457+ }
9458+ return n;
9459+}
9460+
9461+extern unsigned long copy_in_user(void __user *to, const void __user *from,
9462+ unsigned long n);
9463+
9464+#endif /* __powerpc64__ */
9465+
9466 extern unsigned long __clear_user(void __user *addr, unsigned long size);
9467
9468 static inline unsigned long clear_user(void __user *addr, unsigned long size)
9469diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
9470index 670c312..60c2b52 100644
9471--- a/arch/powerpc/kernel/Makefile
9472+++ b/arch/powerpc/kernel/Makefile
9473@@ -27,6 +27,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
9474 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
9475 endif
9476
9477+CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
9478+
9479 obj-y := cputable.o ptrace.o syscalls.o \
9480 irq.o align.o signal_32.o pmc.o vdso.o \
9481 process.o systbl.o idle.o \
9482diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
9483index bb9cac6..5181202 100644
9484--- a/arch/powerpc/kernel/exceptions-64e.S
9485+++ b/arch/powerpc/kernel/exceptions-64e.S
9486@@ -1010,6 +1010,7 @@ storage_fault_common:
9487 std r14,_DAR(r1)
9488 std r15,_DSISR(r1)
9489 addi r3,r1,STACK_FRAME_OVERHEAD
9490+ bl save_nvgprs
9491 mr r4,r14
9492 mr r5,r15
9493 ld r14,PACA_EXGEN+EX_R14(r13)
9494@@ -1018,8 +1019,7 @@ storage_fault_common:
9495 cmpdi r3,0
9496 bne- 1f
9497 b ret_from_except_lite
9498-1: bl save_nvgprs
9499- mr r5,r3
9500+1: mr r5,r3
9501 addi r3,r1,STACK_FRAME_OVERHEAD
9502 ld r4,_DAR(r1)
9503 bl bad_page_fault
9504diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
9505index 050f79a..f385bfe 100644
9506--- a/arch/powerpc/kernel/exceptions-64s.S
9507+++ b/arch/powerpc/kernel/exceptions-64s.S
9508@@ -1593,10 +1593,10 @@ handle_page_fault:
9509 11: ld r4,_DAR(r1)
9510 ld r5,_DSISR(r1)
9511 addi r3,r1,STACK_FRAME_OVERHEAD
9512+ bl save_nvgprs
9513 bl do_page_fault
9514 cmpdi r3,0
9515 beq+ 12f
9516- bl save_nvgprs
9517 mr r5,r3
9518 addi r3,r1,STACK_FRAME_OVERHEAD
9519 lwz r4,_DAR(r1)
9520diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
9521index 4c5891d..a5d88bb 100644
9522--- a/arch/powerpc/kernel/irq.c
9523+++ b/arch/powerpc/kernel/irq.c
9524@@ -461,6 +461,8 @@ void migrate_irqs(void)
9525 }
9526 #endif
9527
9528+extern void gr_handle_kernel_exploit(void);
9529+
9530 static inline void check_stack_overflow(void)
9531 {
9532 #ifdef CONFIG_DEBUG_STACKOVERFLOW
9533@@ -473,6 +475,7 @@ static inline void check_stack_overflow(void)
9534 printk("do_IRQ: stack overflow: %ld\n",
9535 sp - sizeof(struct thread_info));
9536 dump_stack();
9537+ gr_handle_kernel_exploit();
9538 }
9539 #endif
9540 }
9541diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
9542index 6cff040..74ac5d1b 100644
9543--- a/arch/powerpc/kernel/module_32.c
9544+++ b/arch/powerpc/kernel/module_32.c
9545@@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
9546 me->arch.core_plt_section = i;
9547 }
9548 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
9549- printk("Module doesn't contain .plt or .init.plt sections.\n");
9550+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
9551 return -ENOEXEC;
9552 }
9553
9554@@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
9555
9556 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
9557 /* Init, or core PLT? */
9558- if (location >= mod->module_core
9559- && location < mod->module_core + mod->core_size)
9560+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
9561+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
9562 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
9563- else
9564+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
9565+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
9566 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
9567+ else {
9568+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
9569+ return ~0UL;
9570+ }
9571
9572 /* Find this entry, or if that fails, the next avail. entry */
9573 while (entry->jump[0]) {
9574@@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
9575 }
9576 #ifdef CONFIG_DYNAMIC_FTRACE
9577 module->arch.tramp =
9578- do_plt_call(module->module_core,
9579+ do_plt_call(module->module_core_rx,
9580 (unsigned long)ftrace_caller,
9581 sechdrs, module);
9582 #endif
9583diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
9584index bf44ae9..6d2ce71 100644
9585--- a/arch/powerpc/kernel/process.c
9586+++ b/arch/powerpc/kernel/process.c
9587@@ -1039,8 +1039,8 @@ void show_regs(struct pt_regs * regs)
9588 * Lookup NIP late so we have the best change of getting the
9589 * above info out without failing
9590 */
9591- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
9592- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
9593+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
9594+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
9595 #endif
9596 show_stack(current, (unsigned long *) regs->gpr[1]);
9597 if (!user_mode(regs))
9598@@ -1558,10 +1558,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
9599 newsp = stack[0];
9600 ip = stack[STACK_FRAME_LR_SAVE];
9601 if (!firstframe || ip != lr) {
9602- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
9603+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
9604 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
9605 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
9606- printk(" (%pS)",
9607+ printk(" (%pA)",
9608 (void *)current->ret_stack[curr_frame].ret);
9609 curr_frame--;
9610 }
9611@@ -1581,7 +1581,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
9612 struct pt_regs *regs = (struct pt_regs *)
9613 (sp + STACK_FRAME_OVERHEAD);
9614 lr = regs->link;
9615- printk("--- interrupt: %lx at %pS\n LR = %pS\n",
9616+ printk("--- interrupt: %lx at %pA\n LR = %pA\n",
9617 regs->trap, (void *)regs->nip, (void *)lr);
9618 firstframe = 1;
9619 }
9620@@ -1617,58 +1617,3 @@ void notrace __ppc64_runlatch_off(void)
9621 mtspr(SPRN_CTRLT, ctrl);
9622 }
9623 #endif /* CONFIG_PPC64 */
9624-
9625-unsigned long arch_align_stack(unsigned long sp)
9626-{
9627- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9628- sp -= get_random_int() & ~PAGE_MASK;
9629- return sp & ~0xf;
9630-}
9631-
9632-static inline unsigned long brk_rnd(void)
9633-{
9634- unsigned long rnd = 0;
9635-
9636- /* 8MB for 32bit, 1GB for 64bit */
9637- if (is_32bit_task())
9638- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
9639- else
9640- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
9641-
9642- return rnd << PAGE_SHIFT;
9643-}
9644-
9645-unsigned long arch_randomize_brk(struct mm_struct *mm)
9646-{
9647- unsigned long base = mm->brk;
9648- unsigned long ret;
9649-
9650-#ifdef CONFIG_PPC_STD_MMU_64
9651- /*
9652- * If we are using 1TB segments and we are allowed to randomise
9653- * the heap, we can put it above 1TB so it is backed by a 1TB
9654- * segment. Otherwise the heap will be in the bottom 1TB
9655- * which always uses 256MB segments and this may result in a
9656- * performance penalty.
9657- */
9658- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
9659- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
9660-#endif
9661-
9662- ret = PAGE_ALIGN(base + brk_rnd());
9663-
9664- if (ret < mm->brk)
9665- return mm->brk;
9666-
9667- return ret;
9668-}
9669-
9670-unsigned long randomize_et_dyn(unsigned long base)
9671-{
9672- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
9673-
9674- if (ret < base)
9675- return base;
9676-
9677- return ret;
9678-}
9679diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
9680index 2e3d2bf..35df241 100644
9681--- a/arch/powerpc/kernel/ptrace.c
9682+++ b/arch/powerpc/kernel/ptrace.c
9683@@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
9684 return ret;
9685 }
9686
9687+#ifdef CONFIG_GRKERNSEC_SETXID
9688+extern void gr_delayed_cred_worker(void);
9689+#endif
9690+
9691 /*
9692 * We must return the syscall number to actually look up in the table.
9693 * This can be -1L to skip running any syscall at all.
9694@@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
9695
9696 secure_computing_strict(regs->gpr[0]);
9697
9698+#ifdef CONFIG_GRKERNSEC_SETXID
9699+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9700+ gr_delayed_cred_worker();
9701+#endif
9702+
9703 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
9704 tracehook_report_syscall_entry(regs))
9705 /*
9706@@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
9707 {
9708 int step;
9709
9710+#ifdef CONFIG_GRKERNSEC_SETXID
9711+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9712+ gr_delayed_cred_worker();
9713+#endif
9714+
9715 audit_syscall_exit(regs);
9716
9717 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9718diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
9719index b171001..4ac7ac5 100644
9720--- a/arch/powerpc/kernel/signal_32.c
9721+++ b/arch/powerpc/kernel/signal_32.c
9722@@ -1011,7 +1011,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
9723 /* Save user registers on the stack */
9724 frame = &rt_sf->uc.uc_mcontext;
9725 addr = frame;
9726- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
9727+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9728 sigret = 0;
9729 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
9730 } else {
9731diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
9732index 2cb0c94..c0c0bc9 100644
9733--- a/arch/powerpc/kernel/signal_64.c
9734+++ b/arch/powerpc/kernel/signal_64.c
9735@@ -754,7 +754,7 @@ int handle_rt_signal64(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs
9736 current->thread.fp_state.fpscr = 0;
9737
9738 /* Set up to return from userspace. */
9739- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
9740+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9741 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
9742 } else {
9743 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
9744diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
9745index 0dc43f9..a885d33 100644
9746--- a/arch/powerpc/kernel/traps.c
9747+++ b/arch/powerpc/kernel/traps.c
9748@@ -36,6 +36,7 @@
9749 #include <linux/debugfs.h>
9750 #include <linux/ratelimit.h>
9751 #include <linux/context_tracking.h>
9752+#include <linux/uaccess.h>
9753
9754 #include <asm/emulated_ops.h>
9755 #include <asm/pgtable.h>
9756@@ -142,6 +143,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
9757 return flags;
9758 }
9759
9760+extern void gr_handle_kernel_exploit(void);
9761+
9762 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9763 int signr)
9764 {
9765@@ -191,6 +194,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9766 panic("Fatal exception in interrupt");
9767 if (panic_on_oops)
9768 panic("Fatal exception");
9769+
9770+ gr_handle_kernel_exploit();
9771+
9772 do_exit(signr);
9773 }
9774
9775@@ -1137,6 +1143,26 @@ void __kprobes program_check_exception(struct pt_regs *regs)
9776 enum ctx_state prev_state = exception_enter();
9777 unsigned int reason = get_reason(regs);
9778
9779+#ifdef CONFIG_PAX_REFCOUNT
9780+ unsigned int bkpt;
9781+ const struct exception_table_entry *entry;
9782+
9783+ if (reason & REASON_ILLEGAL) {
9784+ /* Check if PaX bad instruction */
9785+ if (!probe_kernel_address(regs->nip, bkpt) && bkpt == 0xc00b00) {
9786+ current->thread.trap_nr = 0;
9787+ pax_report_refcount_overflow(regs);
9788+ /* fixup_exception() for PowerPC does not exist, simulate its job */
9789+ if ((entry = search_exception_tables(regs->nip)) != NULL) {
9790+ regs->nip = entry->fixup;
9791+ return;
9792+ }
9793+ /* fixup_exception() could not handle */
9794+ goto bail;
9795+ }
9796+ }
9797+#endif
9798+
9799 /* We can now get here via a FP Unavailable exception if the core
9800 * has no FPU, in that case the reason flags will be 0 */
9801
9802diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
9803index f174351..5722009 100644
9804--- a/arch/powerpc/kernel/vdso.c
9805+++ b/arch/powerpc/kernel/vdso.c
9806@@ -35,6 +35,7 @@
9807 #include <asm/vdso.h>
9808 #include <asm/vdso_datapage.h>
9809 #include <asm/setup.h>
9810+#include <asm/mman.h>
9811
9812 #undef DEBUG
9813
9814@@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9815 vdso_base = VDSO32_MBASE;
9816 #endif
9817
9818- current->mm->context.vdso_base = 0;
9819+ current->mm->context.vdso_base = ~0UL;
9820
9821 /* vDSO has a problem and was disabled, just don't "enable" it for the
9822 * process
9823@@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9824 vdso_base = get_unmapped_area(NULL, vdso_base,
9825 (vdso_pages << PAGE_SHIFT) +
9826 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
9827- 0, 0);
9828+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
9829 if (IS_ERR_VALUE(vdso_base)) {
9830 rc = vdso_base;
9831 goto fail_mmapsem;
9832diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
9833index 4c79284..0e462c3 100644
9834--- a/arch/powerpc/kvm/powerpc.c
9835+++ b/arch/powerpc/kvm/powerpc.c
9836@@ -1338,7 +1338,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
9837 }
9838 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
9839
9840-int kvm_arch_init(void *opaque)
9841+int kvm_arch_init(const void *opaque)
9842 {
9843 return 0;
9844 }
9845diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
9846index 5eea6f3..5d10396 100644
9847--- a/arch/powerpc/lib/usercopy_64.c
9848+++ b/arch/powerpc/lib/usercopy_64.c
9849@@ -9,22 +9,6 @@
9850 #include <linux/module.h>
9851 #include <asm/uaccess.h>
9852
9853-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9854-{
9855- if (likely(access_ok(VERIFY_READ, from, n)))
9856- n = __copy_from_user(to, from, n);
9857- else
9858- memset(to, 0, n);
9859- return n;
9860-}
9861-
9862-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9863-{
9864- if (likely(access_ok(VERIFY_WRITE, to, n)))
9865- n = __copy_to_user(to, from, n);
9866- return n;
9867-}
9868-
9869 unsigned long copy_in_user(void __user *to, const void __user *from,
9870 unsigned long n)
9871 {
9872@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
9873 return n;
9874 }
9875
9876-EXPORT_SYMBOL(copy_from_user);
9877-EXPORT_SYMBOL(copy_to_user);
9878 EXPORT_SYMBOL(copy_in_user);
9879
9880diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
9881index 51ab9e7..7d3c78b 100644
9882--- a/arch/powerpc/mm/fault.c
9883+++ b/arch/powerpc/mm/fault.c
9884@@ -33,6 +33,10 @@
9885 #include <linux/magic.h>
9886 #include <linux/ratelimit.h>
9887 #include <linux/context_tracking.h>
9888+#include <linux/slab.h>
9889+#include <linux/pagemap.h>
9890+#include <linux/compiler.h>
9891+#include <linux/unistd.h>
9892
9893 #include <asm/firmware.h>
9894 #include <asm/page.h>
9895@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
9896 }
9897 #endif
9898
9899+#ifdef CONFIG_PAX_PAGEEXEC
9900+/*
9901+ * PaX: decide what to do with offenders (regs->nip = fault address)
9902+ *
9903+ * returns 1 when task should be killed
9904+ */
9905+static int pax_handle_fetch_fault(struct pt_regs *regs)
9906+{
9907+ return 1;
9908+}
9909+
9910+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9911+{
9912+ unsigned long i;
9913+
9914+ printk(KERN_ERR "PAX: bytes at PC: ");
9915+ for (i = 0; i < 5; i++) {
9916+ unsigned int c;
9917+ if (get_user(c, (unsigned int __user *)pc+i))
9918+ printk(KERN_CONT "???????? ");
9919+ else
9920+ printk(KERN_CONT "%08x ", c);
9921+ }
9922+ printk("\n");
9923+}
9924+#endif
9925+
9926 /*
9927 * Check whether the instruction at regs->nip is a store using
9928 * an update addressing form which will update r1.
9929@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
9930 * indicate errors in DSISR but can validly be set in SRR1.
9931 */
9932 if (trap == 0x400)
9933- error_code &= 0x48200000;
9934+ error_code &= 0x58200000;
9935 else
9936 is_write = error_code & DSISR_ISSTORE;
9937 #else
9938@@ -378,7 +409,7 @@ good_area:
9939 * "undefined". Of those that can be set, this is the only
9940 * one which seems bad.
9941 */
9942- if (error_code & 0x10000000)
9943+ if (error_code & DSISR_GUARDED)
9944 /* Guarded storage error. */
9945 goto bad_area;
9946 #endif /* CONFIG_8xx */
9947@@ -393,7 +424,7 @@ good_area:
9948 * processors use the same I/D cache coherency mechanism
9949 * as embedded.
9950 */
9951- if (error_code & DSISR_PROTFAULT)
9952+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
9953 goto bad_area;
9954 #endif /* CONFIG_PPC_STD_MMU */
9955
9956@@ -483,6 +514,23 @@ bad_area:
9957 bad_area_nosemaphore:
9958 /* User mode accesses cause a SIGSEGV */
9959 if (user_mode(regs)) {
9960+
9961+#ifdef CONFIG_PAX_PAGEEXEC
9962+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
9963+#ifdef CONFIG_PPC_STD_MMU
9964+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
9965+#else
9966+ if (is_exec && regs->nip == address) {
9967+#endif
9968+ switch (pax_handle_fetch_fault(regs)) {
9969+ }
9970+
9971+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
9972+ do_group_exit(SIGKILL);
9973+ }
9974+ }
9975+#endif
9976+
9977 _exception(SIGSEGV, regs, code, address);
9978 goto bail;
9979 }
9980diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9981index cb8bdbe..cde4bc7 100644
9982--- a/arch/powerpc/mm/mmap.c
9983+++ b/arch/powerpc/mm/mmap.c
9984@@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9985 return sysctl_legacy_va_layout;
9986 }
9987
9988-static unsigned long mmap_rnd(void)
9989+static unsigned long mmap_rnd(struct mm_struct *mm)
9990 {
9991 unsigned long rnd = 0;
9992
9993+#ifdef CONFIG_PAX_RANDMMAP
9994+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9995+#endif
9996+
9997 if (current->flags & PF_RANDOMIZE) {
9998 /* 8MB for 32bit, 1GB for 64bit */
9999 if (is_32bit_task())
10000@@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
10001 return rnd << PAGE_SHIFT;
10002 }
10003
10004-static inline unsigned long mmap_base(void)
10005+static inline unsigned long mmap_base(struct mm_struct *mm)
10006 {
10007 unsigned long gap = rlimit(RLIMIT_STACK);
10008
10009@@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
10010 else if (gap > MAX_GAP)
10011 gap = MAX_GAP;
10012
10013- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
10014+ return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
10015 }
10016
10017 /*
10018@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10019 */
10020 if (mmap_is_legacy()) {
10021 mm->mmap_base = TASK_UNMAPPED_BASE;
10022+
10023+#ifdef CONFIG_PAX_RANDMMAP
10024+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10025+ mm->mmap_base += mm->delta_mmap;
10026+#endif
10027+
10028 mm->get_unmapped_area = arch_get_unmapped_area;
10029 } else {
10030- mm->mmap_base = mmap_base();
10031+ mm->mmap_base = mmap_base(mm);
10032+
10033+#ifdef CONFIG_PAX_RANDMMAP
10034+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10035+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10036+#endif
10037+
10038 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10039 }
10040 }
10041diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
10042index b0c75cc..ef7fb93 100644
10043--- a/arch/powerpc/mm/slice.c
10044+++ b/arch/powerpc/mm/slice.c
10045@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
10046 if ((mm->task_size - len) < addr)
10047 return 0;
10048 vma = find_vma(mm, addr);
10049- return (!vma || (addr + len) <= vma->vm_start);
10050+ return check_heap_stack_gap(vma, addr, len, 0);
10051 }
10052
10053 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
10054@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
10055 info.align_offset = 0;
10056
10057 addr = TASK_UNMAPPED_BASE;
10058+
10059+#ifdef CONFIG_PAX_RANDMMAP
10060+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10061+ addr += mm->delta_mmap;
10062+#endif
10063+
10064 while (addr < TASK_SIZE) {
10065 info.low_limit = addr;
10066 if (!slice_scan_available(addr, available, 1, &addr))
10067@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
10068 if (fixed && addr > (mm->task_size - len))
10069 return -ENOMEM;
10070
10071+#ifdef CONFIG_PAX_RANDMMAP
10072+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
10073+ addr = 0;
10074+#endif
10075+
10076 /* If hint, make sure it matches our alignment restrictions */
10077 if (!fixed && addr) {
10078 addr = _ALIGN_UP(addr, 1ul << pshift);
10079diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
10080index 3afa6f4..40c53ff 100644
10081--- a/arch/powerpc/net/bpf_jit_comp.c
10082+++ b/arch/powerpc/net/bpf_jit_comp.c
10083@@ -697,5 +697,6 @@ void bpf_jit_free(struct bpf_prog *fp)
10084 {
10085 if (fp->jited)
10086 module_free(NULL, fp->bpf_func);
10087- kfree(fp);
10088+
10089+ bpf_prog_unlock_free(fp);
10090 }
10091diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
10092index 4278acf..67fd0e6 100644
10093--- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
10094+++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
10095@@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
10096 }
10097
10098 static struct pci_ops scc_pciex_pci_ops = {
10099- scc_pciex_read_config,
10100- scc_pciex_write_config,
10101+ .read = scc_pciex_read_config,
10102+ .write = scc_pciex_write_config,
10103 };
10104
10105 static void pciex_clear_intr_all(unsigned int __iomem *base)
10106diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
10107index d966bbe..372124a 100644
10108--- a/arch/powerpc/platforms/cell/spufs/file.c
10109+++ b/arch/powerpc/platforms/cell/spufs/file.c
10110@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10111 return VM_FAULT_NOPAGE;
10112 }
10113
10114-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
10115+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
10116 unsigned long address,
10117- void *buf, int len, int write)
10118+ void *buf, size_t len, int write)
10119 {
10120 struct spu_context *ctx = vma->vm_file->private_data;
10121 unsigned long offset = address - vma->vm_start;
10122diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
10123index fa934fe..c296056 100644
10124--- a/arch/s390/include/asm/atomic.h
10125+++ b/arch/s390/include/asm/atomic.h
10126@@ -412,4 +412,14 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
10127 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
10128 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10129
10130+#define atomic64_read_unchecked(v) atomic64_read(v)
10131+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
10132+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
10133+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
10134+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
10135+#define atomic64_inc_unchecked(v) atomic64_inc(v)
10136+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
10137+#define atomic64_dec_unchecked(v) atomic64_dec(v)
10138+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
10139+
10140 #endif /* __ARCH_S390_ATOMIC__ */
10141diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
10142index 19ff956..8d39cb1 100644
10143--- a/arch/s390/include/asm/barrier.h
10144+++ b/arch/s390/include/asm/barrier.h
10145@@ -37,7 +37,7 @@
10146 do { \
10147 compiletime_assert_atomic_type(*p); \
10148 barrier(); \
10149- ACCESS_ONCE(*p) = (v); \
10150+ ACCESS_ONCE_RW(*p) = (v); \
10151 } while (0)
10152
10153 #define smp_load_acquire(p) \
10154diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
10155index 4d7ccac..d03d0ad 100644
10156--- a/arch/s390/include/asm/cache.h
10157+++ b/arch/s390/include/asm/cache.h
10158@@ -9,8 +9,10 @@
10159 #ifndef __ARCH_S390_CACHE_H
10160 #define __ARCH_S390_CACHE_H
10161
10162-#define L1_CACHE_BYTES 256
10163+#include <linux/const.h>
10164+
10165 #define L1_CACHE_SHIFT 8
10166+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10167 #define NET_SKB_PAD 32
10168
10169 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10170diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
10171index 78f4f87..598ce39 100644
10172--- a/arch/s390/include/asm/elf.h
10173+++ b/arch/s390/include/asm/elf.h
10174@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
10175 the loader. We need to make sure that it is out of the way of the program
10176 that it will "exec", and that there is sufficient room for the brk. */
10177
10178-extern unsigned long randomize_et_dyn(unsigned long base);
10179-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
10180+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
10181+
10182+#ifdef CONFIG_PAX_ASLR
10183+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
10184+
10185+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
10186+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
10187+#endif
10188
10189 /* This yields a mask that user programs can use to figure out what
10190 instruction set this CPU supports. */
10191@@ -222,9 +228,6 @@ struct linux_binprm;
10192 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
10193 int arch_setup_additional_pages(struct linux_binprm *, int);
10194
10195-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10196-#define arch_randomize_brk arch_randomize_brk
10197-
10198 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
10199
10200 #endif
10201diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
10202index c4a93d6..4d2a9b4 100644
10203--- a/arch/s390/include/asm/exec.h
10204+++ b/arch/s390/include/asm/exec.h
10205@@ -7,6 +7,6 @@
10206 #ifndef __ASM_EXEC_H
10207 #define __ASM_EXEC_H
10208
10209-extern unsigned long arch_align_stack(unsigned long sp);
10210+#define arch_align_stack(x) ((x) & ~0xfUL)
10211
10212 #endif /* __ASM_EXEC_H */
10213diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
10214index cd4c68e..6764641 100644
10215--- a/arch/s390/include/asm/uaccess.h
10216+++ b/arch/s390/include/asm/uaccess.h
10217@@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
10218 __range_ok((unsigned long)(addr), (size)); \
10219 })
10220
10221+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
10222 #define access_ok(type, addr, size) __access_ok(addr, size)
10223
10224 /*
10225@@ -275,6 +276,10 @@ static inline unsigned long __must_check
10226 copy_to_user(void __user *to, const void *from, unsigned long n)
10227 {
10228 might_fault();
10229+
10230+ if ((long)n < 0)
10231+ return n;
10232+
10233 return __copy_to_user(to, from, n);
10234 }
10235
10236@@ -303,10 +308,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
10237 static inline unsigned long __must_check
10238 copy_from_user(void *to, const void __user *from, unsigned long n)
10239 {
10240- unsigned int sz = __compiletime_object_size(to);
10241+ size_t sz = __compiletime_object_size(to);
10242
10243 might_fault();
10244- if (unlikely(sz != -1 && sz < n)) {
10245+
10246+ if ((long)n < 0)
10247+ return n;
10248+
10249+ if (unlikely(sz != (size_t)-1 && sz < n)) {
10250 copy_from_user_overflow();
10251 return n;
10252 }
10253diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
10254index b89b591..fd9609d 100644
10255--- a/arch/s390/kernel/module.c
10256+++ b/arch/s390/kernel/module.c
10257@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
10258
10259 /* Increase core size by size of got & plt and set start
10260 offsets for got and plt. */
10261- me->core_size = ALIGN(me->core_size, 4);
10262- me->arch.got_offset = me->core_size;
10263- me->core_size += me->arch.got_size;
10264- me->arch.plt_offset = me->core_size;
10265- me->core_size += me->arch.plt_size;
10266+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
10267+ me->arch.got_offset = me->core_size_rw;
10268+ me->core_size_rw += me->arch.got_size;
10269+ me->arch.plt_offset = me->core_size_rx;
10270+ me->core_size_rx += me->arch.plt_size;
10271 return 0;
10272 }
10273
10274@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10275 if (info->got_initialized == 0) {
10276 Elf_Addr *gotent;
10277
10278- gotent = me->module_core + me->arch.got_offset +
10279+ gotent = me->module_core_rw + me->arch.got_offset +
10280 info->got_offset;
10281 *gotent = val;
10282 info->got_initialized = 1;
10283@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10284 rc = apply_rela_bits(loc, val, 0, 64, 0);
10285 else if (r_type == R_390_GOTENT ||
10286 r_type == R_390_GOTPLTENT) {
10287- val += (Elf_Addr) me->module_core - loc;
10288+ val += (Elf_Addr) me->module_core_rw - loc;
10289 rc = apply_rela_bits(loc, val, 1, 32, 1);
10290 }
10291 break;
10292@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10293 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
10294 if (info->plt_initialized == 0) {
10295 unsigned int *ip;
10296- ip = me->module_core + me->arch.plt_offset +
10297+ ip = me->module_core_rx + me->arch.plt_offset +
10298 info->plt_offset;
10299 #ifndef CONFIG_64BIT
10300 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
10301@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10302 val - loc + 0xffffUL < 0x1ffffeUL) ||
10303 (r_type == R_390_PLT32DBL &&
10304 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
10305- val = (Elf_Addr) me->module_core +
10306+ val = (Elf_Addr) me->module_core_rx +
10307 me->arch.plt_offset +
10308 info->plt_offset;
10309 val += rela->r_addend - loc;
10310@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10311 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
10312 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
10313 val = val + rela->r_addend -
10314- ((Elf_Addr) me->module_core + me->arch.got_offset);
10315+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
10316 if (r_type == R_390_GOTOFF16)
10317 rc = apply_rela_bits(loc, val, 0, 16, 0);
10318 else if (r_type == R_390_GOTOFF32)
10319@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10320 break;
10321 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
10322 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
10323- val = (Elf_Addr) me->module_core + me->arch.got_offset +
10324+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
10325 rela->r_addend - loc;
10326 if (r_type == R_390_GOTPC)
10327 rc = apply_rela_bits(loc, val, 1, 32, 0);
10328diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
10329index 93b9ca4..4ea1454 100644
10330--- a/arch/s390/kernel/process.c
10331+++ b/arch/s390/kernel/process.c
10332@@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
10333 }
10334 return 0;
10335 }
10336-
10337-unsigned long arch_align_stack(unsigned long sp)
10338-{
10339- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
10340- sp -= get_random_int() & ~PAGE_MASK;
10341- return sp & ~0xf;
10342-}
10343-
10344-static inline unsigned long brk_rnd(void)
10345-{
10346- /* 8MB for 32bit, 1GB for 64bit */
10347- if (is_32bit_task())
10348- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
10349- else
10350- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
10351-}
10352-
10353-unsigned long arch_randomize_brk(struct mm_struct *mm)
10354-{
10355- unsigned long ret;
10356-
10357- ret = PAGE_ALIGN(mm->brk + brk_rnd());
10358- return (ret > mm->brk) ? ret : mm->brk;
10359-}
10360-
10361-unsigned long randomize_et_dyn(unsigned long base)
10362-{
10363- unsigned long ret;
10364-
10365- if (!(current->flags & PF_RANDOMIZE))
10366- return base;
10367- ret = PAGE_ALIGN(base + brk_rnd());
10368- return (ret > base) ? ret : base;
10369-}
10370diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
10371index 9b436c2..54fbf0a 100644
10372--- a/arch/s390/mm/mmap.c
10373+++ b/arch/s390/mm/mmap.c
10374@@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10375 */
10376 if (mmap_is_legacy()) {
10377 mm->mmap_base = mmap_base_legacy();
10378+
10379+#ifdef CONFIG_PAX_RANDMMAP
10380+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10381+ mm->mmap_base += mm->delta_mmap;
10382+#endif
10383+
10384 mm->get_unmapped_area = arch_get_unmapped_area;
10385 } else {
10386 mm->mmap_base = mmap_base();
10387+
10388+#ifdef CONFIG_PAX_RANDMMAP
10389+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10390+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10391+#endif
10392+
10393 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10394 }
10395 }
10396@@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10397 */
10398 if (mmap_is_legacy()) {
10399 mm->mmap_base = mmap_base_legacy();
10400+
10401+#ifdef CONFIG_PAX_RANDMMAP
10402+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10403+ mm->mmap_base += mm->delta_mmap;
10404+#endif
10405+
10406 mm->get_unmapped_area = s390_get_unmapped_area;
10407 } else {
10408 mm->mmap_base = mmap_base();
10409+
10410+#ifdef CONFIG_PAX_RANDMMAP
10411+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10412+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10413+#endif
10414+
10415 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
10416 }
10417 }
10418diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
10419index 61e45b7..f2833c5 100644
10420--- a/arch/s390/net/bpf_jit_comp.c
10421+++ b/arch/s390/net/bpf_jit_comp.c
10422@@ -887,5 +887,5 @@ void bpf_jit_free(struct bpf_prog *fp)
10423 module_free(NULL, header);
10424
10425 free_filter:
10426- kfree(fp);
10427+ bpf_prog_unlock_free(fp);
10428 }
10429diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
10430index ae3d59f..f65f075 100644
10431--- a/arch/score/include/asm/cache.h
10432+++ b/arch/score/include/asm/cache.h
10433@@ -1,7 +1,9 @@
10434 #ifndef _ASM_SCORE_CACHE_H
10435 #define _ASM_SCORE_CACHE_H
10436
10437+#include <linux/const.h>
10438+
10439 #define L1_CACHE_SHIFT 4
10440-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10441+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10442
10443 #endif /* _ASM_SCORE_CACHE_H */
10444diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
10445index f9f3cd5..58ff438 100644
10446--- a/arch/score/include/asm/exec.h
10447+++ b/arch/score/include/asm/exec.h
10448@@ -1,6 +1,6 @@
10449 #ifndef _ASM_SCORE_EXEC_H
10450 #define _ASM_SCORE_EXEC_H
10451
10452-extern unsigned long arch_align_stack(unsigned long sp);
10453+#define arch_align_stack(x) (x)
10454
10455 #endif /* _ASM_SCORE_EXEC_H */
10456diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
10457index a1519ad3..e8ac1ff 100644
10458--- a/arch/score/kernel/process.c
10459+++ b/arch/score/kernel/process.c
10460@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
10461
10462 return task_pt_regs(task)->cp0_epc;
10463 }
10464-
10465-unsigned long arch_align_stack(unsigned long sp)
10466-{
10467- return sp;
10468-}
10469diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
10470index ef9e555..331bd29 100644
10471--- a/arch/sh/include/asm/cache.h
10472+++ b/arch/sh/include/asm/cache.h
10473@@ -9,10 +9,11 @@
10474 #define __ASM_SH_CACHE_H
10475 #ifdef __KERNEL__
10476
10477+#include <linux/const.h>
10478 #include <linux/init.h>
10479 #include <cpu/cache.h>
10480
10481-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10482+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10483
10484 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10485
10486diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
10487index 6777177..cb5e44f 100644
10488--- a/arch/sh/mm/mmap.c
10489+++ b/arch/sh/mm/mmap.c
10490@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
10491 struct mm_struct *mm = current->mm;
10492 struct vm_area_struct *vma;
10493 int do_colour_align;
10494+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10495 struct vm_unmapped_area_info info;
10496
10497 if (flags & MAP_FIXED) {
10498@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
10499 if (filp || (flags & MAP_SHARED))
10500 do_colour_align = 1;
10501
10502+#ifdef CONFIG_PAX_RANDMMAP
10503+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10504+#endif
10505+
10506 if (addr) {
10507 if (do_colour_align)
10508 addr = COLOUR_ALIGN(addr, pgoff);
10509@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
10510 addr = PAGE_ALIGN(addr);
10511
10512 vma = find_vma(mm, addr);
10513- if (TASK_SIZE - len >= addr &&
10514- (!vma || addr + len <= vma->vm_start))
10515+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10516 return addr;
10517 }
10518
10519 info.flags = 0;
10520 info.length = len;
10521- info.low_limit = TASK_UNMAPPED_BASE;
10522+ info.low_limit = mm->mmap_base;
10523 info.high_limit = TASK_SIZE;
10524 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
10525 info.align_offset = pgoff << PAGE_SHIFT;
10526@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10527 struct mm_struct *mm = current->mm;
10528 unsigned long addr = addr0;
10529 int do_colour_align;
10530+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10531 struct vm_unmapped_area_info info;
10532
10533 if (flags & MAP_FIXED) {
10534@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10535 if (filp || (flags & MAP_SHARED))
10536 do_colour_align = 1;
10537
10538+#ifdef CONFIG_PAX_RANDMMAP
10539+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10540+#endif
10541+
10542 /* requesting a specific address */
10543 if (addr) {
10544 if (do_colour_align)
10545@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10546 addr = PAGE_ALIGN(addr);
10547
10548 vma = find_vma(mm, addr);
10549- if (TASK_SIZE - len >= addr &&
10550- (!vma || addr + len <= vma->vm_start))
10551+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10552 return addr;
10553 }
10554
10555@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10556 VM_BUG_ON(addr != -ENOMEM);
10557 info.flags = 0;
10558 info.low_limit = TASK_UNMAPPED_BASE;
10559+
10560+#ifdef CONFIG_PAX_RANDMMAP
10561+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10562+ info.low_limit += mm->delta_mmap;
10563+#endif
10564+
10565 info.high_limit = TASK_SIZE;
10566 addr = vm_unmapped_area(&info);
10567 }
10568diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
10569index bb894c8..81b82e9 100644
10570--- a/arch/sparc/include/asm/atomic_64.h
10571+++ b/arch/sparc/include/asm/atomic_64.h
10572@@ -15,18 +15,40 @@
10573 #define ATOMIC64_INIT(i) { (i) }
10574
10575 #define atomic_read(v) (*(volatile int *)&(v)->counter)
10576+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
10577+{
10578+ return *(const volatile int *)&v->counter;
10579+}
10580 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
10581+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
10582+{
10583+ return *(const volatile long *)&v->counter;
10584+}
10585
10586 #define atomic_set(v, i) (((v)->counter) = i)
10587+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
10588+{
10589+ v->counter = i;
10590+}
10591 #define atomic64_set(v, i) (((v)->counter) = i)
10592+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
10593+{
10594+ v->counter = i;
10595+}
10596
10597 void atomic_add(int, atomic_t *);
10598+void atomic_add_unchecked(int, atomic_unchecked_t *);
10599 void atomic64_add(long, atomic64_t *);
10600+void atomic64_add_unchecked(long, atomic64_unchecked_t *);
10601 void atomic_sub(int, atomic_t *);
10602+void atomic_sub_unchecked(int, atomic_unchecked_t *);
10603 void atomic64_sub(long, atomic64_t *);
10604+void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
10605
10606 int atomic_add_ret(int, atomic_t *);
10607+int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
10608 long atomic64_add_ret(long, atomic64_t *);
10609+long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
10610 int atomic_sub_ret(int, atomic_t *);
10611 long atomic64_sub_ret(long, atomic64_t *);
10612
10613@@ -34,13 +56,29 @@ long atomic64_sub_ret(long, atomic64_t *);
10614 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
10615
10616 #define atomic_inc_return(v) atomic_add_ret(1, v)
10617+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
10618+{
10619+ return atomic_add_ret_unchecked(1, v);
10620+}
10621 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
10622+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10623+{
10624+ return atomic64_add_ret_unchecked(1, v);
10625+}
10626
10627 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
10628 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
10629
10630 #define atomic_add_return(i, v) atomic_add_ret(i, v)
10631+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
10632+{
10633+ return atomic_add_ret_unchecked(i, v);
10634+}
10635 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
10636+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10637+{
10638+ return atomic64_add_ret_unchecked(i, v);
10639+}
10640
10641 /*
10642 * atomic_inc_and_test - increment and test
10643@@ -51,6 +89,10 @@ long atomic64_sub_ret(long, atomic64_t *);
10644 * other cases.
10645 */
10646 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
10647+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
10648+{
10649+ return atomic_inc_return_unchecked(v) == 0;
10650+}
10651 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
10652
10653 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
10654@@ -60,25 +102,60 @@ long atomic64_sub_ret(long, atomic64_t *);
10655 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
10656
10657 #define atomic_inc(v) atomic_add(1, v)
10658+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
10659+{
10660+ atomic_add_unchecked(1, v);
10661+}
10662 #define atomic64_inc(v) atomic64_add(1, v)
10663+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
10664+{
10665+ atomic64_add_unchecked(1, v);
10666+}
10667
10668 #define atomic_dec(v) atomic_sub(1, v)
10669+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10670+{
10671+ atomic_sub_unchecked(1, v);
10672+}
10673 #define atomic64_dec(v) atomic64_sub(1, v)
10674+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
10675+{
10676+ atomic64_sub_unchecked(1, v);
10677+}
10678
10679 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
10680 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
10681
10682 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
10683+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10684+{
10685+ return cmpxchg(&v->counter, old, new);
10686+}
10687 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
10688+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10689+{
10690+ return xchg(&v->counter, new);
10691+}
10692
10693 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10694 {
10695- int c, old;
10696+ int c, old, new;
10697 c = atomic_read(v);
10698 for (;;) {
10699- if (unlikely(c == (u)))
10700+ if (unlikely(c == u))
10701 break;
10702- old = atomic_cmpxchg((v), c, c + (a));
10703+
10704+ asm volatile("addcc %2, %0, %0\n"
10705+
10706+#ifdef CONFIG_PAX_REFCOUNT
10707+ "tvs %%icc, 6\n"
10708+#endif
10709+
10710+ : "=r" (new)
10711+ : "0" (c), "ir" (a)
10712+ : "cc");
10713+
10714+ old = atomic_cmpxchg(v, c, new);
10715 if (likely(old == c))
10716 break;
10717 c = old;
10718@@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10719 #define atomic64_cmpxchg(v, o, n) \
10720 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
10721 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
10722+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
10723+{
10724+ return xchg(&v->counter, new);
10725+}
10726
10727 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10728 {
10729- long c, old;
10730+ long c, old, new;
10731 c = atomic64_read(v);
10732 for (;;) {
10733- if (unlikely(c == (u)))
10734+ if (unlikely(c == u))
10735 break;
10736- old = atomic64_cmpxchg((v), c, c + (a));
10737+
10738+ asm volatile("addcc %2, %0, %0\n"
10739+
10740+#ifdef CONFIG_PAX_REFCOUNT
10741+ "tvs %%xcc, 6\n"
10742+#endif
10743+
10744+ : "=r" (new)
10745+ : "0" (c), "ir" (a)
10746+ : "cc");
10747+
10748+ old = atomic64_cmpxchg(v, c, new);
10749 if (likely(old == c))
10750 break;
10751 c = old;
10752 }
10753- return c != (u);
10754+ return c != u;
10755 }
10756
10757 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10758diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
10759index 305dcc3..7835030 100644
10760--- a/arch/sparc/include/asm/barrier_64.h
10761+++ b/arch/sparc/include/asm/barrier_64.h
10762@@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
10763 do { \
10764 compiletime_assert_atomic_type(*p); \
10765 barrier(); \
10766- ACCESS_ONCE(*p) = (v); \
10767+ ACCESS_ONCE_RW(*p) = (v); \
10768 } while (0)
10769
10770 #define smp_load_acquire(p) \
10771diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
10772index 5bb6991..5c2132e 100644
10773--- a/arch/sparc/include/asm/cache.h
10774+++ b/arch/sparc/include/asm/cache.h
10775@@ -7,10 +7,12 @@
10776 #ifndef _SPARC_CACHE_H
10777 #define _SPARC_CACHE_H
10778
10779+#include <linux/const.h>
10780+
10781 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
10782
10783 #define L1_CACHE_SHIFT 5
10784-#define L1_CACHE_BYTES 32
10785+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10786
10787 #ifdef CONFIG_SPARC32
10788 #define SMP_CACHE_BYTES_SHIFT 5
10789diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
10790index a24e41f..47677ff 100644
10791--- a/arch/sparc/include/asm/elf_32.h
10792+++ b/arch/sparc/include/asm/elf_32.h
10793@@ -114,6 +114,13 @@ typedef struct {
10794
10795 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
10796
10797+#ifdef CONFIG_PAX_ASLR
10798+#define PAX_ELF_ET_DYN_BASE 0x10000UL
10799+
10800+#define PAX_DELTA_MMAP_LEN 16
10801+#define PAX_DELTA_STACK_LEN 16
10802+#endif
10803+
10804 /* This yields a mask that user programs can use to figure out what
10805 instruction set this cpu supports. This can NOT be done in userspace
10806 on Sparc. */
10807diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
10808index 370ca1e..d4f4a98 100644
10809--- a/arch/sparc/include/asm/elf_64.h
10810+++ b/arch/sparc/include/asm/elf_64.h
10811@@ -189,6 +189,13 @@ typedef struct {
10812 #define ELF_ET_DYN_BASE 0x0000010000000000UL
10813 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
10814
10815+#ifdef CONFIG_PAX_ASLR
10816+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
10817+
10818+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
10819+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
10820+#endif
10821+
10822 extern unsigned long sparc64_elf_hwcap;
10823 #define ELF_HWCAP sparc64_elf_hwcap
10824
10825diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
10826index a3890da..f6a408e 100644
10827--- a/arch/sparc/include/asm/pgalloc_32.h
10828+++ b/arch/sparc/include/asm/pgalloc_32.h
10829@@ -35,6 +35,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
10830 }
10831
10832 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
10833+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10834
10835 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
10836 unsigned long address)
10837diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
10838index 5e31871..13469c6 100644
10839--- a/arch/sparc/include/asm/pgalloc_64.h
10840+++ b/arch/sparc/include/asm/pgalloc_64.h
10841@@ -21,6 +21,7 @@ static inline void __pgd_populate(pgd_t *pgd, pud_t *pud)
10842 }
10843
10844 #define pgd_populate(MM, PGD, PUD) __pgd_populate(PGD, PUD)
10845+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10846
10847 static inline pgd_t *pgd_alloc(struct mm_struct *mm)
10848 {
10849@@ -38,6 +39,7 @@ static inline void __pud_populate(pud_t *pud, pmd_t *pmd)
10850 }
10851
10852 #define pud_populate(MM, PUD, PMD) __pud_populate(PUD, PMD)
10853+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
10854
10855 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
10856 {
10857diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
10858index 59ba6f6..4518128 100644
10859--- a/arch/sparc/include/asm/pgtable.h
10860+++ b/arch/sparc/include/asm/pgtable.h
10861@@ -5,4 +5,8 @@
10862 #else
10863 #include <asm/pgtable_32.h>
10864 #endif
10865+
10866+#define ktla_ktva(addr) (addr)
10867+#define ktva_ktla(addr) (addr)
10868+
10869 #endif
10870diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
10871index b9b91ae..950b91e 100644
10872--- a/arch/sparc/include/asm/pgtable_32.h
10873+++ b/arch/sparc/include/asm/pgtable_32.h
10874@@ -51,6 +51,9 @@ unsigned long __init bootmem_init(unsigned long *pages_avail);
10875 #define PAGE_SHARED SRMMU_PAGE_SHARED
10876 #define PAGE_COPY SRMMU_PAGE_COPY
10877 #define PAGE_READONLY SRMMU_PAGE_RDONLY
10878+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
10879+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
10880+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
10881 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
10882
10883 /* Top-level page directory - dummy used by init-mm.
10884@@ -63,18 +66,18 @@ extern unsigned long ptr_in_current_pgd;
10885
10886 /* xwr */
10887 #define __P000 PAGE_NONE
10888-#define __P001 PAGE_READONLY
10889-#define __P010 PAGE_COPY
10890-#define __P011 PAGE_COPY
10891+#define __P001 PAGE_READONLY_NOEXEC
10892+#define __P010 PAGE_COPY_NOEXEC
10893+#define __P011 PAGE_COPY_NOEXEC
10894 #define __P100 PAGE_READONLY
10895 #define __P101 PAGE_READONLY
10896 #define __P110 PAGE_COPY
10897 #define __P111 PAGE_COPY
10898
10899 #define __S000 PAGE_NONE
10900-#define __S001 PAGE_READONLY
10901-#define __S010 PAGE_SHARED
10902-#define __S011 PAGE_SHARED
10903+#define __S001 PAGE_READONLY_NOEXEC
10904+#define __S010 PAGE_SHARED_NOEXEC
10905+#define __S011 PAGE_SHARED_NOEXEC
10906 #define __S100 PAGE_READONLY
10907 #define __S101 PAGE_READONLY
10908 #define __S110 PAGE_SHARED
10909diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
10910index 79da178..c2eede8 100644
10911--- a/arch/sparc/include/asm/pgtsrmmu.h
10912+++ b/arch/sparc/include/asm/pgtsrmmu.h
10913@@ -115,6 +115,11 @@
10914 SRMMU_EXEC | SRMMU_REF)
10915 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
10916 SRMMU_EXEC | SRMMU_REF)
10917+
10918+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
10919+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10920+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10921+
10922 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
10923 SRMMU_DIRTY | SRMMU_REF)
10924
10925diff --git a/arch/sparc/include/asm/setup.h b/arch/sparc/include/asm/setup.h
10926index 29d64b1..4272fe8 100644
10927--- a/arch/sparc/include/asm/setup.h
10928+++ b/arch/sparc/include/asm/setup.h
10929@@ -55,8 +55,8 @@ int handle_ldf_stq(u32 insn, struct pt_regs *regs);
10930 void handle_ld_nf(u32 insn, struct pt_regs *regs);
10931
10932 /* init_64.c */
10933-extern atomic_t dcpage_flushes;
10934-extern atomic_t dcpage_flushes_xcall;
10935+extern atomic_unchecked_t dcpage_flushes;
10936+extern atomic_unchecked_t dcpage_flushes_xcall;
10937
10938 extern int sysctl_tsb_ratio;
10939 #endif
10940diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
10941index 9689176..63c18ea 100644
10942--- a/arch/sparc/include/asm/spinlock_64.h
10943+++ b/arch/sparc/include/asm/spinlock_64.h
10944@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
10945
10946 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
10947
10948-static void inline arch_read_lock(arch_rwlock_t *lock)
10949+static inline void arch_read_lock(arch_rwlock_t *lock)
10950 {
10951 unsigned long tmp1, tmp2;
10952
10953 __asm__ __volatile__ (
10954 "1: ldsw [%2], %0\n"
10955 " brlz,pn %0, 2f\n"
10956-"4: add %0, 1, %1\n"
10957+"4: addcc %0, 1, %1\n"
10958+
10959+#ifdef CONFIG_PAX_REFCOUNT
10960+" tvs %%icc, 6\n"
10961+#endif
10962+
10963 " cas [%2], %0, %1\n"
10964 " cmp %0, %1\n"
10965 " bne,pn %%icc, 1b\n"
10966@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
10967 " .previous"
10968 : "=&r" (tmp1), "=&r" (tmp2)
10969 : "r" (lock)
10970- : "memory");
10971+ : "memory", "cc");
10972 }
10973
10974-static int inline arch_read_trylock(arch_rwlock_t *lock)
10975+static inline int arch_read_trylock(arch_rwlock_t *lock)
10976 {
10977 int tmp1, tmp2;
10978
10979@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10980 "1: ldsw [%2], %0\n"
10981 " brlz,a,pn %0, 2f\n"
10982 " mov 0, %0\n"
10983-" add %0, 1, %1\n"
10984+" addcc %0, 1, %1\n"
10985+
10986+#ifdef CONFIG_PAX_REFCOUNT
10987+" tvs %%icc, 6\n"
10988+#endif
10989+
10990 " cas [%2], %0, %1\n"
10991 " cmp %0, %1\n"
10992 " bne,pn %%icc, 1b\n"
10993@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10994 return tmp1;
10995 }
10996
10997-static void inline arch_read_unlock(arch_rwlock_t *lock)
10998+static inline void arch_read_unlock(arch_rwlock_t *lock)
10999 {
11000 unsigned long tmp1, tmp2;
11001
11002 __asm__ __volatile__(
11003 "1: lduw [%2], %0\n"
11004-" sub %0, 1, %1\n"
11005+" subcc %0, 1, %1\n"
11006+
11007+#ifdef CONFIG_PAX_REFCOUNT
11008+" tvs %%icc, 6\n"
11009+#endif
11010+
11011 " cas [%2], %0, %1\n"
11012 " cmp %0, %1\n"
11013 " bne,pn %%xcc, 1b\n"
11014@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
11015 : "memory");
11016 }
11017
11018-static void inline arch_write_lock(arch_rwlock_t *lock)
11019+static inline void arch_write_lock(arch_rwlock_t *lock)
11020 {
11021 unsigned long mask, tmp1, tmp2;
11022
11023@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
11024 : "memory");
11025 }
11026
11027-static void inline arch_write_unlock(arch_rwlock_t *lock)
11028+static inline void arch_write_unlock(arch_rwlock_t *lock)
11029 {
11030 __asm__ __volatile__(
11031 " stw %%g0, [%0]"
11032@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
11033 : "memory");
11034 }
11035
11036-static int inline arch_write_trylock(arch_rwlock_t *lock)
11037+static inline int arch_write_trylock(arch_rwlock_t *lock)
11038 {
11039 unsigned long mask, tmp1, tmp2, result;
11040
11041diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
11042index 96efa7a..16858bf 100644
11043--- a/arch/sparc/include/asm/thread_info_32.h
11044+++ b/arch/sparc/include/asm/thread_info_32.h
11045@@ -49,6 +49,8 @@ struct thread_info {
11046 unsigned long w_saved;
11047
11048 struct restart_block restart_block;
11049+
11050+ unsigned long lowest_stack;
11051 };
11052
11053 /*
11054diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
11055index cc6275c..7eb8e21 100644
11056--- a/arch/sparc/include/asm/thread_info_64.h
11057+++ b/arch/sparc/include/asm/thread_info_64.h
11058@@ -63,6 +63,8 @@ struct thread_info {
11059 struct pt_regs *kern_una_regs;
11060 unsigned int kern_una_insn;
11061
11062+ unsigned long lowest_stack;
11063+
11064 unsigned long fpregs[(7 * 256) / sizeof(unsigned long)]
11065 __attribute__ ((aligned(64)));
11066 };
11067@@ -190,12 +192,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
11068 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
11069 /* flag bit 4 is available */
11070 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
11071-/* flag bit 6 is available */
11072+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
11073 #define TIF_32BIT 7 /* 32-bit binary */
11074 #define TIF_NOHZ 8 /* in adaptive nohz mode */
11075 #define TIF_SECCOMP 9 /* secure computing */
11076 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
11077 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
11078+
11079 /* NOTE: Thread flags >= 12 should be ones we have no interest
11080 * in using in assembly, else we can't use the mask as
11081 * an immediate value in instructions such as andcc.
11082@@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
11083 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
11084 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
11085 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
11086+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
11087
11088 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
11089 _TIF_DO_NOTIFY_RESUME_MASK | \
11090 _TIF_NEED_RESCHED)
11091 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
11092
11093+#define _TIF_WORK_SYSCALL \
11094+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
11095+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
11096+
11097+
11098 /*
11099 * Thread-synchronous status.
11100 *
11101diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
11102index bd56c28..4b63d83 100644
11103--- a/arch/sparc/include/asm/uaccess.h
11104+++ b/arch/sparc/include/asm/uaccess.h
11105@@ -1,5 +1,6 @@
11106 #ifndef ___ASM_SPARC_UACCESS_H
11107 #define ___ASM_SPARC_UACCESS_H
11108+
11109 #if defined(__sparc__) && defined(__arch64__)
11110 #include <asm/uaccess_64.h>
11111 #else
11112diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
11113index 9634d08..f55fe4f 100644
11114--- a/arch/sparc/include/asm/uaccess_32.h
11115+++ b/arch/sparc/include/asm/uaccess_32.h
11116@@ -250,27 +250,46 @@ unsigned long __copy_user(void __user *to, const void __user *from, unsigned lon
11117
11118 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
11119 {
11120- if (n && __access_ok((unsigned long) to, n))
11121+ if ((long)n < 0)
11122+ return n;
11123+
11124+ if (n && __access_ok((unsigned long) to, n)) {
11125+ if (!__builtin_constant_p(n))
11126+ check_object_size(from, n, true);
11127 return __copy_user(to, (__force void __user *) from, n);
11128- else
11129+ } else
11130 return n;
11131 }
11132
11133 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
11134 {
11135+ if ((long)n < 0)
11136+ return n;
11137+
11138+ if (!__builtin_constant_p(n))
11139+ check_object_size(from, n, true);
11140+
11141 return __copy_user(to, (__force void __user *) from, n);
11142 }
11143
11144 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
11145 {
11146- if (n && __access_ok((unsigned long) from, n))
11147+ if ((long)n < 0)
11148+ return n;
11149+
11150+ if (n && __access_ok((unsigned long) from, n)) {
11151+ if (!__builtin_constant_p(n))
11152+ check_object_size(to, n, false);
11153 return __copy_user((__force void __user *) to, from, n);
11154- else
11155+ } else
11156 return n;
11157 }
11158
11159 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
11160 {
11161+ if ((long)n < 0)
11162+ return n;
11163+
11164 return __copy_user((__force void __user *) to, from, n);
11165 }
11166
11167diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
11168index c990a5e..f17b9c1 100644
11169--- a/arch/sparc/include/asm/uaccess_64.h
11170+++ b/arch/sparc/include/asm/uaccess_64.h
11171@@ -10,6 +10,7 @@
11172 #include <linux/compiler.h>
11173 #include <linux/string.h>
11174 #include <linux/thread_info.h>
11175+#include <linux/kernel.h>
11176 #include <asm/asi.h>
11177 #include <asm/spitfire.h>
11178 #include <asm-generic/uaccess-unaligned.h>
11179@@ -214,8 +215,15 @@ unsigned long copy_from_user_fixup(void *to, const void __user *from,
11180 static inline unsigned long __must_check
11181 copy_from_user(void *to, const void __user *from, unsigned long size)
11182 {
11183- unsigned long ret = ___copy_from_user(to, from, size);
11184+ unsigned long ret;
11185
11186+ if ((long)size < 0 || size > INT_MAX)
11187+ return size;
11188+
11189+ if (!__builtin_constant_p(size))
11190+ check_object_size(to, size, false);
11191+
11192+ ret = ___copy_from_user(to, from, size);
11193 if (unlikely(ret))
11194 ret = copy_from_user_fixup(to, from, size);
11195
11196@@ -231,8 +239,15 @@ unsigned long copy_to_user_fixup(void __user *to, const void *from,
11197 static inline unsigned long __must_check
11198 copy_to_user(void __user *to, const void *from, unsigned long size)
11199 {
11200- unsigned long ret = ___copy_to_user(to, from, size);
11201+ unsigned long ret;
11202
11203+ if ((long)size < 0 || size > INT_MAX)
11204+ return size;
11205+
11206+ if (!__builtin_constant_p(size))
11207+ check_object_size(from, size, true);
11208+
11209+ ret = ___copy_to_user(to, from, size);
11210 if (unlikely(ret))
11211 ret = copy_to_user_fixup(to, from, size);
11212 return ret;
11213diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
11214index 7cf9c6e..6206648 100644
11215--- a/arch/sparc/kernel/Makefile
11216+++ b/arch/sparc/kernel/Makefile
11217@@ -4,7 +4,7 @@
11218 #
11219
11220 asflags-y := -ansi
11221-ccflags-y := -Werror
11222+#ccflags-y := -Werror
11223
11224 extra-y := head_$(BITS).o
11225
11226diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
11227index 50e7b62..79fae35 100644
11228--- a/arch/sparc/kernel/process_32.c
11229+++ b/arch/sparc/kernel/process_32.c
11230@@ -123,14 +123,14 @@ void show_regs(struct pt_regs *r)
11231
11232 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
11233 r->psr, r->pc, r->npc, r->y, print_tainted());
11234- printk("PC: <%pS>\n", (void *) r->pc);
11235+ printk("PC: <%pA>\n", (void *) r->pc);
11236 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
11237 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
11238 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
11239 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
11240 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
11241 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
11242- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
11243+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
11244
11245 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
11246 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
11247@@ -167,7 +167,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11248 rw = (struct reg_window32 *) fp;
11249 pc = rw->ins[7];
11250 printk("[%08lx : ", pc);
11251- printk("%pS ] ", (void *) pc);
11252+ printk("%pA ] ", (void *) pc);
11253 fp = rw->ins[6];
11254 } while (++count < 16);
11255 printk("\n");
11256diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
11257index 0be7bf9..2b1cba8 100644
11258--- a/arch/sparc/kernel/process_64.c
11259+++ b/arch/sparc/kernel/process_64.c
11260@@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
11261 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
11262 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
11263 if (regs->tstate & TSTATE_PRIV)
11264- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
11265+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
11266 }
11267
11268 void show_regs(struct pt_regs *regs)
11269@@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
11270
11271 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
11272 regs->tpc, regs->tnpc, regs->y, print_tainted());
11273- printk("TPC: <%pS>\n", (void *) regs->tpc);
11274+ printk("TPC: <%pA>\n", (void *) regs->tpc);
11275 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
11276 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
11277 regs->u_regs[3]);
11278@@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
11279 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
11280 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
11281 regs->u_regs[15]);
11282- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
11283+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
11284 show_regwindow(regs);
11285 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
11286 }
11287@@ -278,7 +278,7 @@ void arch_trigger_all_cpu_backtrace(bool include_self)
11288 ((tp && tp->task) ? tp->task->pid : -1));
11289
11290 if (gp->tstate & TSTATE_PRIV) {
11291- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
11292+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
11293 (void *) gp->tpc,
11294 (void *) gp->o7,
11295 (void *) gp->i7,
11296diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
11297index 79cc0d1..ec62734 100644
11298--- a/arch/sparc/kernel/prom_common.c
11299+++ b/arch/sparc/kernel/prom_common.c
11300@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
11301
11302 unsigned int prom_early_allocated __initdata;
11303
11304-static struct of_pdt_ops prom_sparc_ops __initdata = {
11305+static struct of_pdt_ops prom_sparc_ops __initconst = {
11306 .nextprop = prom_common_nextprop,
11307 .getproplen = prom_getproplen,
11308 .getproperty = prom_getproperty,
11309diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
11310index c13c9f2..d572c34 100644
11311--- a/arch/sparc/kernel/ptrace_64.c
11312+++ b/arch/sparc/kernel/ptrace_64.c
11313@@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
11314 return ret;
11315 }
11316
11317+#ifdef CONFIG_GRKERNSEC_SETXID
11318+extern void gr_delayed_cred_worker(void);
11319+#endif
11320+
11321 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
11322 {
11323 int ret = 0;
11324@@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
11325 if (test_thread_flag(TIF_NOHZ))
11326 user_exit();
11327
11328+#ifdef CONFIG_GRKERNSEC_SETXID
11329+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
11330+ gr_delayed_cred_worker();
11331+#endif
11332+
11333 if (test_thread_flag(TIF_SYSCALL_TRACE))
11334 ret = tracehook_report_syscall_entry(regs);
11335
11336@@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
11337 if (test_thread_flag(TIF_NOHZ))
11338 user_exit();
11339
11340+#ifdef CONFIG_GRKERNSEC_SETXID
11341+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
11342+ gr_delayed_cred_worker();
11343+#endif
11344+
11345 audit_syscall_exit(regs);
11346
11347 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
11348diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
11349index 81954ee..6cfaa98 100644
11350--- a/arch/sparc/kernel/smp_64.c
11351+++ b/arch/sparc/kernel/smp_64.c
11352@@ -887,7 +887,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
11353 return;
11354
11355 #ifdef CONFIG_DEBUG_DCFLUSH
11356- atomic_inc(&dcpage_flushes);
11357+ atomic_inc_unchecked(&dcpage_flushes);
11358 #endif
11359
11360 this_cpu = get_cpu();
11361@@ -911,7 +911,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
11362 xcall_deliver(data0, __pa(pg_addr),
11363 (u64) pg_addr, cpumask_of(cpu));
11364 #ifdef CONFIG_DEBUG_DCFLUSH
11365- atomic_inc(&dcpage_flushes_xcall);
11366+ atomic_inc_unchecked(&dcpage_flushes_xcall);
11367 #endif
11368 }
11369 }
11370@@ -930,7 +930,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
11371 preempt_disable();
11372
11373 #ifdef CONFIG_DEBUG_DCFLUSH
11374- atomic_inc(&dcpage_flushes);
11375+ atomic_inc_unchecked(&dcpage_flushes);
11376 #endif
11377 data0 = 0;
11378 pg_addr = page_address(page);
11379@@ -947,7 +947,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
11380 xcall_deliver(data0, __pa(pg_addr),
11381 (u64) pg_addr, cpu_online_mask);
11382 #ifdef CONFIG_DEBUG_DCFLUSH
11383- atomic_inc(&dcpage_flushes_xcall);
11384+ atomic_inc_unchecked(&dcpage_flushes_xcall);
11385 #endif
11386 }
11387 __local_flush_dcache_page(page);
11388diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
11389index 646988d..b88905f 100644
11390--- a/arch/sparc/kernel/sys_sparc_32.c
11391+++ b/arch/sparc/kernel/sys_sparc_32.c
11392@@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
11393 if (len > TASK_SIZE - PAGE_SIZE)
11394 return -ENOMEM;
11395 if (!addr)
11396- addr = TASK_UNMAPPED_BASE;
11397+ addr = current->mm->mmap_base;
11398
11399 info.flags = 0;
11400 info.length = len;
11401diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
11402index c85403d..6af95c9 100644
11403--- a/arch/sparc/kernel/sys_sparc_64.c
11404+++ b/arch/sparc/kernel/sys_sparc_64.c
11405@@ -89,13 +89,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
11406 struct vm_area_struct * vma;
11407 unsigned long task_size = TASK_SIZE;
11408 int do_color_align;
11409+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
11410 struct vm_unmapped_area_info info;
11411
11412 if (flags & MAP_FIXED) {
11413 /* We do not accept a shared mapping if it would violate
11414 * cache aliasing constraints.
11415 */
11416- if ((flags & MAP_SHARED) &&
11417+ if ((filp || (flags & MAP_SHARED)) &&
11418 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
11419 return -EINVAL;
11420 return addr;
11421@@ -110,6 +111,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
11422 if (filp || (flags & MAP_SHARED))
11423 do_color_align = 1;
11424
11425+#ifdef CONFIG_PAX_RANDMMAP
11426+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11427+#endif
11428+
11429 if (addr) {
11430 if (do_color_align)
11431 addr = COLOR_ALIGN(addr, pgoff);
11432@@ -117,22 +122,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
11433 addr = PAGE_ALIGN(addr);
11434
11435 vma = find_vma(mm, addr);
11436- if (task_size - len >= addr &&
11437- (!vma || addr + len <= vma->vm_start))
11438+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11439 return addr;
11440 }
11441
11442 info.flags = 0;
11443 info.length = len;
11444- info.low_limit = TASK_UNMAPPED_BASE;
11445+ info.low_limit = mm->mmap_base;
11446 info.high_limit = min(task_size, VA_EXCLUDE_START);
11447 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
11448 info.align_offset = pgoff << PAGE_SHIFT;
11449+ info.threadstack_offset = offset;
11450 addr = vm_unmapped_area(&info);
11451
11452 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11453 VM_BUG_ON(addr != -ENOMEM);
11454 info.low_limit = VA_EXCLUDE_END;
11455+
11456+#ifdef CONFIG_PAX_RANDMMAP
11457+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11458+ info.low_limit += mm->delta_mmap;
11459+#endif
11460+
11461 info.high_limit = task_size;
11462 addr = vm_unmapped_area(&info);
11463 }
11464@@ -150,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11465 unsigned long task_size = STACK_TOP32;
11466 unsigned long addr = addr0;
11467 int do_color_align;
11468+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
11469 struct vm_unmapped_area_info info;
11470
11471 /* This should only ever run for 32-bit processes. */
11472@@ -159,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11473 /* We do not accept a shared mapping if it would violate
11474 * cache aliasing constraints.
11475 */
11476- if ((flags & MAP_SHARED) &&
11477+ if ((filp || (flags & MAP_SHARED)) &&
11478 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
11479 return -EINVAL;
11480 return addr;
11481@@ -172,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11482 if (filp || (flags & MAP_SHARED))
11483 do_color_align = 1;
11484
11485+#ifdef CONFIG_PAX_RANDMMAP
11486+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11487+#endif
11488+
11489 /* requesting a specific address */
11490 if (addr) {
11491 if (do_color_align)
11492@@ -180,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11493 addr = PAGE_ALIGN(addr);
11494
11495 vma = find_vma(mm, addr);
11496- if (task_size - len >= addr &&
11497- (!vma || addr + len <= vma->vm_start))
11498+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11499 return addr;
11500 }
11501
11502@@ -191,6 +206,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11503 info.high_limit = mm->mmap_base;
11504 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
11505 info.align_offset = pgoff << PAGE_SHIFT;
11506+ info.threadstack_offset = offset;
11507 addr = vm_unmapped_area(&info);
11508
11509 /*
11510@@ -203,6 +219,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11511 VM_BUG_ON(addr != -ENOMEM);
11512 info.flags = 0;
11513 info.low_limit = TASK_UNMAPPED_BASE;
11514+
11515+#ifdef CONFIG_PAX_RANDMMAP
11516+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11517+ info.low_limit += mm->delta_mmap;
11518+#endif
11519+
11520 info.high_limit = STACK_TOP32;
11521 addr = vm_unmapped_area(&info);
11522 }
11523@@ -259,10 +281,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
11524 EXPORT_SYMBOL(get_fb_unmapped_area);
11525
11526 /* Essentially the same as PowerPC. */
11527-static unsigned long mmap_rnd(void)
11528+static unsigned long mmap_rnd(struct mm_struct *mm)
11529 {
11530 unsigned long rnd = 0UL;
11531
11532+#ifdef CONFIG_PAX_RANDMMAP
11533+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11534+#endif
11535+
11536 if (current->flags & PF_RANDOMIZE) {
11537 unsigned long val = get_random_int();
11538 if (test_thread_flag(TIF_32BIT))
11539@@ -275,7 +301,7 @@ static unsigned long mmap_rnd(void)
11540
11541 void arch_pick_mmap_layout(struct mm_struct *mm)
11542 {
11543- unsigned long random_factor = mmap_rnd();
11544+ unsigned long random_factor = mmap_rnd(mm);
11545 unsigned long gap;
11546
11547 /*
11548@@ -288,6 +314,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
11549 gap == RLIM_INFINITY ||
11550 sysctl_legacy_va_layout) {
11551 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
11552+
11553+#ifdef CONFIG_PAX_RANDMMAP
11554+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11555+ mm->mmap_base += mm->delta_mmap;
11556+#endif
11557+
11558 mm->get_unmapped_area = arch_get_unmapped_area;
11559 } else {
11560 /* We know it's 32-bit */
11561@@ -299,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
11562 gap = (task_size / 6 * 5);
11563
11564 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
11565+
11566+#ifdef CONFIG_PAX_RANDMMAP
11567+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11568+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
11569+#endif
11570+
11571 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
11572 }
11573 }
11574diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
11575index 33a17e7..d87fb1f 100644
11576--- a/arch/sparc/kernel/syscalls.S
11577+++ b/arch/sparc/kernel/syscalls.S
11578@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
11579 #endif
11580 .align 32
11581 1: ldx [%g6 + TI_FLAGS], %l5
11582- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11583+ andcc %l5, _TIF_WORK_SYSCALL, %g0
11584 be,pt %icc, rtrap
11585 nop
11586 call syscall_trace_leave
11587@@ -184,7 +184,7 @@ linux_sparc_syscall32:
11588
11589 srl %i3, 0, %o3 ! IEU0
11590 srl %i2, 0, %o2 ! IEU0 Group
11591- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11592+ andcc %l0, _TIF_WORK_SYSCALL, %g0
11593 bne,pn %icc, linux_syscall_trace32 ! CTI
11594 mov %i0, %l5 ! IEU1
11595 5: call %l7 ! CTI Group brk forced
11596@@ -208,7 +208,7 @@ linux_sparc_syscall:
11597
11598 mov %i3, %o3 ! IEU1
11599 mov %i4, %o4 ! IEU0 Group
11600- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11601+ andcc %l0, _TIF_WORK_SYSCALL, %g0
11602 bne,pn %icc, linux_syscall_trace ! CTI Group
11603 mov %i0, %l5 ! IEU0
11604 2: call %l7 ! CTI Group brk forced
11605@@ -223,7 +223,7 @@ ret_sys_call:
11606
11607 cmp %o0, -ERESTART_RESTARTBLOCK
11608 bgeu,pn %xcc, 1f
11609- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11610+ andcc %l0, _TIF_WORK_SYSCALL, %g0
11611 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
11612
11613 2:
11614diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
11615index 6fd386c5..6907d81 100644
11616--- a/arch/sparc/kernel/traps_32.c
11617+++ b/arch/sparc/kernel/traps_32.c
11618@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
11619 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
11620 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
11621
11622+extern void gr_handle_kernel_exploit(void);
11623+
11624 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11625 {
11626 static int die_counter;
11627@@ -76,15 +78,17 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11628 count++ < 30 &&
11629 (((unsigned long) rw) >= PAGE_OFFSET) &&
11630 !(((unsigned long) rw) & 0x7)) {
11631- printk("Caller[%08lx]: %pS\n", rw->ins[7],
11632+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
11633 (void *) rw->ins[7]);
11634 rw = (struct reg_window32 *)rw->ins[6];
11635 }
11636 }
11637 printk("Instruction DUMP:");
11638 instruction_dump ((unsigned long *) regs->pc);
11639- if(regs->psr & PSR_PS)
11640+ if(regs->psr & PSR_PS) {
11641+ gr_handle_kernel_exploit();
11642 do_exit(SIGKILL);
11643+ }
11644 do_exit(SIGSEGV);
11645 }
11646
11647diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
11648index 981a769..d906eda 100644
11649--- a/arch/sparc/kernel/traps_64.c
11650+++ b/arch/sparc/kernel/traps_64.c
11651@@ -79,7 +79,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
11652 i + 1,
11653 p->trapstack[i].tstate, p->trapstack[i].tpc,
11654 p->trapstack[i].tnpc, p->trapstack[i].tt);
11655- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
11656+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
11657 }
11658 }
11659
11660@@ -99,6 +99,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
11661
11662 lvl -= 0x100;
11663 if (regs->tstate & TSTATE_PRIV) {
11664+
11665+#ifdef CONFIG_PAX_REFCOUNT
11666+ if (lvl == 6)
11667+ pax_report_refcount_overflow(regs);
11668+#endif
11669+
11670 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
11671 die_if_kernel(buffer, regs);
11672 }
11673@@ -117,11 +123,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
11674 void bad_trap_tl1(struct pt_regs *regs, long lvl)
11675 {
11676 char buffer[32];
11677-
11678+
11679 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
11680 0, lvl, SIGTRAP) == NOTIFY_STOP)
11681 return;
11682
11683+#ifdef CONFIG_PAX_REFCOUNT
11684+ if (lvl == 6)
11685+ pax_report_refcount_overflow(regs);
11686+#endif
11687+
11688 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
11689
11690 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
11691@@ -1151,7 +1162,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
11692 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
11693 printk("%s" "ERROR(%d): ",
11694 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
11695- printk("TPC<%pS>\n", (void *) regs->tpc);
11696+ printk("TPC<%pA>\n", (void *) regs->tpc);
11697 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
11698 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
11699 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
11700@@ -1758,7 +1769,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11701 smp_processor_id(),
11702 (type & 0x1) ? 'I' : 'D',
11703 regs->tpc);
11704- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
11705+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
11706 panic("Irrecoverable Cheetah+ parity error.");
11707 }
11708
11709@@ -1766,7 +1777,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11710 smp_processor_id(),
11711 (type & 0x1) ? 'I' : 'D',
11712 regs->tpc);
11713- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
11714+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
11715 }
11716
11717 struct sun4v_error_entry {
11718@@ -1839,8 +1850,8 @@ struct sun4v_error_entry {
11719 /*0x38*/u64 reserved_5;
11720 };
11721
11722-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11723-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11724+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11725+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11726
11727 static const char *sun4v_err_type_to_str(u8 type)
11728 {
11729@@ -1932,7 +1943,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
11730 }
11731
11732 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11733- int cpu, const char *pfx, atomic_t *ocnt)
11734+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
11735 {
11736 u64 *raw_ptr = (u64 *) ent;
11737 u32 attrs;
11738@@ -1990,8 +2001,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11739
11740 show_regs(regs);
11741
11742- if ((cnt = atomic_read(ocnt)) != 0) {
11743- atomic_set(ocnt, 0);
11744+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
11745+ atomic_set_unchecked(ocnt, 0);
11746 wmb();
11747 printk("%s: Queue overflowed %d times.\n",
11748 pfx, cnt);
11749@@ -2048,7 +2059,7 @@ out:
11750 */
11751 void sun4v_resum_overflow(struct pt_regs *regs)
11752 {
11753- atomic_inc(&sun4v_resum_oflow_cnt);
11754+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
11755 }
11756
11757 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
11758@@ -2101,7 +2112,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
11759 /* XXX Actually even this can make not that much sense. Perhaps
11760 * XXX we should just pull the plug and panic directly from here?
11761 */
11762- atomic_inc(&sun4v_nonresum_oflow_cnt);
11763+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
11764 }
11765
11766 static void sun4v_tlb_error(struct pt_regs *regs)
11767@@ -2120,9 +2131,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
11768
11769 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
11770 regs->tpc, tl);
11771- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
11772+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
11773 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11774- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
11775+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
11776 (void *) regs->u_regs[UREG_I7]);
11777 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
11778 "pte[%lx] error[%lx]\n",
11779@@ -2143,9 +2154,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
11780
11781 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
11782 regs->tpc, tl);
11783- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
11784+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
11785 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11786- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
11787+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
11788 (void *) regs->u_regs[UREG_I7]);
11789 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
11790 "pte[%lx] error[%lx]\n",
11791@@ -2362,13 +2373,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11792 fp = (unsigned long)sf->fp + STACK_BIAS;
11793 }
11794
11795- printk(" [%016lx] %pS\n", pc, (void *) pc);
11796+ printk(" [%016lx] %pA\n", pc, (void *) pc);
11797 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
11798 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
11799 int index = tsk->curr_ret_stack;
11800 if (tsk->ret_stack && index >= graph) {
11801 pc = tsk->ret_stack[index - graph].ret;
11802- printk(" [%016lx] %pS\n", pc, (void *) pc);
11803+ printk(" [%016lx] %pA\n", pc, (void *) pc);
11804 graph++;
11805 }
11806 }
11807@@ -2386,6 +2397,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
11808 return (struct reg_window *) (fp + STACK_BIAS);
11809 }
11810
11811+extern void gr_handle_kernel_exploit(void);
11812+
11813 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11814 {
11815 static int die_counter;
11816@@ -2414,7 +2427,7 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11817 while (rw &&
11818 count++ < 30 &&
11819 kstack_valid(tp, (unsigned long) rw)) {
11820- printk("Caller[%016lx]: %pS\n", rw->ins[7],
11821+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
11822 (void *) rw->ins[7]);
11823
11824 rw = kernel_stack_up(rw);
11825@@ -2427,8 +2440,10 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11826 }
11827 user_instruction_dump ((unsigned int __user *) regs->tpc);
11828 }
11829- if (regs->tstate & TSTATE_PRIV)
11830+ if (regs->tstate & TSTATE_PRIV) {
11831+ gr_handle_kernel_exploit();
11832 do_exit(SIGKILL);
11833+ }
11834 do_exit(SIGSEGV);
11835 }
11836 EXPORT_SYMBOL(die_if_kernel);
11837diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
11838index 62098a8..547ab2c 100644
11839--- a/arch/sparc/kernel/unaligned_64.c
11840+++ b/arch/sparc/kernel/unaligned_64.c
11841@@ -297,7 +297,7 @@ static void log_unaligned(struct pt_regs *regs)
11842 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
11843
11844 if (__ratelimit(&ratelimit)) {
11845- printk("Kernel unaligned access at TPC[%lx] %pS\n",
11846+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
11847 regs->tpc, (void *) regs->tpc);
11848 }
11849 }
11850diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
11851index 3269b02..64f5231 100644
11852--- a/arch/sparc/lib/Makefile
11853+++ b/arch/sparc/lib/Makefile
11854@@ -2,7 +2,7 @@
11855 #
11856
11857 asflags-y := -ansi -DST_DIV0=0x02
11858-ccflags-y := -Werror
11859+#ccflags-y := -Werror
11860
11861 lib-$(CONFIG_SPARC32) += ashrdi3.o
11862 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
11863diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
11864index 85c233d..68500e0 100644
11865--- a/arch/sparc/lib/atomic_64.S
11866+++ b/arch/sparc/lib/atomic_64.S
11867@@ -17,7 +17,12 @@
11868 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
11869 BACKOFF_SETUP(%o2)
11870 1: lduw [%o1], %g1
11871- add %g1, %o0, %g7
11872+ addcc %g1, %o0, %g7
11873+
11874+#ifdef CONFIG_PAX_REFCOUNT
11875+ tvs %icc, 6
11876+#endif
11877+
11878 cas [%o1], %g1, %g7
11879 cmp %g1, %g7
11880 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11881@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
11882 2: BACKOFF_SPIN(%o2, %o3, 1b)
11883 ENDPROC(atomic_add)
11884
11885+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11886+ BACKOFF_SETUP(%o2)
11887+1: lduw [%o1], %g1
11888+ add %g1, %o0, %g7
11889+ cas [%o1], %g1, %g7
11890+ cmp %g1, %g7
11891+ bne,pn %icc, 2f
11892+ nop
11893+ retl
11894+ nop
11895+2: BACKOFF_SPIN(%o2, %o3, 1b)
11896+ENDPROC(atomic_add_unchecked)
11897+
11898 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11899 BACKOFF_SETUP(%o2)
11900 1: lduw [%o1], %g1
11901- sub %g1, %o0, %g7
11902+ subcc %g1, %o0, %g7
11903+
11904+#ifdef CONFIG_PAX_REFCOUNT
11905+ tvs %icc, 6
11906+#endif
11907+
11908 cas [%o1], %g1, %g7
11909 cmp %g1, %g7
11910 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11911@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11912 2: BACKOFF_SPIN(%o2, %o3, 1b)
11913 ENDPROC(atomic_sub)
11914
11915+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11916+ BACKOFF_SETUP(%o2)
11917+1: lduw [%o1], %g1
11918+ sub %g1, %o0, %g7
11919+ cas [%o1], %g1, %g7
11920+ cmp %g1, %g7
11921+ bne,pn %icc, 2f
11922+ nop
11923+ retl
11924+ nop
11925+2: BACKOFF_SPIN(%o2, %o3, 1b)
11926+ENDPROC(atomic_sub_unchecked)
11927+
11928 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11929 BACKOFF_SETUP(%o2)
11930 1: lduw [%o1], %g1
11931- add %g1, %o0, %g7
11932+ addcc %g1, %o0, %g7
11933+
11934+#ifdef CONFIG_PAX_REFCOUNT
11935+ tvs %icc, 6
11936+#endif
11937+
11938 cas [%o1], %g1, %g7
11939 cmp %g1, %g7
11940 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11941@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11942 2: BACKOFF_SPIN(%o2, %o3, 1b)
11943 ENDPROC(atomic_add_ret)
11944
11945+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11946+ BACKOFF_SETUP(%o2)
11947+1: lduw [%o1], %g1
11948+ addcc %g1, %o0, %g7
11949+ cas [%o1], %g1, %g7
11950+ cmp %g1, %g7
11951+ bne,pn %icc, 2f
11952+ add %g7, %o0, %g7
11953+ sra %g7, 0, %o0
11954+ retl
11955+ nop
11956+2: BACKOFF_SPIN(%o2, %o3, 1b)
11957+ENDPROC(atomic_add_ret_unchecked)
11958+
11959 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11960 BACKOFF_SETUP(%o2)
11961 1: lduw [%o1], %g1
11962- sub %g1, %o0, %g7
11963+ subcc %g1, %o0, %g7
11964+
11965+#ifdef CONFIG_PAX_REFCOUNT
11966+ tvs %icc, 6
11967+#endif
11968+
11969 cas [%o1], %g1, %g7
11970 cmp %g1, %g7
11971 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11972@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
11973 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11974 BACKOFF_SETUP(%o2)
11975 1: ldx [%o1], %g1
11976- add %g1, %o0, %g7
11977+ addcc %g1, %o0, %g7
11978+
11979+#ifdef CONFIG_PAX_REFCOUNT
11980+ tvs %xcc, 6
11981+#endif
11982+
11983 casx [%o1], %g1, %g7
11984 cmp %g1, %g7
11985 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11986@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11987 2: BACKOFF_SPIN(%o2, %o3, 1b)
11988 ENDPROC(atomic64_add)
11989
11990+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11991+ BACKOFF_SETUP(%o2)
11992+1: ldx [%o1], %g1
11993+ addcc %g1, %o0, %g7
11994+ casx [%o1], %g1, %g7
11995+ cmp %g1, %g7
11996+ bne,pn %xcc, 2f
11997+ nop
11998+ retl
11999+ nop
12000+2: BACKOFF_SPIN(%o2, %o3, 1b)
12001+ENDPROC(atomic64_add_unchecked)
12002+
12003 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
12004 BACKOFF_SETUP(%o2)
12005 1: ldx [%o1], %g1
12006- sub %g1, %o0, %g7
12007+ subcc %g1, %o0, %g7
12008+
12009+#ifdef CONFIG_PAX_REFCOUNT
12010+ tvs %xcc, 6
12011+#endif
12012+
12013 casx [%o1], %g1, %g7
12014 cmp %g1, %g7
12015 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
12016@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
12017 2: BACKOFF_SPIN(%o2, %o3, 1b)
12018 ENDPROC(atomic64_sub)
12019
12020+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
12021+ BACKOFF_SETUP(%o2)
12022+1: ldx [%o1], %g1
12023+ subcc %g1, %o0, %g7
12024+ casx [%o1], %g1, %g7
12025+ cmp %g1, %g7
12026+ bne,pn %xcc, 2f
12027+ nop
12028+ retl
12029+ nop
12030+2: BACKOFF_SPIN(%o2, %o3, 1b)
12031+ENDPROC(atomic64_sub_unchecked)
12032+
12033 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
12034 BACKOFF_SETUP(%o2)
12035 1: ldx [%o1], %g1
12036- add %g1, %o0, %g7
12037+ addcc %g1, %o0, %g7
12038+
12039+#ifdef CONFIG_PAX_REFCOUNT
12040+ tvs %xcc, 6
12041+#endif
12042+
12043 casx [%o1], %g1, %g7
12044 cmp %g1, %g7
12045 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
12046@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
12047 2: BACKOFF_SPIN(%o2, %o3, 1b)
12048 ENDPROC(atomic64_add_ret)
12049
12050+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
12051+ BACKOFF_SETUP(%o2)
12052+1: ldx [%o1], %g1
12053+ addcc %g1, %o0, %g7
12054+ casx [%o1], %g1, %g7
12055+ cmp %g1, %g7
12056+ bne,pn %xcc, 2f
12057+ add %g7, %o0, %g7
12058+ mov %g7, %o0
12059+ retl
12060+ nop
12061+2: BACKOFF_SPIN(%o2, %o3, 1b)
12062+ENDPROC(atomic64_add_ret_unchecked)
12063+
12064 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
12065 BACKOFF_SETUP(%o2)
12066 1: ldx [%o1], %g1
12067- sub %g1, %o0, %g7
12068+ subcc %g1, %o0, %g7
12069+
12070+#ifdef CONFIG_PAX_REFCOUNT
12071+ tvs %xcc, 6
12072+#endif
12073+
12074 casx [%o1], %g1, %g7
12075 cmp %g1, %g7
12076 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
12077diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
12078index 323335b..ed85ea2 100644
12079--- a/arch/sparc/lib/ksyms.c
12080+++ b/arch/sparc/lib/ksyms.c
12081@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
12082
12083 /* Atomic counter implementation. */
12084 EXPORT_SYMBOL(atomic_add);
12085+EXPORT_SYMBOL(atomic_add_unchecked);
12086 EXPORT_SYMBOL(atomic_add_ret);
12087+EXPORT_SYMBOL(atomic_add_ret_unchecked);
12088 EXPORT_SYMBOL(atomic_sub);
12089+EXPORT_SYMBOL(atomic_sub_unchecked);
12090 EXPORT_SYMBOL(atomic_sub_ret);
12091 EXPORT_SYMBOL(atomic64_add);
12092+EXPORT_SYMBOL(atomic64_add_unchecked);
12093 EXPORT_SYMBOL(atomic64_add_ret);
12094+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
12095 EXPORT_SYMBOL(atomic64_sub);
12096+EXPORT_SYMBOL(atomic64_sub_unchecked);
12097 EXPORT_SYMBOL(atomic64_sub_ret);
12098 EXPORT_SYMBOL(atomic64_dec_if_positive);
12099
12100diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
12101index 30c3ecc..736f015 100644
12102--- a/arch/sparc/mm/Makefile
12103+++ b/arch/sparc/mm/Makefile
12104@@ -2,7 +2,7 @@
12105 #
12106
12107 asflags-y := -ansi
12108-ccflags-y := -Werror
12109+#ccflags-y := -Werror
12110
12111 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
12112 obj-y += fault_$(BITS).o
12113diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
12114index 908e8c1..1524793 100644
12115--- a/arch/sparc/mm/fault_32.c
12116+++ b/arch/sparc/mm/fault_32.c
12117@@ -21,6 +21,9 @@
12118 #include <linux/perf_event.h>
12119 #include <linux/interrupt.h>
12120 #include <linux/kdebug.h>
12121+#include <linux/slab.h>
12122+#include <linux/pagemap.h>
12123+#include <linux/compiler.h>
12124
12125 #include <asm/page.h>
12126 #include <asm/pgtable.h>
12127@@ -156,6 +159,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
12128 return safe_compute_effective_address(regs, insn);
12129 }
12130
12131+#ifdef CONFIG_PAX_PAGEEXEC
12132+#ifdef CONFIG_PAX_DLRESOLVE
12133+static void pax_emuplt_close(struct vm_area_struct *vma)
12134+{
12135+ vma->vm_mm->call_dl_resolve = 0UL;
12136+}
12137+
12138+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
12139+{
12140+ unsigned int *kaddr;
12141+
12142+ vmf->page = alloc_page(GFP_HIGHUSER);
12143+ if (!vmf->page)
12144+ return VM_FAULT_OOM;
12145+
12146+ kaddr = kmap(vmf->page);
12147+ memset(kaddr, 0, PAGE_SIZE);
12148+ kaddr[0] = 0x9DE3BFA8U; /* save */
12149+ flush_dcache_page(vmf->page);
12150+ kunmap(vmf->page);
12151+ return VM_FAULT_MAJOR;
12152+}
12153+
12154+static const struct vm_operations_struct pax_vm_ops = {
12155+ .close = pax_emuplt_close,
12156+ .fault = pax_emuplt_fault
12157+};
12158+
12159+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
12160+{
12161+ int ret;
12162+
12163+ INIT_LIST_HEAD(&vma->anon_vma_chain);
12164+ vma->vm_mm = current->mm;
12165+ vma->vm_start = addr;
12166+ vma->vm_end = addr + PAGE_SIZE;
12167+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
12168+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
12169+ vma->vm_ops = &pax_vm_ops;
12170+
12171+ ret = insert_vm_struct(current->mm, vma);
12172+ if (ret)
12173+ return ret;
12174+
12175+ ++current->mm->total_vm;
12176+ return 0;
12177+}
12178+#endif
12179+
12180+/*
12181+ * PaX: decide what to do with offenders (regs->pc = fault address)
12182+ *
12183+ * returns 1 when task should be killed
12184+ * 2 when patched PLT trampoline was detected
12185+ * 3 when unpatched PLT trampoline was detected
12186+ */
12187+static int pax_handle_fetch_fault(struct pt_regs *regs)
12188+{
12189+
12190+#ifdef CONFIG_PAX_EMUPLT
12191+ int err;
12192+
12193+ do { /* PaX: patched PLT emulation #1 */
12194+ unsigned int sethi1, sethi2, jmpl;
12195+
12196+ err = get_user(sethi1, (unsigned int *)regs->pc);
12197+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
12198+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
12199+
12200+ if (err)
12201+ break;
12202+
12203+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
12204+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
12205+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
12206+ {
12207+ unsigned int addr;
12208+
12209+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
12210+ addr = regs->u_regs[UREG_G1];
12211+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
12212+ regs->pc = addr;
12213+ regs->npc = addr+4;
12214+ return 2;
12215+ }
12216+ } while (0);
12217+
12218+ do { /* PaX: patched PLT emulation #2 */
12219+ unsigned int ba;
12220+
12221+ err = get_user(ba, (unsigned int *)regs->pc);
12222+
12223+ if (err)
12224+ break;
12225+
12226+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
12227+ unsigned int addr;
12228+
12229+ if ((ba & 0xFFC00000U) == 0x30800000U)
12230+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
12231+ else
12232+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
12233+ regs->pc = addr;
12234+ regs->npc = addr+4;
12235+ return 2;
12236+ }
12237+ } while (0);
12238+
12239+ do { /* PaX: patched PLT emulation #3 */
12240+ unsigned int sethi, bajmpl, nop;
12241+
12242+ err = get_user(sethi, (unsigned int *)regs->pc);
12243+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
12244+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
12245+
12246+ if (err)
12247+ break;
12248+
12249+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12250+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
12251+ nop == 0x01000000U)
12252+ {
12253+ unsigned int addr;
12254+
12255+ addr = (sethi & 0x003FFFFFU) << 10;
12256+ regs->u_regs[UREG_G1] = addr;
12257+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
12258+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
12259+ else
12260+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
12261+ regs->pc = addr;
12262+ regs->npc = addr+4;
12263+ return 2;
12264+ }
12265+ } while (0);
12266+
12267+ do { /* PaX: unpatched PLT emulation step 1 */
12268+ unsigned int sethi, ba, nop;
12269+
12270+ err = get_user(sethi, (unsigned int *)regs->pc);
12271+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
12272+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
12273+
12274+ if (err)
12275+ break;
12276+
12277+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12278+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
12279+ nop == 0x01000000U)
12280+ {
12281+ unsigned int addr, save, call;
12282+
12283+ if ((ba & 0xFFC00000U) == 0x30800000U)
12284+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
12285+ else
12286+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
12287+
12288+ err = get_user(save, (unsigned int *)addr);
12289+ err |= get_user(call, (unsigned int *)(addr+4));
12290+ err |= get_user(nop, (unsigned int *)(addr+8));
12291+ if (err)
12292+ break;
12293+
12294+#ifdef CONFIG_PAX_DLRESOLVE
12295+ if (save == 0x9DE3BFA8U &&
12296+ (call & 0xC0000000U) == 0x40000000U &&
12297+ nop == 0x01000000U)
12298+ {
12299+ struct vm_area_struct *vma;
12300+ unsigned long call_dl_resolve;
12301+
12302+ down_read(&current->mm->mmap_sem);
12303+ call_dl_resolve = current->mm->call_dl_resolve;
12304+ up_read(&current->mm->mmap_sem);
12305+ if (likely(call_dl_resolve))
12306+ goto emulate;
12307+
12308+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
12309+
12310+ down_write(&current->mm->mmap_sem);
12311+ if (current->mm->call_dl_resolve) {
12312+ call_dl_resolve = current->mm->call_dl_resolve;
12313+ up_write(&current->mm->mmap_sem);
12314+ if (vma)
12315+ kmem_cache_free(vm_area_cachep, vma);
12316+ goto emulate;
12317+ }
12318+
12319+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
12320+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
12321+ up_write(&current->mm->mmap_sem);
12322+ if (vma)
12323+ kmem_cache_free(vm_area_cachep, vma);
12324+ return 1;
12325+ }
12326+
12327+ if (pax_insert_vma(vma, call_dl_resolve)) {
12328+ up_write(&current->mm->mmap_sem);
12329+ kmem_cache_free(vm_area_cachep, vma);
12330+ return 1;
12331+ }
12332+
12333+ current->mm->call_dl_resolve = call_dl_resolve;
12334+ up_write(&current->mm->mmap_sem);
12335+
12336+emulate:
12337+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12338+ regs->pc = call_dl_resolve;
12339+ regs->npc = addr+4;
12340+ return 3;
12341+ }
12342+#endif
12343+
12344+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
12345+ if ((save & 0xFFC00000U) == 0x05000000U &&
12346+ (call & 0xFFFFE000U) == 0x85C0A000U &&
12347+ nop == 0x01000000U)
12348+ {
12349+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12350+ regs->u_regs[UREG_G2] = addr + 4;
12351+ addr = (save & 0x003FFFFFU) << 10;
12352+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
12353+ regs->pc = addr;
12354+ regs->npc = addr+4;
12355+ return 3;
12356+ }
12357+ }
12358+ } while (0);
12359+
12360+ do { /* PaX: unpatched PLT emulation step 2 */
12361+ unsigned int save, call, nop;
12362+
12363+ err = get_user(save, (unsigned int *)(regs->pc-4));
12364+ err |= get_user(call, (unsigned int *)regs->pc);
12365+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
12366+ if (err)
12367+ break;
12368+
12369+ if (save == 0x9DE3BFA8U &&
12370+ (call & 0xC0000000U) == 0x40000000U &&
12371+ nop == 0x01000000U)
12372+ {
12373+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
12374+
12375+ regs->u_regs[UREG_RETPC] = regs->pc;
12376+ regs->pc = dl_resolve;
12377+ regs->npc = dl_resolve+4;
12378+ return 3;
12379+ }
12380+ } while (0);
12381+#endif
12382+
12383+ return 1;
12384+}
12385+
12386+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12387+{
12388+ unsigned long i;
12389+
12390+ printk(KERN_ERR "PAX: bytes at PC: ");
12391+ for (i = 0; i < 8; i++) {
12392+ unsigned int c;
12393+ if (get_user(c, (unsigned int *)pc+i))
12394+ printk(KERN_CONT "???????? ");
12395+ else
12396+ printk(KERN_CONT "%08x ", c);
12397+ }
12398+ printk("\n");
12399+}
12400+#endif
12401+
12402 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
12403 int text_fault)
12404 {
12405@@ -226,6 +500,24 @@ good_area:
12406 if (!(vma->vm_flags & VM_WRITE))
12407 goto bad_area;
12408 } else {
12409+
12410+#ifdef CONFIG_PAX_PAGEEXEC
12411+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
12412+ up_read(&mm->mmap_sem);
12413+ switch (pax_handle_fetch_fault(regs)) {
12414+
12415+#ifdef CONFIG_PAX_EMUPLT
12416+ case 2:
12417+ case 3:
12418+ return;
12419+#endif
12420+
12421+ }
12422+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
12423+ do_group_exit(SIGKILL);
12424+ }
12425+#endif
12426+
12427 /* Allow reads even for write-only mappings */
12428 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
12429 goto bad_area;
12430diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
12431index 18fcd71..e4fe821 100644
12432--- a/arch/sparc/mm/fault_64.c
12433+++ b/arch/sparc/mm/fault_64.c
12434@@ -22,6 +22,9 @@
12435 #include <linux/kdebug.h>
12436 #include <linux/percpu.h>
12437 #include <linux/context_tracking.h>
12438+#include <linux/slab.h>
12439+#include <linux/pagemap.h>
12440+#include <linux/compiler.h>
12441
12442 #include <asm/page.h>
12443 #include <asm/pgtable.h>
12444@@ -76,7 +79,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
12445 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
12446 regs->tpc);
12447 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
12448- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
12449+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
12450 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
12451 dump_stack();
12452 unhandled_fault(regs->tpc, current, regs);
12453@@ -279,6 +282,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
12454 show_regs(regs);
12455 }
12456
12457+#ifdef CONFIG_PAX_PAGEEXEC
12458+#ifdef CONFIG_PAX_DLRESOLVE
12459+static void pax_emuplt_close(struct vm_area_struct *vma)
12460+{
12461+ vma->vm_mm->call_dl_resolve = 0UL;
12462+}
12463+
12464+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
12465+{
12466+ unsigned int *kaddr;
12467+
12468+ vmf->page = alloc_page(GFP_HIGHUSER);
12469+ if (!vmf->page)
12470+ return VM_FAULT_OOM;
12471+
12472+ kaddr = kmap(vmf->page);
12473+ memset(kaddr, 0, PAGE_SIZE);
12474+ kaddr[0] = 0x9DE3BFA8U; /* save */
12475+ flush_dcache_page(vmf->page);
12476+ kunmap(vmf->page);
12477+ return VM_FAULT_MAJOR;
12478+}
12479+
12480+static const struct vm_operations_struct pax_vm_ops = {
12481+ .close = pax_emuplt_close,
12482+ .fault = pax_emuplt_fault
12483+};
12484+
12485+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
12486+{
12487+ int ret;
12488+
12489+ INIT_LIST_HEAD(&vma->anon_vma_chain);
12490+ vma->vm_mm = current->mm;
12491+ vma->vm_start = addr;
12492+ vma->vm_end = addr + PAGE_SIZE;
12493+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
12494+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
12495+ vma->vm_ops = &pax_vm_ops;
12496+
12497+ ret = insert_vm_struct(current->mm, vma);
12498+ if (ret)
12499+ return ret;
12500+
12501+ ++current->mm->total_vm;
12502+ return 0;
12503+}
12504+#endif
12505+
12506+/*
12507+ * PaX: decide what to do with offenders (regs->tpc = fault address)
12508+ *
12509+ * returns 1 when task should be killed
12510+ * 2 when patched PLT trampoline was detected
12511+ * 3 when unpatched PLT trampoline was detected
12512+ */
12513+static int pax_handle_fetch_fault(struct pt_regs *regs)
12514+{
12515+
12516+#ifdef CONFIG_PAX_EMUPLT
12517+ int err;
12518+
12519+ do { /* PaX: patched PLT emulation #1 */
12520+ unsigned int sethi1, sethi2, jmpl;
12521+
12522+ err = get_user(sethi1, (unsigned int *)regs->tpc);
12523+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
12524+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
12525+
12526+ if (err)
12527+ break;
12528+
12529+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
12530+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
12531+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
12532+ {
12533+ unsigned long addr;
12534+
12535+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
12536+ addr = regs->u_regs[UREG_G1];
12537+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12538+
12539+ if (test_thread_flag(TIF_32BIT))
12540+ addr &= 0xFFFFFFFFUL;
12541+
12542+ regs->tpc = addr;
12543+ regs->tnpc = addr+4;
12544+ return 2;
12545+ }
12546+ } while (0);
12547+
12548+ do { /* PaX: patched PLT emulation #2 */
12549+ unsigned int ba;
12550+
12551+ err = get_user(ba, (unsigned int *)regs->tpc);
12552+
12553+ if (err)
12554+ break;
12555+
12556+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
12557+ unsigned long addr;
12558+
12559+ if ((ba & 0xFFC00000U) == 0x30800000U)
12560+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
12561+ else
12562+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12563+
12564+ if (test_thread_flag(TIF_32BIT))
12565+ addr &= 0xFFFFFFFFUL;
12566+
12567+ regs->tpc = addr;
12568+ regs->tnpc = addr+4;
12569+ return 2;
12570+ }
12571+ } while (0);
12572+
12573+ do { /* PaX: patched PLT emulation #3 */
12574+ unsigned int sethi, bajmpl, nop;
12575+
12576+ err = get_user(sethi, (unsigned int *)regs->tpc);
12577+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
12578+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12579+
12580+ if (err)
12581+ break;
12582+
12583+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12584+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
12585+ nop == 0x01000000U)
12586+ {
12587+ unsigned long addr;
12588+
12589+ addr = (sethi & 0x003FFFFFU) << 10;
12590+ regs->u_regs[UREG_G1] = addr;
12591+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
12592+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12593+ else
12594+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12595+
12596+ if (test_thread_flag(TIF_32BIT))
12597+ addr &= 0xFFFFFFFFUL;
12598+
12599+ regs->tpc = addr;
12600+ regs->tnpc = addr+4;
12601+ return 2;
12602+ }
12603+ } while (0);
12604+
12605+ do { /* PaX: patched PLT emulation #4 */
12606+ unsigned int sethi, mov1, call, mov2;
12607+
12608+ err = get_user(sethi, (unsigned int *)regs->tpc);
12609+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
12610+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
12611+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
12612+
12613+ if (err)
12614+ break;
12615+
12616+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12617+ mov1 == 0x8210000FU &&
12618+ (call & 0xC0000000U) == 0x40000000U &&
12619+ mov2 == 0x9E100001U)
12620+ {
12621+ unsigned long addr;
12622+
12623+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
12624+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12625+
12626+ if (test_thread_flag(TIF_32BIT))
12627+ addr &= 0xFFFFFFFFUL;
12628+
12629+ regs->tpc = addr;
12630+ regs->tnpc = addr+4;
12631+ return 2;
12632+ }
12633+ } while (0);
12634+
12635+ do { /* PaX: patched PLT emulation #5 */
12636+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
12637+
12638+ err = get_user(sethi, (unsigned int *)regs->tpc);
12639+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
12640+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
12641+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
12642+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
12643+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
12644+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
12645+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
12646+
12647+ if (err)
12648+ break;
12649+
12650+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12651+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
12652+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12653+ (or1 & 0xFFFFE000U) == 0x82106000U &&
12654+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
12655+ sllx == 0x83287020U &&
12656+ jmpl == 0x81C04005U &&
12657+ nop == 0x01000000U)
12658+ {
12659+ unsigned long addr;
12660+
12661+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12662+ regs->u_regs[UREG_G1] <<= 32;
12663+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12664+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
12665+ regs->tpc = addr;
12666+ regs->tnpc = addr+4;
12667+ return 2;
12668+ }
12669+ } while (0);
12670+
12671+ do { /* PaX: patched PLT emulation #6 */
12672+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
12673+
12674+ err = get_user(sethi, (unsigned int *)regs->tpc);
12675+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
12676+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
12677+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
12678+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
12679+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
12680+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
12681+
12682+ if (err)
12683+ break;
12684+
12685+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12686+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
12687+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12688+ sllx == 0x83287020U &&
12689+ (or & 0xFFFFE000U) == 0x8A116000U &&
12690+ jmpl == 0x81C04005U &&
12691+ nop == 0x01000000U)
12692+ {
12693+ unsigned long addr;
12694+
12695+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
12696+ regs->u_regs[UREG_G1] <<= 32;
12697+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
12698+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
12699+ regs->tpc = addr;
12700+ regs->tnpc = addr+4;
12701+ return 2;
12702+ }
12703+ } while (0);
12704+
12705+ do { /* PaX: unpatched PLT emulation step 1 */
12706+ unsigned int sethi, ba, nop;
12707+
12708+ err = get_user(sethi, (unsigned int *)regs->tpc);
12709+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12710+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12711+
12712+ if (err)
12713+ break;
12714+
12715+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12716+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
12717+ nop == 0x01000000U)
12718+ {
12719+ unsigned long addr;
12720+ unsigned int save, call;
12721+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
12722+
12723+ if ((ba & 0xFFC00000U) == 0x30800000U)
12724+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
12725+ else
12726+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12727+
12728+ if (test_thread_flag(TIF_32BIT))
12729+ addr &= 0xFFFFFFFFUL;
12730+
12731+ err = get_user(save, (unsigned int *)addr);
12732+ err |= get_user(call, (unsigned int *)(addr+4));
12733+ err |= get_user(nop, (unsigned int *)(addr+8));
12734+ if (err)
12735+ break;
12736+
12737+#ifdef CONFIG_PAX_DLRESOLVE
12738+ if (save == 0x9DE3BFA8U &&
12739+ (call & 0xC0000000U) == 0x40000000U &&
12740+ nop == 0x01000000U)
12741+ {
12742+ struct vm_area_struct *vma;
12743+ unsigned long call_dl_resolve;
12744+
12745+ down_read(&current->mm->mmap_sem);
12746+ call_dl_resolve = current->mm->call_dl_resolve;
12747+ up_read(&current->mm->mmap_sem);
12748+ if (likely(call_dl_resolve))
12749+ goto emulate;
12750+
12751+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
12752+
12753+ down_write(&current->mm->mmap_sem);
12754+ if (current->mm->call_dl_resolve) {
12755+ call_dl_resolve = current->mm->call_dl_resolve;
12756+ up_write(&current->mm->mmap_sem);
12757+ if (vma)
12758+ kmem_cache_free(vm_area_cachep, vma);
12759+ goto emulate;
12760+ }
12761+
12762+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
12763+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
12764+ up_write(&current->mm->mmap_sem);
12765+ if (vma)
12766+ kmem_cache_free(vm_area_cachep, vma);
12767+ return 1;
12768+ }
12769+
12770+ if (pax_insert_vma(vma, call_dl_resolve)) {
12771+ up_write(&current->mm->mmap_sem);
12772+ kmem_cache_free(vm_area_cachep, vma);
12773+ return 1;
12774+ }
12775+
12776+ current->mm->call_dl_resolve = call_dl_resolve;
12777+ up_write(&current->mm->mmap_sem);
12778+
12779+emulate:
12780+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12781+ regs->tpc = call_dl_resolve;
12782+ regs->tnpc = addr+4;
12783+ return 3;
12784+ }
12785+#endif
12786+
12787+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
12788+ if ((save & 0xFFC00000U) == 0x05000000U &&
12789+ (call & 0xFFFFE000U) == 0x85C0A000U &&
12790+ nop == 0x01000000U)
12791+ {
12792+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12793+ regs->u_regs[UREG_G2] = addr + 4;
12794+ addr = (save & 0x003FFFFFU) << 10;
12795+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12796+
12797+ if (test_thread_flag(TIF_32BIT))
12798+ addr &= 0xFFFFFFFFUL;
12799+
12800+ regs->tpc = addr;
12801+ regs->tnpc = addr+4;
12802+ return 3;
12803+ }
12804+
12805+ /* PaX: 64-bit PLT stub */
12806+ err = get_user(sethi1, (unsigned int *)addr);
12807+ err |= get_user(sethi2, (unsigned int *)(addr+4));
12808+ err |= get_user(or1, (unsigned int *)(addr+8));
12809+ err |= get_user(or2, (unsigned int *)(addr+12));
12810+ err |= get_user(sllx, (unsigned int *)(addr+16));
12811+ err |= get_user(add, (unsigned int *)(addr+20));
12812+ err |= get_user(jmpl, (unsigned int *)(addr+24));
12813+ err |= get_user(nop, (unsigned int *)(addr+28));
12814+ if (err)
12815+ break;
12816+
12817+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
12818+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12819+ (or1 & 0xFFFFE000U) == 0x88112000U &&
12820+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
12821+ sllx == 0x89293020U &&
12822+ add == 0x8A010005U &&
12823+ jmpl == 0x89C14000U &&
12824+ nop == 0x01000000U)
12825+ {
12826+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12827+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12828+ regs->u_regs[UREG_G4] <<= 32;
12829+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12830+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
12831+ regs->u_regs[UREG_G4] = addr + 24;
12832+ addr = regs->u_regs[UREG_G5];
12833+ regs->tpc = addr;
12834+ regs->tnpc = addr+4;
12835+ return 3;
12836+ }
12837+ }
12838+ } while (0);
12839+
12840+#ifdef CONFIG_PAX_DLRESOLVE
12841+ do { /* PaX: unpatched PLT emulation step 2 */
12842+ unsigned int save, call, nop;
12843+
12844+ err = get_user(save, (unsigned int *)(regs->tpc-4));
12845+ err |= get_user(call, (unsigned int *)regs->tpc);
12846+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
12847+ if (err)
12848+ break;
12849+
12850+ if (save == 0x9DE3BFA8U &&
12851+ (call & 0xC0000000U) == 0x40000000U &&
12852+ nop == 0x01000000U)
12853+ {
12854+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12855+
12856+ if (test_thread_flag(TIF_32BIT))
12857+ dl_resolve &= 0xFFFFFFFFUL;
12858+
12859+ regs->u_regs[UREG_RETPC] = regs->tpc;
12860+ regs->tpc = dl_resolve;
12861+ regs->tnpc = dl_resolve+4;
12862+ return 3;
12863+ }
12864+ } while (0);
12865+#endif
12866+
12867+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
12868+ unsigned int sethi, ba, nop;
12869+
12870+ err = get_user(sethi, (unsigned int *)regs->tpc);
12871+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12872+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12873+
12874+ if (err)
12875+ break;
12876+
12877+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12878+ (ba & 0xFFF00000U) == 0x30600000U &&
12879+ nop == 0x01000000U)
12880+ {
12881+ unsigned long addr;
12882+
12883+ addr = (sethi & 0x003FFFFFU) << 10;
12884+ regs->u_regs[UREG_G1] = addr;
12885+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12886+
12887+ if (test_thread_flag(TIF_32BIT))
12888+ addr &= 0xFFFFFFFFUL;
12889+
12890+ regs->tpc = addr;
12891+ regs->tnpc = addr+4;
12892+ return 2;
12893+ }
12894+ } while (0);
12895+
12896+#endif
12897+
12898+ return 1;
12899+}
12900+
12901+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12902+{
12903+ unsigned long i;
12904+
12905+ printk(KERN_ERR "PAX: bytes at PC: ");
12906+ for (i = 0; i < 8; i++) {
12907+ unsigned int c;
12908+ if (get_user(c, (unsigned int *)pc+i))
12909+ printk(KERN_CONT "???????? ");
12910+ else
12911+ printk(KERN_CONT "%08x ", c);
12912+ }
12913+ printk("\n");
12914+}
12915+#endif
12916+
12917 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
12918 {
12919 enum ctx_state prev_state = exception_enter();
12920@@ -353,6 +816,29 @@ retry:
12921 if (!vma)
12922 goto bad_area;
12923
12924+#ifdef CONFIG_PAX_PAGEEXEC
12925+ /* PaX: detect ITLB misses on non-exec pages */
12926+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
12927+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
12928+ {
12929+ if (address != regs->tpc)
12930+ goto good_area;
12931+
12932+ up_read(&mm->mmap_sem);
12933+ switch (pax_handle_fetch_fault(regs)) {
12934+
12935+#ifdef CONFIG_PAX_EMUPLT
12936+ case 2:
12937+ case 3:
12938+ return;
12939+#endif
12940+
12941+ }
12942+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
12943+ do_group_exit(SIGKILL);
12944+ }
12945+#endif
12946+
12947 /* Pure DTLB misses do not tell us whether the fault causing
12948 * load/store/atomic was a write or not, it only says that there
12949 * was no match. So in such a case we (carefully) read the
12950diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
12951index d329537..2c3746a 100644
12952--- a/arch/sparc/mm/hugetlbpage.c
12953+++ b/arch/sparc/mm/hugetlbpage.c
12954@@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12955 unsigned long addr,
12956 unsigned long len,
12957 unsigned long pgoff,
12958- unsigned long flags)
12959+ unsigned long flags,
12960+ unsigned long offset)
12961 {
12962+ struct mm_struct *mm = current->mm;
12963 unsigned long task_size = TASK_SIZE;
12964 struct vm_unmapped_area_info info;
12965
12966@@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12967
12968 info.flags = 0;
12969 info.length = len;
12970- info.low_limit = TASK_UNMAPPED_BASE;
12971+ info.low_limit = mm->mmap_base;
12972 info.high_limit = min(task_size, VA_EXCLUDE_START);
12973 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12974 info.align_offset = 0;
12975+ info.threadstack_offset = offset;
12976 addr = vm_unmapped_area(&info);
12977
12978 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
12979 VM_BUG_ON(addr != -ENOMEM);
12980 info.low_limit = VA_EXCLUDE_END;
12981+
12982+#ifdef CONFIG_PAX_RANDMMAP
12983+ if (mm->pax_flags & MF_PAX_RANDMMAP)
12984+ info.low_limit += mm->delta_mmap;
12985+#endif
12986+
12987 info.high_limit = task_size;
12988 addr = vm_unmapped_area(&info);
12989 }
12990@@ -55,7 +64,8 @@ static unsigned long
12991 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12992 const unsigned long len,
12993 const unsigned long pgoff,
12994- const unsigned long flags)
12995+ const unsigned long flags,
12996+ const unsigned long offset)
12997 {
12998 struct mm_struct *mm = current->mm;
12999 unsigned long addr = addr0;
13000@@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
13001 info.high_limit = mm->mmap_base;
13002 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
13003 info.align_offset = 0;
13004+ info.threadstack_offset = offset;
13005 addr = vm_unmapped_area(&info);
13006
13007 /*
13008@@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
13009 VM_BUG_ON(addr != -ENOMEM);
13010 info.flags = 0;
13011 info.low_limit = TASK_UNMAPPED_BASE;
13012+
13013+#ifdef CONFIG_PAX_RANDMMAP
13014+ if (mm->pax_flags & MF_PAX_RANDMMAP)
13015+ info.low_limit += mm->delta_mmap;
13016+#endif
13017+
13018 info.high_limit = STACK_TOP32;
13019 addr = vm_unmapped_area(&info);
13020 }
13021@@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
13022 struct mm_struct *mm = current->mm;
13023 struct vm_area_struct *vma;
13024 unsigned long task_size = TASK_SIZE;
13025+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
13026
13027 if (test_thread_flag(TIF_32BIT))
13028 task_size = STACK_TOP32;
13029@@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
13030 return addr;
13031 }
13032
13033+#ifdef CONFIG_PAX_RANDMMAP
13034+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
13035+#endif
13036+
13037 if (addr) {
13038 addr = ALIGN(addr, HPAGE_SIZE);
13039 vma = find_vma(mm, addr);
13040- if (task_size - len >= addr &&
13041- (!vma || addr + len <= vma->vm_start))
13042+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
13043 return addr;
13044 }
13045 if (mm->get_unmapped_area == arch_get_unmapped_area)
13046 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
13047- pgoff, flags);
13048+ pgoff, flags, offset);
13049 else
13050 return hugetlb_get_unmapped_area_topdown(file, addr, len,
13051- pgoff, flags);
13052+ pgoff, flags, offset);
13053 }
13054
13055 pte_t *huge_pte_alloc(struct mm_struct *mm,
13056diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
13057index 04bc826..0fefab9 100644
13058--- a/arch/sparc/mm/init_64.c
13059+++ b/arch/sparc/mm/init_64.c
13060@@ -186,9 +186,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
13061 int num_kernel_image_mappings;
13062
13063 #ifdef CONFIG_DEBUG_DCFLUSH
13064-atomic_t dcpage_flushes = ATOMIC_INIT(0);
13065+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
13066 #ifdef CONFIG_SMP
13067-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
13068+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
13069 #endif
13070 #endif
13071
13072@@ -196,7 +196,7 @@ inline void flush_dcache_page_impl(struct page *page)
13073 {
13074 BUG_ON(tlb_type == hypervisor);
13075 #ifdef CONFIG_DEBUG_DCFLUSH
13076- atomic_inc(&dcpage_flushes);
13077+ atomic_inc_unchecked(&dcpage_flushes);
13078 #endif
13079
13080 #ifdef DCACHE_ALIASING_POSSIBLE
13081@@ -468,10 +468,10 @@ void mmu_info(struct seq_file *m)
13082
13083 #ifdef CONFIG_DEBUG_DCFLUSH
13084 seq_printf(m, "DCPageFlushes\t: %d\n",
13085- atomic_read(&dcpage_flushes));
13086+ atomic_read_unchecked(&dcpage_flushes));
13087 #ifdef CONFIG_SMP
13088 seq_printf(m, "DCPageFlushesXC\t: %d\n",
13089- atomic_read(&dcpage_flushes_xcall));
13090+ atomic_read_unchecked(&dcpage_flushes_xcall));
13091 #endif /* CONFIG_SMP */
13092 #endif /* CONFIG_DEBUG_DCFLUSH */
13093 }
13094diff --git a/arch/sparc/net/bpf_jit_comp.c b/arch/sparc/net/bpf_jit_comp.c
13095index ece4af0..f04b862 100644
13096--- a/arch/sparc/net/bpf_jit_comp.c
13097+++ b/arch/sparc/net/bpf_jit_comp.c
13098@@ -823,5 +823,6 @@ void bpf_jit_free(struct bpf_prog *fp)
13099 {
13100 if (fp->jited)
13101 module_free(NULL, fp->bpf_func);
13102- kfree(fp);
13103+
13104+ bpf_prog_unlock_free(fp);
13105 }
13106diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
13107index 7fcd492..1311074 100644
13108--- a/arch/tile/Kconfig
13109+++ b/arch/tile/Kconfig
13110@@ -191,6 +191,7 @@ source "kernel/Kconfig.hz"
13111
13112 config KEXEC
13113 bool "kexec system call"
13114+ depends on !GRKERNSEC_KMEM
13115 ---help---
13116 kexec is a system call that implements the ability to shutdown your
13117 current kernel, and to start another kernel. It is like a reboot
13118diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
13119index 7b11c5f..755a026 100644
13120--- a/arch/tile/include/asm/atomic_64.h
13121+++ b/arch/tile/include/asm/atomic_64.h
13122@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
13123
13124 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
13125
13126+#define atomic64_read_unchecked(v) atomic64_read(v)
13127+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
13128+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
13129+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
13130+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
13131+#define atomic64_inc_unchecked(v) atomic64_inc(v)
13132+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
13133+#define atomic64_dec_unchecked(v) atomic64_dec(v)
13134+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
13135+
13136 /* Define this to indicate that cmpxchg is an efficient operation. */
13137 #define __HAVE_ARCH_CMPXCHG
13138
13139diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
13140index 6160761..00cac88 100644
13141--- a/arch/tile/include/asm/cache.h
13142+++ b/arch/tile/include/asm/cache.h
13143@@ -15,11 +15,12 @@
13144 #ifndef _ASM_TILE_CACHE_H
13145 #define _ASM_TILE_CACHE_H
13146
13147+#include <linux/const.h>
13148 #include <arch/chip.h>
13149
13150 /* bytes per L1 data cache line */
13151 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
13152-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
13153+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
13154
13155 /* bytes per L2 cache line */
13156 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
13157diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
13158index b6cde32..c0cb736 100644
13159--- a/arch/tile/include/asm/uaccess.h
13160+++ b/arch/tile/include/asm/uaccess.h
13161@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
13162 const void __user *from,
13163 unsigned long n)
13164 {
13165- int sz = __compiletime_object_size(to);
13166+ size_t sz = __compiletime_object_size(to);
13167
13168- if (likely(sz == -1 || sz >= n))
13169+ if (likely(sz == (size_t)-1 || sz >= n))
13170 n = _copy_from_user(to, from, n);
13171 else
13172 copy_from_user_overflow();
13173diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
13174index e514899..f8743c4 100644
13175--- a/arch/tile/mm/hugetlbpage.c
13176+++ b/arch/tile/mm/hugetlbpage.c
13177@@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
13178 info.high_limit = TASK_SIZE;
13179 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
13180 info.align_offset = 0;
13181+ info.threadstack_offset = 0;
13182 return vm_unmapped_area(&info);
13183 }
13184
13185@@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
13186 info.high_limit = current->mm->mmap_base;
13187 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
13188 info.align_offset = 0;
13189+ info.threadstack_offset = 0;
13190 addr = vm_unmapped_area(&info);
13191
13192 /*
13193diff --git a/arch/um/Makefile b/arch/um/Makefile
13194index e4b1a96..16162f8 100644
13195--- a/arch/um/Makefile
13196+++ b/arch/um/Makefile
13197@@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
13198 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
13199 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
13200
13201+ifdef CONSTIFY_PLUGIN
13202+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
13203+endif
13204+
13205 #This will adjust *FLAGS accordingly to the platform.
13206 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
13207
13208diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
13209index 19e1bdd..3665b77 100644
13210--- a/arch/um/include/asm/cache.h
13211+++ b/arch/um/include/asm/cache.h
13212@@ -1,6 +1,7 @@
13213 #ifndef __UM_CACHE_H
13214 #define __UM_CACHE_H
13215
13216+#include <linux/const.h>
13217
13218 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
13219 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
13220@@ -12,6 +13,6 @@
13221 # define L1_CACHE_SHIFT 5
13222 #endif
13223
13224-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
13225+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
13226
13227 #endif
13228diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
13229index 2e0a6b1..a64d0f5 100644
13230--- a/arch/um/include/asm/kmap_types.h
13231+++ b/arch/um/include/asm/kmap_types.h
13232@@ -8,6 +8,6 @@
13233
13234 /* No more #include "asm/arch/kmap_types.h" ! */
13235
13236-#define KM_TYPE_NR 14
13237+#define KM_TYPE_NR 15
13238
13239 #endif
13240diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
13241index 71c5d13..4c7b9f1 100644
13242--- a/arch/um/include/asm/page.h
13243+++ b/arch/um/include/asm/page.h
13244@@ -14,6 +14,9 @@
13245 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
13246 #define PAGE_MASK (~(PAGE_SIZE-1))
13247
13248+#define ktla_ktva(addr) (addr)
13249+#define ktva_ktla(addr) (addr)
13250+
13251 #ifndef __ASSEMBLY__
13252
13253 struct page;
13254diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
13255index 0032f92..cd151e0 100644
13256--- a/arch/um/include/asm/pgtable-3level.h
13257+++ b/arch/um/include/asm/pgtable-3level.h
13258@@ -58,6 +58,7 @@
13259 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
13260 #define pud_populate(mm, pud, pmd) \
13261 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
13262+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
13263
13264 #ifdef CONFIG_64BIT
13265 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
13266diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
13267index f17bca8..48adb87 100644
13268--- a/arch/um/kernel/process.c
13269+++ b/arch/um/kernel/process.c
13270@@ -356,22 +356,6 @@ int singlestepping(void * t)
13271 return 2;
13272 }
13273
13274-/*
13275- * Only x86 and x86_64 have an arch_align_stack().
13276- * All other arches have "#define arch_align_stack(x) (x)"
13277- * in their asm/exec.h
13278- * As this is included in UML from asm-um/system-generic.h,
13279- * we can use it to behave as the subarch does.
13280- */
13281-#ifndef arch_align_stack
13282-unsigned long arch_align_stack(unsigned long sp)
13283-{
13284- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
13285- sp -= get_random_int() % 8192;
13286- return sp & ~0xf;
13287-}
13288-#endif
13289-
13290 unsigned long get_wchan(struct task_struct *p)
13291 {
13292 unsigned long stack_page, sp, ip;
13293diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
13294index ad8f795..2c7eec6 100644
13295--- a/arch/unicore32/include/asm/cache.h
13296+++ b/arch/unicore32/include/asm/cache.h
13297@@ -12,8 +12,10 @@
13298 #ifndef __UNICORE_CACHE_H__
13299 #define __UNICORE_CACHE_H__
13300
13301-#define L1_CACHE_SHIFT (5)
13302-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
13303+#include <linux/const.h>
13304+
13305+#define L1_CACHE_SHIFT 5
13306+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
13307
13308 /*
13309 * Memory returned by kmalloc() may be used for DMA, so we must make
13310diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
13311index 3632743..630a8bb 100644
13312--- a/arch/x86/Kconfig
13313+++ b/arch/x86/Kconfig
13314@@ -130,7 +130,7 @@ config X86
13315 select RTC_LIB
13316 select HAVE_DEBUG_STACKOVERFLOW
13317 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
13318- select HAVE_CC_STACKPROTECTOR
13319+ select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
13320 select GENERIC_CPU_AUTOPROBE
13321 select HAVE_ARCH_AUDITSYSCALL
13322 select ARCH_SUPPORTS_ATOMIC_RMW
13323@@ -258,7 +258,7 @@ config X86_HT
13324
13325 config X86_32_LAZY_GS
13326 def_bool y
13327- depends on X86_32 && !CC_STACKPROTECTOR
13328+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
13329
13330 config ARCH_HWEIGHT_CFLAGS
13331 string
13332@@ -555,6 +555,7 @@ config SCHED_OMIT_FRAME_POINTER
13333
13334 menuconfig HYPERVISOR_GUEST
13335 bool "Linux guest support"
13336+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
13337 ---help---
13338 Say Y here to enable options for running Linux under various hyper-
13339 visors. This option enables basic hypervisor detection and platform
13340@@ -1083,6 +1084,7 @@ choice
13341
13342 config NOHIGHMEM
13343 bool "off"
13344+ depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
13345 ---help---
13346 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
13347 However, the address space of 32-bit x86 processors is only 4
13348@@ -1119,6 +1121,7 @@ config NOHIGHMEM
13349
13350 config HIGHMEM4G
13351 bool "4GB"
13352+ depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
13353 ---help---
13354 Select this if you have a 32-bit processor and between 1 and 4
13355 gigabytes of physical RAM.
13356@@ -1171,7 +1174,7 @@ config PAGE_OFFSET
13357 hex
13358 default 0xB0000000 if VMSPLIT_3G_OPT
13359 default 0x80000000 if VMSPLIT_2G
13360- default 0x78000000 if VMSPLIT_2G_OPT
13361+ default 0x70000000 if VMSPLIT_2G_OPT
13362 default 0x40000000 if VMSPLIT_1G
13363 default 0xC0000000
13364 depends on X86_32
13365@@ -1586,6 +1589,7 @@ source kernel/Kconfig.hz
13366
13367 config KEXEC
13368 bool "kexec system call"
13369+ depends on !GRKERNSEC_KMEM
13370 ---help---
13371 kexec is a system call that implements the ability to shutdown your
13372 current kernel, and to start another kernel. It is like a reboot
13373@@ -1771,7 +1775,9 @@ config X86_NEED_RELOCS
13374
13375 config PHYSICAL_ALIGN
13376 hex "Alignment value to which kernel should be aligned"
13377- default "0x200000"
13378+ default "0x1000000"
13379+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
13380+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
13381 range 0x2000 0x1000000 if X86_32
13382 range 0x200000 0x1000000 if X86_64
13383 ---help---
13384@@ -1854,6 +1860,7 @@ config COMPAT_VDSO
13385 def_bool n
13386 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
13387 depends on X86_32 || IA32_EMULATION
13388+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
13389 ---help---
13390 Certain buggy versions of glibc will crash if they are
13391 presented with a 32-bit vDSO that is not mapped at the address
13392diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
13393index 6983314..54ad7e8 100644
13394--- a/arch/x86/Kconfig.cpu
13395+++ b/arch/x86/Kconfig.cpu
13396@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
13397
13398 config X86_F00F_BUG
13399 def_bool y
13400- depends on M586MMX || M586TSC || M586 || M486
13401+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
13402
13403 config X86_INVD_BUG
13404 def_bool y
13405@@ -327,7 +327,7 @@ config X86_INVD_BUG
13406
13407 config X86_ALIGNMENT_16
13408 def_bool y
13409- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
13410+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
13411
13412 config X86_INTEL_USERCOPY
13413 def_bool y
13414@@ -369,7 +369,7 @@ config X86_CMPXCHG64
13415 # generates cmov.
13416 config X86_CMOV
13417 def_bool y
13418- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
13419+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
13420
13421 config X86_MINIMUM_CPU_FAMILY
13422 int
13423diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
13424index 61bd2ad..50b625d 100644
13425--- a/arch/x86/Kconfig.debug
13426+++ b/arch/x86/Kconfig.debug
13427@@ -93,7 +93,7 @@ config EFI_PGT_DUMP
13428 config DEBUG_RODATA
13429 bool "Write protect kernel read-only data structures"
13430 default y
13431- depends on DEBUG_KERNEL
13432+ depends on DEBUG_KERNEL && BROKEN
13433 ---help---
13434 Mark the kernel read-only data as write-protected in the pagetables,
13435 in order to catch accidental (and incorrect) writes to such const
13436@@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
13437
13438 config DEBUG_SET_MODULE_RONX
13439 bool "Set loadable kernel module data as NX and text as RO"
13440- depends on MODULES
13441+ depends on MODULES && BROKEN
13442 ---help---
13443 This option helps catch unintended modifications to loadable
13444 kernel module's text and read-only data. It also prevents execution
13445diff --git a/arch/x86/Makefile b/arch/x86/Makefile
13446index 60087ca..9d9500e 100644
13447--- a/arch/x86/Makefile
13448+++ b/arch/x86/Makefile
13449@@ -68,9 +68,6 @@ ifeq ($(CONFIG_X86_32),y)
13450 # CPU-specific tuning. Anything which can be shared with UML should go here.
13451 include $(srctree)/arch/x86/Makefile_32.cpu
13452 KBUILD_CFLAGS += $(cflags-y)
13453-
13454- # temporary until string.h is fixed
13455- KBUILD_CFLAGS += -ffreestanding
13456 else
13457 BITS := 64
13458 UTS_MACHINE := x86_64
13459@@ -111,6 +108,9 @@ else
13460 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
13461 endif
13462
13463+# temporary until string.h is fixed
13464+KBUILD_CFLAGS += -ffreestanding
13465+
13466 # Make sure compiler does not have buggy stack-protector support.
13467 ifdef CONFIG_CC_STACKPROTECTOR
13468 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
13469@@ -184,6 +184,7 @@ archheaders:
13470 $(Q)$(MAKE) $(build)=arch/x86/syscalls all
13471
13472 archprepare:
13473+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
13474 ifeq ($(CONFIG_KEXEC_FILE),y)
13475 $(Q)$(MAKE) $(build)=arch/x86/purgatory arch/x86/purgatory/kexec-purgatory.c
13476 endif
13477@@ -274,3 +275,9 @@ define archhelp
13478 echo ' FDINITRD=file initrd for the booted kernel'
13479 echo ' kvmconfig - Enable additional options for guest kernel support'
13480 endef
13481+
13482+define OLD_LD
13483+
13484+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
13485+*** Please upgrade your binutils to 2.18 or newer
13486+endef
13487diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
13488index dbe8dd2..2f0a98f 100644
13489--- a/arch/x86/boot/Makefile
13490+++ b/arch/x86/boot/Makefile
13491@@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
13492 # ---------------------------------------------------------------------------
13493
13494 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
13495+ifdef CONSTIFY_PLUGIN
13496+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
13497+endif
13498 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13499 GCOV_PROFILE := n
13500
13501diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
13502index 878e4b9..20537ab 100644
13503--- a/arch/x86/boot/bitops.h
13504+++ b/arch/x86/boot/bitops.h
13505@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
13506 u8 v;
13507 const u32 *p = (const u32 *)addr;
13508
13509- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
13510+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
13511 return v;
13512 }
13513
13514@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
13515
13516 static inline void set_bit(int nr, void *addr)
13517 {
13518- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
13519+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
13520 }
13521
13522 #endif /* BOOT_BITOPS_H */
13523diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
13524index bd49ec6..94c7f58 100644
13525--- a/arch/x86/boot/boot.h
13526+++ b/arch/x86/boot/boot.h
13527@@ -84,7 +84,7 @@ static inline void io_delay(void)
13528 static inline u16 ds(void)
13529 {
13530 u16 seg;
13531- asm("movw %%ds,%0" : "=rm" (seg));
13532+ asm volatile("movw %%ds,%0" : "=rm" (seg));
13533 return seg;
13534 }
13535
13536diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
13537index 14fe7cb..829b962 100644
13538--- a/arch/x86/boot/compressed/Makefile
13539+++ b/arch/x86/boot/compressed/Makefile
13540@@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
13541 KBUILD_CFLAGS += -mno-mmx -mno-sse
13542 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
13543 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
13544+ifdef CONSTIFY_PLUGIN
13545+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
13546+endif
13547
13548 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13549 GCOV_PROFILE := n
13550diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
13551index a53440e..c3dbf1e 100644
13552--- a/arch/x86/boot/compressed/efi_stub_32.S
13553+++ b/arch/x86/boot/compressed/efi_stub_32.S
13554@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
13555 * parameter 2, ..., param n. To make things easy, we save the return
13556 * address of efi_call_phys in a global variable.
13557 */
13558- popl %ecx
13559- movl %ecx, saved_return_addr(%edx)
13560- /* get the function pointer into ECX*/
13561- popl %ecx
13562- movl %ecx, efi_rt_function_ptr(%edx)
13563+ popl saved_return_addr(%edx)
13564+ popl efi_rt_function_ptr(%edx)
13565
13566 /*
13567 * 3. Call the physical function.
13568 */
13569- call *%ecx
13570+ call *efi_rt_function_ptr(%edx)
13571
13572 /*
13573 * 4. Balance the stack. And because EAX contain the return value,
13574@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
13575 1: popl %edx
13576 subl $1b, %edx
13577
13578- movl efi_rt_function_ptr(%edx), %ecx
13579- pushl %ecx
13580+ pushl efi_rt_function_ptr(%edx)
13581
13582 /*
13583 * 10. Push the saved return address onto the stack and return.
13584 */
13585- movl saved_return_addr(%edx), %ecx
13586- pushl %ecx
13587- ret
13588+ jmpl *saved_return_addr(%edx)
13589 ENDPROC(efi_call_phys)
13590 .previous
13591
13592diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
13593index 1d7fbbc..36ecd58 100644
13594--- a/arch/x86/boot/compressed/head_32.S
13595+++ b/arch/x86/boot/compressed/head_32.S
13596@@ -140,10 +140,10 @@ preferred_addr:
13597 addl %eax, %ebx
13598 notl %eax
13599 andl %eax, %ebx
13600- cmpl $LOAD_PHYSICAL_ADDR, %ebx
13601+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
13602 jge 1f
13603 #endif
13604- movl $LOAD_PHYSICAL_ADDR, %ebx
13605+ movl $____LOAD_PHYSICAL_ADDR, %ebx
13606 1:
13607
13608 /* Target address to relocate to for decompression */
13609diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
13610index 6b1766c..ad465c9 100644
13611--- a/arch/x86/boot/compressed/head_64.S
13612+++ b/arch/x86/boot/compressed/head_64.S
13613@@ -94,10 +94,10 @@ ENTRY(startup_32)
13614 addl %eax, %ebx
13615 notl %eax
13616 andl %eax, %ebx
13617- cmpl $LOAD_PHYSICAL_ADDR, %ebx
13618+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
13619 jge 1f
13620 #endif
13621- movl $LOAD_PHYSICAL_ADDR, %ebx
13622+ movl $____LOAD_PHYSICAL_ADDR, %ebx
13623 1:
13624
13625 /* Target address to relocate to for decompression */
13626@@ -322,10 +322,10 @@ preferred_addr:
13627 addq %rax, %rbp
13628 notq %rax
13629 andq %rax, %rbp
13630- cmpq $LOAD_PHYSICAL_ADDR, %rbp
13631+ cmpq $____LOAD_PHYSICAL_ADDR, %rbp
13632 jge 1f
13633 #endif
13634- movq $LOAD_PHYSICAL_ADDR, %rbp
13635+ movq $____LOAD_PHYSICAL_ADDR, %rbp
13636 1:
13637
13638 /* Target address to relocate to for decompression */
13639@@ -434,8 +434,8 @@ gdt:
13640 .long gdt
13641 .word 0
13642 .quad 0x0000000000000000 /* NULL descriptor */
13643- .quad 0x00af9a000000ffff /* __KERNEL_CS */
13644- .quad 0x00cf92000000ffff /* __KERNEL_DS */
13645+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
13646+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
13647 .quad 0x0080890000000000 /* TS descriptor */
13648 .quad 0x0000000000000000 /* TS continued */
13649 gdt_end:
13650diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
13651index 30dd59a..cd9edc3 100644
13652--- a/arch/x86/boot/compressed/misc.c
13653+++ b/arch/x86/boot/compressed/misc.c
13654@@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
13655 * Calculate the delta between where vmlinux was linked to load
13656 * and where it was actually loaded.
13657 */
13658- delta = min_addr - LOAD_PHYSICAL_ADDR;
13659+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
13660 if (!delta) {
13661 debug_putstr("No relocation needed... ");
13662 return;
13663@@ -312,7 +312,7 @@ static void parse_elf(void *output)
13664 Elf32_Ehdr ehdr;
13665 Elf32_Phdr *phdrs, *phdr;
13666 #endif
13667- void *dest;
13668+ void *dest, *prev;
13669 int i;
13670
13671 memcpy(&ehdr, output, sizeof(ehdr));
13672@@ -339,13 +339,16 @@ static void parse_elf(void *output)
13673 case PT_LOAD:
13674 #ifdef CONFIG_RELOCATABLE
13675 dest = output;
13676- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
13677+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
13678 #else
13679 dest = (void *)(phdr->p_paddr);
13680 #endif
13681 memcpy(dest,
13682 output + phdr->p_offset,
13683 phdr->p_filesz);
13684+ if (i)
13685+ memset(prev, 0xff, dest - prev);
13686+ prev = dest + phdr->p_filesz;
13687 break;
13688 default: /* Ignore other PT_* */ break;
13689 }
13690@@ -402,7 +405,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
13691 error("Destination address too large");
13692 #endif
13693 #ifndef CONFIG_RELOCATABLE
13694- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
13695+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
13696 error("Wrong destination address");
13697 #endif
13698
13699diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
13700index 1fd7d57..0f7d096 100644
13701--- a/arch/x86/boot/cpucheck.c
13702+++ b/arch/x86/boot/cpucheck.c
13703@@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13704 u32 ecx = MSR_K7_HWCR;
13705 u32 eax, edx;
13706
13707- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13708+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13709 eax &= ~(1 << 15);
13710- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13711+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13712
13713 get_cpuflags(); /* Make sure it really did something */
13714 err = check_cpuflags();
13715@@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13716 u32 ecx = MSR_VIA_FCR;
13717 u32 eax, edx;
13718
13719- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13720+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13721 eax |= (1<<1)|(1<<7);
13722- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13723+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13724
13725 set_bit(X86_FEATURE_CX8, cpu.flags);
13726 err = check_cpuflags();
13727@@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13728 u32 eax, edx;
13729 u32 level = 1;
13730
13731- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13732- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13733- asm("cpuid"
13734+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13735+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13736+ asm volatile("cpuid"
13737 : "+a" (level), "=d" (cpu.flags[0])
13738 : : "ecx", "ebx");
13739- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13740+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13741
13742 err = check_cpuflags();
13743 } else if (err == 0x01 &&
13744diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
13745index 16ef025..91e033b 100644
13746--- a/arch/x86/boot/header.S
13747+++ b/arch/x86/boot/header.S
13748@@ -438,10 +438,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
13749 # single linked list of
13750 # struct setup_data
13751
13752-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
13753+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
13754
13755 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
13756+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13757+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
13758+#else
13759 #define VO_INIT_SIZE (VO__end - VO__text)
13760+#endif
13761 #if ZO_INIT_SIZE > VO_INIT_SIZE
13762 #define INIT_SIZE ZO_INIT_SIZE
13763 #else
13764diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
13765index db75d07..8e6d0af 100644
13766--- a/arch/x86/boot/memory.c
13767+++ b/arch/x86/boot/memory.c
13768@@ -19,7 +19,7 @@
13769
13770 static int detect_memory_e820(void)
13771 {
13772- int count = 0;
13773+ unsigned int count = 0;
13774 struct biosregs ireg, oreg;
13775 struct e820entry *desc = boot_params.e820_map;
13776 static struct e820entry buf; /* static so it is zeroed */
13777diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
13778index ba3e100..6501b8f 100644
13779--- a/arch/x86/boot/video-vesa.c
13780+++ b/arch/x86/boot/video-vesa.c
13781@@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
13782
13783 boot_params.screen_info.vesapm_seg = oreg.es;
13784 boot_params.screen_info.vesapm_off = oreg.di;
13785+ boot_params.screen_info.vesapm_size = oreg.cx;
13786 }
13787
13788 /*
13789diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
13790index 43eda28..5ab5fdb 100644
13791--- a/arch/x86/boot/video.c
13792+++ b/arch/x86/boot/video.c
13793@@ -96,7 +96,7 @@ static void store_mode_params(void)
13794 static unsigned int get_entry(void)
13795 {
13796 char entry_buf[4];
13797- int i, len = 0;
13798+ unsigned int i, len = 0;
13799 int key;
13800 unsigned int v;
13801
13802diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
13803index 9105655..41779c1 100644
13804--- a/arch/x86/crypto/aes-x86_64-asm_64.S
13805+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
13806@@ -8,6 +8,8 @@
13807 * including this sentence is retained in full.
13808 */
13809
13810+#include <asm/alternative-asm.h>
13811+
13812 .extern crypto_ft_tab
13813 .extern crypto_it_tab
13814 .extern crypto_fl_tab
13815@@ -70,6 +72,8 @@
13816 je B192; \
13817 leaq 32(r9),r9;
13818
13819+#define ret pax_force_retaddr; ret
13820+
13821 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13822 movq r1,r2; \
13823 movq r3,r4; \
13824diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13825index 477e9d7..c92c7d8 100644
13826--- a/arch/x86/crypto/aesni-intel_asm.S
13827+++ b/arch/x86/crypto/aesni-intel_asm.S
13828@@ -31,6 +31,7 @@
13829
13830 #include <linux/linkage.h>
13831 #include <asm/inst.h>
13832+#include <asm/alternative-asm.h>
13833
13834 #ifdef __x86_64__
13835 .data
13836@@ -205,7 +206,7 @@ enc: .octa 0x2
13837 * num_initial_blocks = b mod 4
13838 * encrypt the initial num_initial_blocks blocks and apply ghash on
13839 * the ciphertext
13840-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13841+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13842 * are clobbered
13843 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13844 */
13845@@ -214,8 +215,8 @@ enc: .octa 0x2
13846 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13847 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13848 mov arg7, %r10 # %r10 = AAD
13849- mov arg8, %r12 # %r12 = aadLen
13850- mov %r12, %r11
13851+ mov arg8, %r15 # %r15 = aadLen
13852+ mov %r15, %r11
13853 pxor %xmm\i, %xmm\i
13854 _get_AAD_loop\num_initial_blocks\operation:
13855 movd (%r10), \TMP1
13856@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13857 psrldq $4, %xmm\i
13858 pxor \TMP1, %xmm\i
13859 add $4, %r10
13860- sub $4, %r12
13861+ sub $4, %r15
13862 jne _get_AAD_loop\num_initial_blocks\operation
13863 cmp $16, %r11
13864 je _get_AAD_loop2_done\num_initial_blocks\operation
13865- mov $16, %r12
13866+ mov $16, %r15
13867 _get_AAD_loop2\num_initial_blocks\operation:
13868 psrldq $4, %xmm\i
13869- sub $4, %r12
13870- cmp %r11, %r12
13871+ sub $4, %r15
13872+ cmp %r11, %r15
13873 jne _get_AAD_loop2\num_initial_blocks\operation
13874 _get_AAD_loop2_done\num_initial_blocks\operation:
13875 movdqa SHUF_MASK(%rip), %xmm14
13876@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13877 * num_initial_blocks = b mod 4
13878 * encrypt the initial num_initial_blocks blocks and apply ghash on
13879 * the ciphertext
13880-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13881+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13882 * are clobbered
13883 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13884 */
13885@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13886 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13887 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13888 mov arg7, %r10 # %r10 = AAD
13889- mov arg8, %r12 # %r12 = aadLen
13890- mov %r12, %r11
13891+ mov arg8, %r15 # %r15 = aadLen
13892+ mov %r15, %r11
13893 pxor %xmm\i, %xmm\i
13894 _get_AAD_loop\num_initial_blocks\operation:
13895 movd (%r10), \TMP1
13896@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13897 psrldq $4, %xmm\i
13898 pxor \TMP1, %xmm\i
13899 add $4, %r10
13900- sub $4, %r12
13901+ sub $4, %r15
13902 jne _get_AAD_loop\num_initial_blocks\operation
13903 cmp $16, %r11
13904 je _get_AAD_loop2_done\num_initial_blocks\operation
13905- mov $16, %r12
13906+ mov $16, %r15
13907 _get_AAD_loop2\num_initial_blocks\operation:
13908 psrldq $4, %xmm\i
13909- sub $4, %r12
13910- cmp %r11, %r12
13911+ sub $4, %r15
13912+ cmp %r11, %r15
13913 jne _get_AAD_loop2\num_initial_blocks\operation
13914 _get_AAD_loop2_done\num_initial_blocks\operation:
13915 movdqa SHUF_MASK(%rip), %xmm14
13916@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13917 *
13918 *****************************************************************************/
13919 ENTRY(aesni_gcm_dec)
13920- push %r12
13921+ push %r15
13922 push %r13
13923 push %r14
13924 mov %rsp, %r14
13925@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13926 */
13927 sub $VARIABLE_OFFSET, %rsp
13928 and $~63, %rsp # align rsp to 64 bytes
13929- mov %arg6, %r12
13930- movdqu (%r12), %xmm13 # %xmm13 = HashKey
13931+ mov %arg6, %r15
13932+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
13933 movdqa SHUF_MASK(%rip), %xmm2
13934 PSHUFB_XMM %xmm2, %xmm13
13935
13936@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13937 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13938 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13939 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13940- mov %r13, %r12
13941- and $(3<<4), %r12
13942+ mov %r13, %r15
13943+ and $(3<<4), %r15
13944 jz _initial_num_blocks_is_0_decrypt
13945- cmp $(2<<4), %r12
13946+ cmp $(2<<4), %r15
13947 jb _initial_num_blocks_is_1_decrypt
13948 je _initial_num_blocks_is_2_decrypt
13949 _initial_num_blocks_is_3_decrypt:
13950@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13951 sub $16, %r11
13952 add %r13, %r11
13953 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13954- lea SHIFT_MASK+16(%rip), %r12
13955- sub %r13, %r12
13956+ lea SHIFT_MASK+16(%rip), %r15
13957+ sub %r13, %r15
13958 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13959 # (%r13 is the number of bytes in plaintext mod 16)
13960- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13961+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13962 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13963
13964 movdqa %xmm1, %xmm2
13965 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13966- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13967+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13968 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13969 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13970 pand %xmm1, %xmm2
13971@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13972 sub $1, %r13
13973 jne _less_than_8_bytes_left_decrypt
13974 _multiple_of_16_bytes_decrypt:
13975- mov arg8, %r12 # %r13 = aadLen (number of bytes)
13976- shl $3, %r12 # convert into number of bits
13977- movd %r12d, %xmm15 # len(A) in %xmm15
13978+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
13979+ shl $3, %r15 # convert into number of bits
13980+ movd %r15d, %xmm15 # len(A) in %xmm15
13981 shl $3, %arg4 # len(C) in bits (*128)
13982 MOVQ_R64_XMM %arg4, %xmm1
13983 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13984@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13985 mov %r14, %rsp
13986 pop %r14
13987 pop %r13
13988- pop %r12
13989+ pop %r15
13990+ pax_force_retaddr
13991 ret
13992 ENDPROC(aesni_gcm_dec)
13993
13994@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
13995 * poly = x^128 + x^127 + x^126 + x^121 + 1
13996 ***************************************************************************/
13997 ENTRY(aesni_gcm_enc)
13998- push %r12
13999+ push %r15
14000 push %r13
14001 push %r14
14002 mov %rsp, %r14
14003@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
14004 #
14005 sub $VARIABLE_OFFSET, %rsp
14006 and $~63, %rsp
14007- mov %arg6, %r12
14008- movdqu (%r12), %xmm13
14009+ mov %arg6, %r15
14010+ movdqu (%r15), %xmm13
14011 movdqa SHUF_MASK(%rip), %xmm2
14012 PSHUFB_XMM %xmm2, %xmm13
14013
14014@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
14015 movdqa %xmm13, HashKey(%rsp)
14016 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
14017 and $-16, %r13
14018- mov %r13, %r12
14019+ mov %r13, %r15
14020
14021 # Encrypt first few blocks
14022
14023- and $(3<<4), %r12
14024+ and $(3<<4), %r15
14025 jz _initial_num_blocks_is_0_encrypt
14026- cmp $(2<<4), %r12
14027+ cmp $(2<<4), %r15
14028 jb _initial_num_blocks_is_1_encrypt
14029 je _initial_num_blocks_is_2_encrypt
14030 _initial_num_blocks_is_3_encrypt:
14031@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
14032 sub $16, %r11
14033 add %r13, %r11
14034 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
14035- lea SHIFT_MASK+16(%rip), %r12
14036- sub %r13, %r12
14037+ lea SHIFT_MASK+16(%rip), %r15
14038+ sub %r13, %r15
14039 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
14040 # (%r13 is the number of bytes in plaintext mod 16)
14041- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
14042+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
14043 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
14044 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
14045- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
14046+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
14047 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
14048 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
14049 movdqa SHUF_MASK(%rip), %xmm10
14050@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
14051 sub $1, %r13
14052 jne _less_than_8_bytes_left_encrypt
14053 _multiple_of_16_bytes_encrypt:
14054- mov arg8, %r12 # %r12 = addLen (number of bytes)
14055- shl $3, %r12
14056- movd %r12d, %xmm15 # len(A) in %xmm15
14057+ mov arg8, %r15 # %r15 = addLen (number of bytes)
14058+ shl $3, %r15
14059+ movd %r15d, %xmm15 # len(A) in %xmm15
14060 shl $3, %arg4 # len(C) in bits (*128)
14061 MOVQ_R64_XMM %arg4, %xmm1
14062 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
14063@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
14064 mov %r14, %rsp
14065 pop %r14
14066 pop %r13
14067- pop %r12
14068+ pop %r15
14069+ pax_force_retaddr
14070 ret
14071 ENDPROC(aesni_gcm_enc)
14072
14073@@ -1722,6 +1725,7 @@ _key_expansion_256a:
14074 pxor %xmm1, %xmm0
14075 movaps %xmm0, (TKEYP)
14076 add $0x10, TKEYP
14077+ pax_force_retaddr
14078 ret
14079 ENDPROC(_key_expansion_128)
14080 ENDPROC(_key_expansion_256a)
14081@@ -1748,6 +1752,7 @@ _key_expansion_192a:
14082 shufps $0b01001110, %xmm2, %xmm1
14083 movaps %xmm1, 0x10(TKEYP)
14084 add $0x20, TKEYP
14085+ pax_force_retaddr
14086 ret
14087 ENDPROC(_key_expansion_192a)
14088
14089@@ -1768,6 +1773,7 @@ _key_expansion_192b:
14090
14091 movaps %xmm0, (TKEYP)
14092 add $0x10, TKEYP
14093+ pax_force_retaddr
14094 ret
14095 ENDPROC(_key_expansion_192b)
14096
14097@@ -1781,6 +1787,7 @@ _key_expansion_256b:
14098 pxor %xmm1, %xmm2
14099 movaps %xmm2, (TKEYP)
14100 add $0x10, TKEYP
14101+ pax_force_retaddr
14102 ret
14103 ENDPROC(_key_expansion_256b)
14104
14105@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
14106 #ifndef __x86_64__
14107 popl KEYP
14108 #endif
14109+ pax_force_retaddr
14110 ret
14111 ENDPROC(aesni_set_key)
14112
14113@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
14114 popl KLEN
14115 popl KEYP
14116 #endif
14117+ pax_force_retaddr
14118 ret
14119 ENDPROC(aesni_enc)
14120
14121@@ -1974,6 +1983,7 @@ _aesni_enc1:
14122 AESENC KEY STATE
14123 movaps 0x70(TKEYP), KEY
14124 AESENCLAST KEY STATE
14125+ pax_force_retaddr
14126 ret
14127 ENDPROC(_aesni_enc1)
14128
14129@@ -2083,6 +2093,7 @@ _aesni_enc4:
14130 AESENCLAST KEY STATE2
14131 AESENCLAST KEY STATE3
14132 AESENCLAST KEY STATE4
14133+ pax_force_retaddr
14134 ret
14135 ENDPROC(_aesni_enc4)
14136
14137@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
14138 popl KLEN
14139 popl KEYP
14140 #endif
14141+ pax_force_retaddr
14142 ret
14143 ENDPROC(aesni_dec)
14144
14145@@ -2164,6 +2176,7 @@ _aesni_dec1:
14146 AESDEC KEY STATE
14147 movaps 0x70(TKEYP), KEY
14148 AESDECLAST KEY STATE
14149+ pax_force_retaddr
14150 ret
14151 ENDPROC(_aesni_dec1)
14152
14153@@ -2273,6 +2286,7 @@ _aesni_dec4:
14154 AESDECLAST KEY STATE2
14155 AESDECLAST KEY STATE3
14156 AESDECLAST KEY STATE4
14157+ pax_force_retaddr
14158 ret
14159 ENDPROC(_aesni_dec4)
14160
14161@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
14162 popl KEYP
14163 popl LEN
14164 #endif
14165+ pax_force_retaddr
14166 ret
14167 ENDPROC(aesni_ecb_enc)
14168
14169@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
14170 popl KEYP
14171 popl LEN
14172 #endif
14173+ pax_force_retaddr
14174 ret
14175 ENDPROC(aesni_ecb_dec)
14176
14177@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
14178 popl LEN
14179 popl IVP
14180 #endif
14181+ pax_force_retaddr
14182 ret
14183 ENDPROC(aesni_cbc_enc)
14184
14185@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
14186 popl LEN
14187 popl IVP
14188 #endif
14189+ pax_force_retaddr
14190 ret
14191 ENDPROC(aesni_cbc_dec)
14192
14193@@ -2550,6 +2568,7 @@ _aesni_inc_init:
14194 mov $1, TCTR_LOW
14195 MOVQ_R64_XMM TCTR_LOW INC
14196 MOVQ_R64_XMM CTR TCTR_LOW
14197+ pax_force_retaddr
14198 ret
14199 ENDPROC(_aesni_inc_init)
14200
14201@@ -2579,6 +2598,7 @@ _aesni_inc:
14202 .Linc_low:
14203 movaps CTR, IV
14204 PSHUFB_XMM BSWAP_MASK IV
14205+ pax_force_retaddr
14206 ret
14207 ENDPROC(_aesni_inc)
14208
14209@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
14210 .Lctr_enc_ret:
14211 movups IV, (IVP)
14212 .Lctr_enc_just_ret:
14213+ pax_force_retaddr
14214 ret
14215 ENDPROC(aesni_ctr_enc)
14216
14217@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
14218 pxor INC, STATE4
14219 movdqu STATE4, 0x70(OUTP)
14220
14221+ pax_force_retaddr
14222 ret
14223 ENDPROC(aesni_xts_crypt8)
14224
14225diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
14226index 246c670..466e2d6 100644
14227--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
14228+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
14229@@ -21,6 +21,7 @@
14230 */
14231
14232 #include <linux/linkage.h>
14233+#include <asm/alternative-asm.h>
14234
14235 .file "blowfish-x86_64-asm.S"
14236 .text
14237@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
14238 jnz .L__enc_xor;
14239
14240 write_block();
14241+ pax_force_retaddr
14242 ret;
14243 .L__enc_xor:
14244 xor_block();
14245+ pax_force_retaddr
14246 ret;
14247 ENDPROC(__blowfish_enc_blk)
14248
14249@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
14250
14251 movq %r11, %rbp;
14252
14253+ pax_force_retaddr
14254 ret;
14255 ENDPROC(blowfish_dec_blk)
14256
14257@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
14258
14259 popq %rbx;
14260 popq %rbp;
14261+ pax_force_retaddr
14262 ret;
14263
14264 .L__enc_xor4:
14265@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
14266
14267 popq %rbx;
14268 popq %rbp;
14269+ pax_force_retaddr
14270 ret;
14271 ENDPROC(__blowfish_enc_blk_4way)
14272
14273@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
14274 popq %rbx;
14275 popq %rbp;
14276
14277+ pax_force_retaddr
14278 ret;
14279 ENDPROC(blowfish_dec_blk_4way)
14280diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
14281index ce71f92..1dce7ec 100644
14282--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
14283+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
14284@@ -16,6 +16,7 @@
14285 */
14286
14287 #include <linux/linkage.h>
14288+#include <asm/alternative-asm.h>
14289
14290 #define CAMELLIA_TABLE_BYTE_LEN 272
14291
14292@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
14293 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
14294 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
14295 %rcx, (%r9));
14296+ pax_force_retaddr
14297 ret;
14298 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
14299
14300@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
14301 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
14302 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
14303 %rax, (%r9));
14304+ pax_force_retaddr
14305 ret;
14306 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
14307
14308@@ -780,6 +783,7 @@ __camellia_enc_blk16:
14309 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
14310 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
14311
14312+ pax_force_retaddr
14313 ret;
14314
14315 .align 8
14316@@ -865,6 +869,7 @@ __camellia_dec_blk16:
14317 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
14318 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
14319
14320+ pax_force_retaddr
14321 ret;
14322
14323 .align 8
14324@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
14325 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14326 %xmm8, %rsi);
14327
14328+ pax_force_retaddr
14329 ret;
14330 ENDPROC(camellia_ecb_enc_16way)
14331
14332@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
14333 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14334 %xmm8, %rsi);
14335
14336+ pax_force_retaddr
14337 ret;
14338 ENDPROC(camellia_ecb_dec_16way)
14339
14340@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
14341 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14342 %xmm8, %rsi);
14343
14344+ pax_force_retaddr
14345 ret;
14346 ENDPROC(camellia_cbc_dec_16way)
14347
14348@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
14349 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14350 %xmm8, %rsi);
14351
14352+ pax_force_retaddr
14353 ret;
14354 ENDPROC(camellia_ctr_16way)
14355
14356@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
14357 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14358 %xmm8, %rsi);
14359
14360+ pax_force_retaddr
14361 ret;
14362 ENDPROC(camellia_xts_crypt_16way)
14363
14364diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
14365index 0e0b886..5a3123c 100644
14366--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
14367+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
14368@@ -11,6 +11,7 @@
14369 */
14370
14371 #include <linux/linkage.h>
14372+#include <asm/alternative-asm.h>
14373
14374 #define CAMELLIA_TABLE_BYTE_LEN 272
14375
14376@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
14377 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
14378 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
14379 %rcx, (%r9));
14380+ pax_force_retaddr
14381 ret;
14382 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
14383
14384@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
14385 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
14386 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
14387 %rax, (%r9));
14388+ pax_force_retaddr
14389 ret;
14390 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
14391
14392@@ -820,6 +823,7 @@ __camellia_enc_blk32:
14393 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
14394 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
14395
14396+ pax_force_retaddr
14397 ret;
14398
14399 .align 8
14400@@ -905,6 +909,7 @@ __camellia_dec_blk32:
14401 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
14402 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
14403
14404+ pax_force_retaddr
14405 ret;
14406
14407 .align 8
14408@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
14409
14410 vzeroupper;
14411
14412+ pax_force_retaddr
14413 ret;
14414 ENDPROC(camellia_ecb_enc_32way)
14415
14416@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
14417
14418 vzeroupper;
14419
14420+ pax_force_retaddr
14421 ret;
14422 ENDPROC(camellia_ecb_dec_32way)
14423
14424@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
14425
14426 vzeroupper;
14427
14428+ pax_force_retaddr
14429 ret;
14430 ENDPROC(camellia_cbc_dec_32way)
14431
14432@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
14433
14434 vzeroupper;
14435
14436+ pax_force_retaddr
14437 ret;
14438 ENDPROC(camellia_ctr_32way)
14439
14440@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
14441
14442 vzeroupper;
14443
14444+ pax_force_retaddr
14445 ret;
14446 ENDPROC(camellia_xts_crypt_32way)
14447
14448diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
14449index 310319c..db3d7b5 100644
14450--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
14451+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
14452@@ -21,6 +21,7 @@
14453 */
14454
14455 #include <linux/linkage.h>
14456+#include <asm/alternative-asm.h>
14457
14458 .file "camellia-x86_64-asm_64.S"
14459 .text
14460@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
14461 enc_outunpack(mov, RT1);
14462
14463 movq RRBP, %rbp;
14464+ pax_force_retaddr
14465 ret;
14466
14467 .L__enc_xor:
14468 enc_outunpack(xor, RT1);
14469
14470 movq RRBP, %rbp;
14471+ pax_force_retaddr
14472 ret;
14473 ENDPROC(__camellia_enc_blk)
14474
14475@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
14476 dec_outunpack();
14477
14478 movq RRBP, %rbp;
14479+ pax_force_retaddr
14480 ret;
14481 ENDPROC(camellia_dec_blk)
14482
14483@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
14484
14485 movq RRBP, %rbp;
14486 popq %rbx;
14487+ pax_force_retaddr
14488 ret;
14489
14490 .L__enc2_xor:
14491@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
14492
14493 movq RRBP, %rbp;
14494 popq %rbx;
14495+ pax_force_retaddr
14496 ret;
14497 ENDPROC(__camellia_enc_blk_2way)
14498
14499@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
14500
14501 movq RRBP, %rbp;
14502 movq RXOR, %rbx;
14503+ pax_force_retaddr
14504 ret;
14505 ENDPROC(camellia_dec_blk_2way)
14506diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
14507index c35fd5d..2d8c7db 100644
14508--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
14509+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
14510@@ -24,6 +24,7 @@
14511 */
14512
14513 #include <linux/linkage.h>
14514+#include <asm/alternative-asm.h>
14515
14516 .file "cast5-avx-x86_64-asm_64.S"
14517
14518@@ -281,6 +282,7 @@ __cast5_enc_blk16:
14519 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
14520 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
14521
14522+ pax_force_retaddr
14523 ret;
14524 ENDPROC(__cast5_enc_blk16)
14525
14526@@ -352,6 +354,7 @@ __cast5_dec_blk16:
14527 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
14528 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
14529
14530+ pax_force_retaddr
14531 ret;
14532
14533 .L__skip_dec:
14534@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
14535 vmovdqu RR4, (6*4*4)(%r11);
14536 vmovdqu RL4, (7*4*4)(%r11);
14537
14538+ pax_force_retaddr
14539 ret;
14540 ENDPROC(cast5_ecb_enc_16way)
14541
14542@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
14543 vmovdqu RR4, (6*4*4)(%r11);
14544 vmovdqu RL4, (7*4*4)(%r11);
14545
14546+ pax_force_retaddr
14547 ret;
14548 ENDPROC(cast5_ecb_dec_16way)
14549
14550@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
14551 * %rdx: src
14552 */
14553
14554- pushq %r12;
14555+ pushq %r14;
14556
14557 movq %rsi, %r11;
14558- movq %rdx, %r12;
14559+ movq %rdx, %r14;
14560
14561 vmovdqu (0*16)(%rdx), RL1;
14562 vmovdqu (1*16)(%rdx), RR1;
14563@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
14564 call __cast5_dec_blk16;
14565
14566 /* xor with src */
14567- vmovq (%r12), RX;
14568+ vmovq (%r14), RX;
14569 vpshufd $0x4f, RX, RX;
14570 vpxor RX, RR1, RR1;
14571- vpxor 0*16+8(%r12), RL1, RL1;
14572- vpxor 1*16+8(%r12), RR2, RR2;
14573- vpxor 2*16+8(%r12), RL2, RL2;
14574- vpxor 3*16+8(%r12), RR3, RR3;
14575- vpxor 4*16+8(%r12), RL3, RL3;
14576- vpxor 5*16+8(%r12), RR4, RR4;
14577- vpxor 6*16+8(%r12), RL4, RL4;
14578+ vpxor 0*16+8(%r14), RL1, RL1;
14579+ vpxor 1*16+8(%r14), RR2, RR2;
14580+ vpxor 2*16+8(%r14), RL2, RL2;
14581+ vpxor 3*16+8(%r14), RR3, RR3;
14582+ vpxor 4*16+8(%r14), RL3, RL3;
14583+ vpxor 5*16+8(%r14), RR4, RR4;
14584+ vpxor 6*16+8(%r14), RL4, RL4;
14585
14586 vmovdqu RR1, (0*16)(%r11);
14587 vmovdqu RL1, (1*16)(%r11);
14588@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
14589 vmovdqu RR4, (6*16)(%r11);
14590 vmovdqu RL4, (7*16)(%r11);
14591
14592- popq %r12;
14593+ popq %r14;
14594
14595+ pax_force_retaddr
14596 ret;
14597 ENDPROC(cast5_cbc_dec_16way)
14598
14599@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
14600 * %rcx: iv (big endian, 64bit)
14601 */
14602
14603- pushq %r12;
14604+ pushq %r14;
14605
14606 movq %rsi, %r11;
14607- movq %rdx, %r12;
14608+ movq %rdx, %r14;
14609
14610 vpcmpeqd RTMP, RTMP, RTMP;
14611 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
14612@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
14613 call __cast5_enc_blk16;
14614
14615 /* dst = src ^ iv */
14616- vpxor (0*16)(%r12), RR1, RR1;
14617- vpxor (1*16)(%r12), RL1, RL1;
14618- vpxor (2*16)(%r12), RR2, RR2;
14619- vpxor (3*16)(%r12), RL2, RL2;
14620- vpxor (4*16)(%r12), RR3, RR3;
14621- vpxor (5*16)(%r12), RL3, RL3;
14622- vpxor (6*16)(%r12), RR4, RR4;
14623- vpxor (7*16)(%r12), RL4, RL4;
14624+ vpxor (0*16)(%r14), RR1, RR1;
14625+ vpxor (1*16)(%r14), RL1, RL1;
14626+ vpxor (2*16)(%r14), RR2, RR2;
14627+ vpxor (3*16)(%r14), RL2, RL2;
14628+ vpxor (4*16)(%r14), RR3, RR3;
14629+ vpxor (5*16)(%r14), RL3, RL3;
14630+ vpxor (6*16)(%r14), RR4, RR4;
14631+ vpxor (7*16)(%r14), RL4, RL4;
14632 vmovdqu RR1, (0*16)(%r11);
14633 vmovdqu RL1, (1*16)(%r11);
14634 vmovdqu RR2, (2*16)(%r11);
14635@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
14636 vmovdqu RR4, (6*16)(%r11);
14637 vmovdqu RL4, (7*16)(%r11);
14638
14639- popq %r12;
14640+ popq %r14;
14641
14642+ pax_force_retaddr
14643 ret;
14644 ENDPROC(cast5_ctr_16way)
14645diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14646index e3531f8..e123f35 100644
14647--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14648+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14649@@ -24,6 +24,7 @@
14650 */
14651
14652 #include <linux/linkage.h>
14653+#include <asm/alternative-asm.h>
14654 #include "glue_helper-asm-avx.S"
14655
14656 .file "cast6-avx-x86_64-asm_64.S"
14657@@ -295,6 +296,7 @@ __cast6_enc_blk8:
14658 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
14659 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
14660
14661+ pax_force_retaddr
14662 ret;
14663 ENDPROC(__cast6_enc_blk8)
14664
14665@@ -340,6 +342,7 @@ __cast6_dec_blk8:
14666 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
14667 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
14668
14669+ pax_force_retaddr
14670 ret;
14671 ENDPROC(__cast6_dec_blk8)
14672
14673@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
14674
14675 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14676
14677+ pax_force_retaddr
14678 ret;
14679 ENDPROC(cast6_ecb_enc_8way)
14680
14681@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
14682
14683 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14684
14685+ pax_force_retaddr
14686 ret;
14687 ENDPROC(cast6_ecb_dec_8way)
14688
14689@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
14690 * %rdx: src
14691 */
14692
14693- pushq %r12;
14694+ pushq %r14;
14695
14696 movq %rsi, %r11;
14697- movq %rdx, %r12;
14698+ movq %rdx, %r14;
14699
14700 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14701
14702 call __cast6_dec_blk8;
14703
14704- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14705+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14706
14707- popq %r12;
14708+ popq %r14;
14709
14710+ pax_force_retaddr
14711 ret;
14712 ENDPROC(cast6_cbc_dec_8way)
14713
14714@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
14715 * %rcx: iv (little endian, 128bit)
14716 */
14717
14718- pushq %r12;
14719+ pushq %r14;
14720
14721 movq %rsi, %r11;
14722- movq %rdx, %r12;
14723+ movq %rdx, %r14;
14724
14725 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14726 RD2, RX, RKR, RKM);
14727
14728 call __cast6_enc_blk8;
14729
14730- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14731+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14732
14733- popq %r12;
14734+ popq %r14;
14735
14736+ pax_force_retaddr
14737 ret;
14738 ENDPROC(cast6_ctr_8way)
14739
14740@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
14741 /* dst <= regs xor IVs(in dst) */
14742 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14743
14744+ pax_force_retaddr
14745 ret;
14746 ENDPROC(cast6_xts_enc_8way)
14747
14748@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
14749 /* dst <= regs xor IVs(in dst) */
14750 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14751
14752+ pax_force_retaddr
14753 ret;
14754 ENDPROC(cast6_xts_dec_8way)
14755diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14756index 26d49eb..c0a8c84 100644
14757--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14758+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14759@@ -45,6 +45,7 @@
14760
14761 #include <asm/inst.h>
14762 #include <linux/linkage.h>
14763+#include <asm/alternative-asm.h>
14764
14765 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
14766
14767@@ -309,6 +310,7 @@ do_return:
14768 popq %rsi
14769 popq %rdi
14770 popq %rbx
14771+ pax_force_retaddr
14772 ret
14773
14774 ################################################################
14775diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14776index 5d1e007..098cb4f 100644
14777--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
14778+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14779@@ -18,6 +18,7 @@
14780
14781 #include <linux/linkage.h>
14782 #include <asm/inst.h>
14783+#include <asm/alternative-asm.h>
14784
14785 .data
14786
14787@@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
14788 psrlq $1, T2
14789 pxor T2, T1
14790 pxor T1, DATA
14791+ pax_force_retaddr
14792 ret
14793 ENDPROC(__clmul_gf128mul_ble)
14794
14795@@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
14796 call __clmul_gf128mul_ble
14797 PSHUFB_XMM BSWAP DATA
14798 movups DATA, (%rdi)
14799+ pax_force_retaddr
14800 ret
14801 ENDPROC(clmul_ghash_mul)
14802
14803@@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
14804 PSHUFB_XMM BSWAP DATA
14805 movups DATA, (%rdi)
14806 .Lupdate_just_ret:
14807+ pax_force_retaddr
14808 ret
14809 ENDPROC(clmul_ghash_update)
14810diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14811index 9279e0b..c4b3d2c 100644
14812--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14813+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14814@@ -1,4 +1,5 @@
14815 #include <linux/linkage.h>
14816+#include <asm/alternative-asm.h>
14817
14818 # enter salsa20_encrypt_bytes
14819 ENTRY(salsa20_encrypt_bytes)
14820@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14821 add %r11,%rsp
14822 mov %rdi,%rax
14823 mov %rsi,%rdx
14824+ pax_force_retaddr
14825 ret
14826 # bytesatleast65:
14827 ._bytesatleast65:
14828@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14829 add %r11,%rsp
14830 mov %rdi,%rax
14831 mov %rsi,%rdx
14832+ pax_force_retaddr
14833 ret
14834 ENDPROC(salsa20_keysetup)
14835
14836@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14837 add %r11,%rsp
14838 mov %rdi,%rax
14839 mov %rsi,%rdx
14840+ pax_force_retaddr
14841 ret
14842 ENDPROC(salsa20_ivsetup)
14843diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14844index 2f202f4..d9164d6 100644
14845--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14846+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14847@@ -24,6 +24,7 @@
14848 */
14849
14850 #include <linux/linkage.h>
14851+#include <asm/alternative-asm.h>
14852 #include "glue_helper-asm-avx.S"
14853
14854 .file "serpent-avx-x86_64-asm_64.S"
14855@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14856 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14857 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14858
14859+ pax_force_retaddr
14860 ret;
14861 ENDPROC(__serpent_enc_blk8_avx)
14862
14863@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14864 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14865 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14866
14867+ pax_force_retaddr
14868 ret;
14869 ENDPROC(__serpent_dec_blk8_avx)
14870
14871@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14872
14873 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14874
14875+ pax_force_retaddr
14876 ret;
14877 ENDPROC(serpent_ecb_enc_8way_avx)
14878
14879@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14880
14881 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14882
14883+ pax_force_retaddr
14884 ret;
14885 ENDPROC(serpent_ecb_dec_8way_avx)
14886
14887@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14888
14889 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14890
14891+ pax_force_retaddr
14892 ret;
14893 ENDPROC(serpent_cbc_dec_8way_avx)
14894
14895@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14896
14897 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14898
14899+ pax_force_retaddr
14900 ret;
14901 ENDPROC(serpent_ctr_8way_avx)
14902
14903@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14904 /* dst <= regs xor IVs(in dst) */
14905 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14906
14907+ pax_force_retaddr
14908 ret;
14909 ENDPROC(serpent_xts_enc_8way_avx)
14910
14911@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14912 /* dst <= regs xor IVs(in dst) */
14913 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14914
14915+ pax_force_retaddr
14916 ret;
14917 ENDPROC(serpent_xts_dec_8way_avx)
14918diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14919index b222085..abd483c 100644
14920--- a/arch/x86/crypto/serpent-avx2-asm_64.S
14921+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14922@@ -15,6 +15,7 @@
14923 */
14924
14925 #include <linux/linkage.h>
14926+#include <asm/alternative-asm.h>
14927 #include "glue_helper-asm-avx2.S"
14928
14929 .file "serpent-avx2-asm_64.S"
14930@@ -610,6 +611,7 @@ __serpent_enc_blk16:
14931 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14932 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14933
14934+ pax_force_retaddr
14935 ret;
14936 ENDPROC(__serpent_enc_blk16)
14937
14938@@ -664,6 +666,7 @@ __serpent_dec_blk16:
14939 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14940 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14941
14942+ pax_force_retaddr
14943 ret;
14944 ENDPROC(__serpent_dec_blk16)
14945
14946@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14947
14948 vzeroupper;
14949
14950+ pax_force_retaddr
14951 ret;
14952 ENDPROC(serpent_ecb_enc_16way)
14953
14954@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14955
14956 vzeroupper;
14957
14958+ pax_force_retaddr
14959 ret;
14960 ENDPROC(serpent_ecb_dec_16way)
14961
14962@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14963
14964 vzeroupper;
14965
14966+ pax_force_retaddr
14967 ret;
14968 ENDPROC(serpent_cbc_dec_16way)
14969
14970@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14971
14972 vzeroupper;
14973
14974+ pax_force_retaddr
14975 ret;
14976 ENDPROC(serpent_ctr_16way)
14977
14978@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14979
14980 vzeroupper;
14981
14982+ pax_force_retaddr
14983 ret;
14984 ENDPROC(serpent_xts_enc_16way)
14985
14986@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14987
14988 vzeroupper;
14989
14990+ pax_force_retaddr
14991 ret;
14992 ENDPROC(serpent_xts_dec_16way)
14993diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14994index acc066c..1559cc4 100644
14995--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14996+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14997@@ -25,6 +25,7 @@
14998 */
14999
15000 #include <linux/linkage.h>
15001+#include <asm/alternative-asm.h>
15002
15003 .file "serpent-sse2-x86_64-asm_64.S"
15004 .text
15005@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
15006 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
15007 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
15008
15009+ pax_force_retaddr
15010 ret;
15011
15012 .L__enc_xor8:
15013 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
15014 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
15015
15016+ pax_force_retaddr
15017 ret;
15018 ENDPROC(__serpent_enc_blk_8way)
15019
15020@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
15021 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
15022 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
15023
15024+ pax_force_retaddr
15025 ret;
15026 ENDPROC(serpent_dec_blk_8way)
15027diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
15028index a410950..9dfe7ad 100644
15029--- a/arch/x86/crypto/sha1_ssse3_asm.S
15030+++ b/arch/x86/crypto/sha1_ssse3_asm.S
15031@@ -29,6 +29,7 @@
15032 */
15033
15034 #include <linux/linkage.h>
15035+#include <asm/alternative-asm.h>
15036
15037 #define CTX %rdi // arg1
15038 #define BUF %rsi // arg2
15039@@ -75,9 +76,9 @@
15040
15041 push %rbx
15042 push %rbp
15043- push %r12
15044+ push %r14
15045
15046- mov %rsp, %r12
15047+ mov %rsp, %r14
15048 sub $64, %rsp # allocate workspace
15049 and $~15, %rsp # align stack
15050
15051@@ -99,11 +100,12 @@
15052 xor %rax, %rax
15053 rep stosq
15054
15055- mov %r12, %rsp # deallocate workspace
15056+ mov %r14, %rsp # deallocate workspace
15057
15058- pop %r12
15059+ pop %r14
15060 pop %rbp
15061 pop %rbx
15062+ pax_force_retaddr
15063 ret
15064
15065 ENDPROC(\name)
15066diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
15067index 642f156..51a513c 100644
15068--- a/arch/x86/crypto/sha256-avx-asm.S
15069+++ b/arch/x86/crypto/sha256-avx-asm.S
15070@@ -49,6 +49,7 @@
15071
15072 #ifdef CONFIG_AS_AVX
15073 #include <linux/linkage.h>
15074+#include <asm/alternative-asm.h>
15075
15076 ## assume buffers not aligned
15077 #define VMOVDQ vmovdqu
15078@@ -460,6 +461,7 @@ done_hash:
15079 popq %r13
15080 popq %rbp
15081 popq %rbx
15082+ pax_force_retaddr
15083 ret
15084 ENDPROC(sha256_transform_avx)
15085
15086diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
15087index 9e86944..3795e6a 100644
15088--- a/arch/x86/crypto/sha256-avx2-asm.S
15089+++ b/arch/x86/crypto/sha256-avx2-asm.S
15090@@ -50,6 +50,7 @@
15091
15092 #ifdef CONFIG_AS_AVX2
15093 #include <linux/linkage.h>
15094+#include <asm/alternative-asm.h>
15095
15096 ## assume buffers not aligned
15097 #define VMOVDQ vmovdqu
15098@@ -720,6 +721,7 @@ done_hash:
15099 popq %r12
15100 popq %rbp
15101 popq %rbx
15102+ pax_force_retaddr
15103 ret
15104 ENDPROC(sha256_transform_rorx)
15105
15106diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
15107index f833b74..8c62a9e 100644
15108--- a/arch/x86/crypto/sha256-ssse3-asm.S
15109+++ b/arch/x86/crypto/sha256-ssse3-asm.S
15110@@ -47,6 +47,7 @@
15111 ########################################################################
15112
15113 #include <linux/linkage.h>
15114+#include <asm/alternative-asm.h>
15115
15116 ## assume buffers not aligned
15117 #define MOVDQ movdqu
15118@@ -471,6 +472,7 @@ done_hash:
15119 popq %rbp
15120 popq %rbx
15121
15122+ pax_force_retaddr
15123 ret
15124 ENDPROC(sha256_transform_ssse3)
15125
15126diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
15127index 974dde9..a823ff9 100644
15128--- a/arch/x86/crypto/sha512-avx-asm.S
15129+++ b/arch/x86/crypto/sha512-avx-asm.S
15130@@ -49,6 +49,7 @@
15131
15132 #ifdef CONFIG_AS_AVX
15133 #include <linux/linkage.h>
15134+#include <asm/alternative-asm.h>
15135
15136 .text
15137
15138@@ -364,6 +365,7 @@ updateblock:
15139 mov frame_RSPSAVE(%rsp), %rsp
15140
15141 nowork:
15142+ pax_force_retaddr
15143 ret
15144 ENDPROC(sha512_transform_avx)
15145
15146diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
15147index 568b961..ed20c37 100644
15148--- a/arch/x86/crypto/sha512-avx2-asm.S
15149+++ b/arch/x86/crypto/sha512-avx2-asm.S
15150@@ -51,6 +51,7 @@
15151
15152 #ifdef CONFIG_AS_AVX2
15153 #include <linux/linkage.h>
15154+#include <asm/alternative-asm.h>
15155
15156 .text
15157
15158@@ -678,6 +679,7 @@ done_hash:
15159
15160 # Restore Stack Pointer
15161 mov frame_RSPSAVE(%rsp), %rsp
15162+ pax_force_retaddr
15163 ret
15164 ENDPROC(sha512_transform_rorx)
15165
15166diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
15167index fb56855..6edd768 100644
15168--- a/arch/x86/crypto/sha512-ssse3-asm.S
15169+++ b/arch/x86/crypto/sha512-ssse3-asm.S
15170@@ -48,6 +48,7 @@
15171 ########################################################################
15172
15173 #include <linux/linkage.h>
15174+#include <asm/alternative-asm.h>
15175
15176 .text
15177
15178@@ -363,6 +364,7 @@ updateblock:
15179 mov frame_RSPSAVE(%rsp), %rsp
15180
15181 nowork:
15182+ pax_force_retaddr
15183 ret
15184 ENDPROC(sha512_transform_ssse3)
15185
15186diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
15187index 0505813..b067311 100644
15188--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
15189+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
15190@@ -24,6 +24,7 @@
15191 */
15192
15193 #include <linux/linkage.h>
15194+#include <asm/alternative-asm.h>
15195 #include "glue_helper-asm-avx.S"
15196
15197 .file "twofish-avx-x86_64-asm_64.S"
15198@@ -284,6 +285,7 @@ __twofish_enc_blk8:
15199 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
15200 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
15201
15202+ pax_force_retaddr
15203 ret;
15204 ENDPROC(__twofish_enc_blk8)
15205
15206@@ -324,6 +326,7 @@ __twofish_dec_blk8:
15207 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
15208 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
15209
15210+ pax_force_retaddr
15211 ret;
15212 ENDPROC(__twofish_dec_blk8)
15213
15214@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
15215
15216 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15217
15218+ pax_force_retaddr
15219 ret;
15220 ENDPROC(twofish_ecb_enc_8way)
15221
15222@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
15223
15224 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
15225
15226+ pax_force_retaddr
15227 ret;
15228 ENDPROC(twofish_ecb_dec_8way)
15229
15230@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
15231 * %rdx: src
15232 */
15233
15234- pushq %r12;
15235+ pushq %r14;
15236
15237 movq %rsi, %r11;
15238- movq %rdx, %r12;
15239+ movq %rdx, %r14;
15240
15241 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15242
15243 call __twofish_dec_blk8;
15244
15245- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
15246+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
15247
15248- popq %r12;
15249+ popq %r14;
15250
15251+ pax_force_retaddr
15252 ret;
15253 ENDPROC(twofish_cbc_dec_8way)
15254
15255@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
15256 * %rcx: iv (little endian, 128bit)
15257 */
15258
15259- pushq %r12;
15260+ pushq %r14;
15261
15262 movq %rsi, %r11;
15263- movq %rdx, %r12;
15264+ movq %rdx, %r14;
15265
15266 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
15267 RD2, RX0, RX1, RY0);
15268
15269 call __twofish_enc_blk8;
15270
15271- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15272+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15273
15274- popq %r12;
15275+ popq %r14;
15276
15277+ pax_force_retaddr
15278 ret;
15279 ENDPROC(twofish_ctr_8way)
15280
15281@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
15282 /* dst <= regs xor IVs(in dst) */
15283 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15284
15285+ pax_force_retaddr
15286 ret;
15287 ENDPROC(twofish_xts_enc_8way)
15288
15289@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
15290 /* dst <= regs xor IVs(in dst) */
15291 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
15292
15293+ pax_force_retaddr
15294 ret;
15295 ENDPROC(twofish_xts_dec_8way)
15296diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
15297index 1c3b7ce..02f578d 100644
15298--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
15299+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
15300@@ -21,6 +21,7 @@
15301 */
15302
15303 #include <linux/linkage.h>
15304+#include <asm/alternative-asm.h>
15305
15306 .file "twofish-x86_64-asm-3way.S"
15307 .text
15308@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
15309 popq %r13;
15310 popq %r14;
15311 popq %r15;
15312+ pax_force_retaddr
15313 ret;
15314
15315 .L__enc_xor3:
15316@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
15317 popq %r13;
15318 popq %r14;
15319 popq %r15;
15320+ pax_force_retaddr
15321 ret;
15322 ENDPROC(__twofish_enc_blk_3way)
15323
15324@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
15325 popq %r13;
15326 popq %r14;
15327 popq %r15;
15328+ pax_force_retaddr
15329 ret;
15330 ENDPROC(twofish_dec_blk_3way)
15331diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
15332index a039d21..524b8b2 100644
15333--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
15334+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
15335@@ -22,6 +22,7 @@
15336
15337 #include <linux/linkage.h>
15338 #include <asm/asm-offsets.h>
15339+#include <asm/alternative-asm.h>
15340
15341 #define a_offset 0
15342 #define b_offset 4
15343@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
15344
15345 popq R1
15346 movq $1,%rax
15347+ pax_force_retaddr
15348 ret
15349 ENDPROC(twofish_enc_blk)
15350
15351@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
15352
15353 popq R1
15354 movq $1,%rax
15355+ pax_force_retaddr
15356 ret
15357 ENDPROC(twofish_dec_blk)
15358diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
15359index d21ff89..6da8e6e 100644
15360--- a/arch/x86/ia32/ia32_aout.c
15361+++ b/arch/x86/ia32/ia32_aout.c
15362@@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
15363 unsigned long dump_start, dump_size;
15364 struct user32 dump;
15365
15366+ memset(&dump, 0, sizeof(dump));
15367+
15368 fs = get_fs();
15369 set_fs(KERNEL_DS);
15370 has_dumped = 1;
15371diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
15372index f9e181a..300544c 100644
15373--- a/arch/x86/ia32/ia32_signal.c
15374+++ b/arch/x86/ia32/ia32_signal.c
15375@@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
15376 if (__get_user(set.sig[0], &frame->sc.oldmask)
15377 || (_COMPAT_NSIG_WORDS > 1
15378 && __copy_from_user((((char *) &set.sig) + 4),
15379- &frame->extramask,
15380+ frame->extramask,
15381 sizeof(frame->extramask))))
15382 goto badframe;
15383
15384@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
15385 sp -= frame_size;
15386 /* Align the stack pointer according to the i386 ABI,
15387 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
15388- sp = ((sp + 4) & -16ul) - 4;
15389+ sp = ((sp - 12) & -16ul) - 4;
15390 return (void __user *) sp;
15391 }
15392
15393@@ -383,10 +383,10 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
15394 } else {
15395 /* Return stub is in 32bit vsyscall page */
15396 if (current->mm->context.vdso)
15397- restorer = current->mm->context.vdso +
15398- selected_vdso32->sym___kernel_sigreturn;
15399+ restorer = (void __force_user *)(current->mm->context.vdso +
15400+ selected_vdso32->sym___kernel_sigreturn);
15401 else
15402- restorer = &frame->retcode;
15403+ restorer = frame->retcode;
15404 }
15405
15406 put_user_try {
15407@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
15408 * These are actually not used anymore, but left because some
15409 * gdb versions depend on them as a marker.
15410 */
15411- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
15412+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
15413 } put_user_catch(err);
15414
15415 if (err)
15416@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
15417 0xb8,
15418 __NR_ia32_rt_sigreturn,
15419 0x80cd,
15420- 0,
15421+ 0
15422 };
15423
15424 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
15425@@ -461,16 +461,19 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
15426
15427 if (ksig->ka.sa.sa_flags & SA_RESTORER)
15428 restorer = ksig->ka.sa.sa_restorer;
15429+ else if (current->mm->context.vdso)
15430+ /* Return stub is in 32bit vsyscall page */
15431+ restorer = (void __force_user *)(current->mm->context.vdso +
15432+ selected_vdso32->sym___kernel_rt_sigreturn);
15433 else
15434- restorer = current->mm->context.vdso +
15435- selected_vdso32->sym___kernel_rt_sigreturn;
15436+ restorer = frame->retcode;
15437 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
15438
15439 /*
15440 * Not actually used anymore, but left because some gdb
15441 * versions need it.
15442 */
15443- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
15444+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
15445 } put_user_catch(err);
15446
15447 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
15448diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
15449index 92a2e93..cd4d95f 100644
15450--- a/arch/x86/ia32/ia32entry.S
15451+++ b/arch/x86/ia32/ia32entry.S
15452@@ -15,8 +15,10 @@
15453 #include <asm/irqflags.h>
15454 #include <asm/asm.h>
15455 #include <asm/smap.h>
15456+#include <asm/pgtable.h>
15457 #include <linux/linkage.h>
15458 #include <linux/err.h>
15459+#include <asm/alternative-asm.h>
15460
15461 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15462 #include <linux/elf-em.h>
15463@@ -62,12 +64,12 @@
15464 */
15465 .macro LOAD_ARGS32 offset, _r9=0
15466 .if \_r9
15467- movl \offset+16(%rsp),%r9d
15468+ movl \offset+R9(%rsp),%r9d
15469 .endif
15470- movl \offset+40(%rsp),%ecx
15471- movl \offset+48(%rsp),%edx
15472- movl \offset+56(%rsp),%esi
15473- movl \offset+64(%rsp),%edi
15474+ movl \offset+RCX(%rsp),%ecx
15475+ movl \offset+RDX(%rsp),%edx
15476+ movl \offset+RSI(%rsp),%esi
15477+ movl \offset+RDI(%rsp),%edi
15478 movl %eax,%eax /* zero extension */
15479 .endm
15480
15481@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
15482 ENDPROC(native_irq_enable_sysexit)
15483 #endif
15484
15485+ .macro pax_enter_kernel_user
15486+ pax_set_fptr_mask
15487+#ifdef CONFIG_PAX_MEMORY_UDEREF
15488+ call pax_enter_kernel_user
15489+#endif
15490+ .endm
15491+
15492+ .macro pax_exit_kernel_user
15493+#ifdef CONFIG_PAX_MEMORY_UDEREF
15494+ call pax_exit_kernel_user
15495+#endif
15496+#ifdef CONFIG_PAX_RANDKSTACK
15497+ pushq %rax
15498+ pushq %r11
15499+ call pax_randomize_kstack
15500+ popq %r11
15501+ popq %rax
15502+#endif
15503+ .endm
15504+
15505+ .macro pax_erase_kstack
15506+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15507+ call pax_erase_kstack
15508+#endif
15509+ .endm
15510+
15511 /*
15512 * 32bit SYSENTER instruction entry.
15513 *
15514@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
15515 CFI_REGISTER rsp,rbp
15516 SWAPGS_UNSAFE_STACK
15517 movq PER_CPU_VAR(kernel_stack), %rsp
15518- addq $(KERNEL_STACK_OFFSET),%rsp
15519- /*
15520- * No need to follow this irqs on/off section: the syscall
15521- * disabled irqs, here we enable it straight after entry:
15522- */
15523- ENABLE_INTERRUPTS(CLBR_NONE)
15524 movl %ebp,%ebp /* zero extension */
15525 pushq_cfi $__USER32_DS
15526 /*CFI_REL_OFFSET ss,0*/
15527@@ -135,23 +157,46 @@ ENTRY(ia32_sysenter_target)
15528 CFI_REL_OFFSET rsp,0
15529 pushfq_cfi
15530 /*CFI_REL_OFFSET rflags,0*/
15531- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
15532- CFI_REGISTER rip,r10
15533+ orl $X86_EFLAGS_IF,(%rsp)
15534+ GET_THREAD_INFO(%r11)
15535+ movl TI_sysenter_return(%r11), %r11d
15536+ CFI_REGISTER rip,r11
15537 pushq_cfi $__USER32_CS
15538 /*CFI_REL_OFFSET cs,0*/
15539 movl %eax, %eax
15540- pushq_cfi %r10
15541+ pushq_cfi %r11
15542 CFI_REL_OFFSET rip,0
15543 pushq_cfi %rax
15544 cld
15545 SAVE_ARGS 0,1,0
15546+ pax_enter_kernel_user
15547+
15548+#ifdef CONFIG_PAX_RANDKSTACK
15549+ pax_erase_kstack
15550+#endif
15551+
15552+ /*
15553+ * No need to follow this irqs on/off section: the syscall
15554+ * disabled irqs, here we enable it straight after entry:
15555+ */
15556+ ENABLE_INTERRUPTS(CLBR_NONE)
15557 /* no need to do an access_ok check here because rbp has been
15558 32bit zero extended */
15559+
15560+#ifdef CONFIG_PAX_MEMORY_UDEREF
15561+ addq pax_user_shadow_base,%rbp
15562+ ASM_PAX_OPEN_USERLAND
15563+#endif
15564+
15565 ASM_STAC
15566 1: movl (%rbp),%ebp
15567 _ASM_EXTABLE(1b,ia32_badarg)
15568 ASM_CLAC
15569
15570+#ifdef CONFIG_PAX_MEMORY_UDEREF
15571+ ASM_PAX_CLOSE_USERLAND
15572+#endif
15573+
15574 /*
15575 * Sysenter doesn't filter flags, so we need to clear NT
15576 * ourselves. To save a few cycles, we can check whether
15577@@ -161,8 +206,9 @@ ENTRY(ia32_sysenter_target)
15578 jnz sysenter_fix_flags
15579 sysenter_flags_fixed:
15580
15581- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15582- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15583+ GET_THREAD_INFO(%r11)
15584+ orl $TS_COMPAT,TI_status(%r11)
15585+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15586 CFI_REMEMBER_STATE
15587 jnz sysenter_tracesys
15588 cmpq $(IA32_NR_syscalls-1),%rax
15589@@ -172,15 +218,18 @@ sysenter_do_call:
15590 sysenter_dispatch:
15591 call *ia32_sys_call_table(,%rax,8)
15592 movq %rax,RAX-ARGOFFSET(%rsp)
15593+ GET_THREAD_INFO(%r11)
15594 DISABLE_INTERRUPTS(CLBR_NONE)
15595 TRACE_IRQS_OFF
15596- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15597+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
15598 jnz sysexit_audit
15599 sysexit_from_sys_call:
15600- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15601+ pax_exit_kernel_user
15602+ pax_erase_kstack
15603+ andl $~TS_COMPAT,TI_status(%r11)
15604 /* clear IF, that popfq doesn't enable interrupts early */
15605- andl $~0x200,EFLAGS-R11(%rsp)
15606- movl RIP-R11(%rsp),%edx /* User %eip */
15607+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
15608+ movl RIP(%rsp),%edx /* User %eip */
15609 CFI_REGISTER rip,rdx
15610 RESTORE_ARGS 0,24,0,0,0,0
15611 xorq %r8,%r8
15612@@ -205,6 +254,9 @@ sysexit_from_sys_call:
15613 movl %eax,%esi /* 2nd arg: syscall number */
15614 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
15615 call __audit_syscall_entry
15616+
15617+ pax_erase_kstack
15618+
15619 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
15620 cmpq $(IA32_NR_syscalls-1),%rax
15621 ja ia32_badsys
15622@@ -216,7 +268,7 @@ sysexit_from_sys_call:
15623 .endm
15624
15625 .macro auditsys_exit exit
15626- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15627+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15628 jnz ia32_ret_from_sys_call
15629 TRACE_IRQS_ON
15630 ENABLE_INTERRUPTS(CLBR_NONE)
15631@@ -227,11 +279,12 @@ sysexit_from_sys_call:
15632 1: setbe %al /* 1 if error, 0 if not */
15633 movzbl %al,%edi /* zero-extend that into %edi */
15634 call __audit_syscall_exit
15635+ GET_THREAD_INFO(%r11)
15636 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
15637 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
15638 DISABLE_INTERRUPTS(CLBR_NONE)
15639 TRACE_IRQS_OFF
15640- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15641+ testl %edi,TI_flags(%r11)
15642 jz \exit
15643 CLEAR_RREGS -ARGOFFSET
15644 jmp int_with_check
15645@@ -253,7 +306,7 @@ sysenter_fix_flags:
15646
15647 sysenter_tracesys:
15648 #ifdef CONFIG_AUDITSYSCALL
15649- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15650+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15651 jz sysenter_auditsys
15652 #endif
15653 SAVE_REST
15654@@ -265,6 +318,9 @@ sysenter_tracesys:
15655 RESTORE_REST
15656 cmpq $(IA32_NR_syscalls-1),%rax
15657 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
15658+
15659+ pax_erase_kstack
15660+
15661 jmp sysenter_do_call
15662 CFI_ENDPROC
15663 ENDPROC(ia32_sysenter_target)
15664@@ -292,19 +348,25 @@ ENDPROC(ia32_sysenter_target)
15665 ENTRY(ia32_cstar_target)
15666 CFI_STARTPROC32 simple
15667 CFI_SIGNAL_FRAME
15668- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
15669+ CFI_DEF_CFA rsp,0
15670 CFI_REGISTER rip,rcx
15671 /*CFI_REGISTER rflags,r11*/
15672 SWAPGS_UNSAFE_STACK
15673 movl %esp,%r8d
15674 CFI_REGISTER rsp,r8
15675 movq PER_CPU_VAR(kernel_stack),%rsp
15676+ SAVE_ARGS 8*6,0,0
15677+ pax_enter_kernel_user
15678+
15679+#ifdef CONFIG_PAX_RANDKSTACK
15680+ pax_erase_kstack
15681+#endif
15682+
15683 /*
15684 * No need to follow this irqs on/off section: the syscall
15685 * disabled irqs and here we enable it straight after entry:
15686 */
15687 ENABLE_INTERRUPTS(CLBR_NONE)
15688- SAVE_ARGS 8,0,0
15689 movl %eax,%eax /* zero extension */
15690 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
15691 movq %rcx,RIP-ARGOFFSET(%rsp)
15692@@ -320,12 +382,25 @@ ENTRY(ia32_cstar_target)
15693 /* no need to do an access_ok check here because r8 has been
15694 32bit zero extended */
15695 /* hardware stack frame is complete now */
15696+
15697+#ifdef CONFIG_PAX_MEMORY_UDEREF
15698+ ASM_PAX_OPEN_USERLAND
15699+ movq pax_user_shadow_base,%r8
15700+ addq RSP-ARGOFFSET(%rsp),%r8
15701+#endif
15702+
15703 ASM_STAC
15704 1: movl (%r8),%r9d
15705 _ASM_EXTABLE(1b,ia32_badarg)
15706 ASM_CLAC
15707- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15708- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15709+
15710+#ifdef CONFIG_PAX_MEMORY_UDEREF
15711+ ASM_PAX_CLOSE_USERLAND
15712+#endif
15713+
15714+ GET_THREAD_INFO(%r11)
15715+ orl $TS_COMPAT,TI_status(%r11)
15716+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15717 CFI_REMEMBER_STATE
15718 jnz cstar_tracesys
15719 cmpq $IA32_NR_syscalls-1,%rax
15720@@ -335,13 +410,16 @@ cstar_do_call:
15721 cstar_dispatch:
15722 call *ia32_sys_call_table(,%rax,8)
15723 movq %rax,RAX-ARGOFFSET(%rsp)
15724+ GET_THREAD_INFO(%r11)
15725 DISABLE_INTERRUPTS(CLBR_NONE)
15726 TRACE_IRQS_OFF
15727- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15728+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
15729 jnz sysretl_audit
15730 sysretl_from_sys_call:
15731- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15732- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
15733+ pax_exit_kernel_user
15734+ pax_erase_kstack
15735+ andl $~TS_COMPAT,TI_status(%r11)
15736+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
15737 movl RIP-ARGOFFSET(%rsp),%ecx
15738 CFI_REGISTER rip,rcx
15739 movl EFLAGS-ARGOFFSET(%rsp),%r11d
15740@@ -368,7 +446,7 @@ sysretl_audit:
15741
15742 cstar_tracesys:
15743 #ifdef CONFIG_AUDITSYSCALL
15744- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15745+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15746 jz cstar_auditsys
15747 #endif
15748 xchgl %r9d,%ebp
15749@@ -382,11 +460,19 @@ cstar_tracesys:
15750 xchgl %ebp,%r9d
15751 cmpq $(IA32_NR_syscalls-1),%rax
15752 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
15753+
15754+ pax_erase_kstack
15755+
15756 jmp cstar_do_call
15757 END(ia32_cstar_target)
15758
15759 ia32_badarg:
15760 ASM_CLAC
15761+
15762+#ifdef CONFIG_PAX_MEMORY_UDEREF
15763+ ASM_PAX_CLOSE_USERLAND
15764+#endif
15765+
15766 movq $-EFAULT,%rax
15767 jmp ia32_sysret
15768 CFI_ENDPROC
15769@@ -423,19 +509,26 @@ ENTRY(ia32_syscall)
15770 CFI_REL_OFFSET rip,RIP-RIP
15771 PARAVIRT_ADJUST_EXCEPTION_FRAME
15772 SWAPGS
15773- /*
15774- * No need to follow this irqs on/off section: the syscall
15775- * disabled irqs and here we enable it straight after entry:
15776- */
15777- ENABLE_INTERRUPTS(CLBR_NONE)
15778 movl %eax,%eax
15779 pushq_cfi %rax
15780 cld
15781 /* note the registers are not zero extended to the sf.
15782 this could be a problem. */
15783 SAVE_ARGS 0,1,0
15784- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15785- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15786+ pax_enter_kernel_user
15787+
15788+#ifdef CONFIG_PAX_RANDKSTACK
15789+ pax_erase_kstack
15790+#endif
15791+
15792+ /*
15793+ * No need to follow this irqs on/off section: the syscall
15794+ * disabled irqs and here we enable it straight after entry:
15795+ */
15796+ ENABLE_INTERRUPTS(CLBR_NONE)
15797+ GET_THREAD_INFO(%r11)
15798+ orl $TS_COMPAT,TI_status(%r11)
15799+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15800 jnz ia32_tracesys
15801 cmpq $(IA32_NR_syscalls-1),%rax
15802 ja ia32_badsys
15803@@ -458,6 +551,9 @@ ia32_tracesys:
15804 RESTORE_REST
15805 cmpq $(IA32_NR_syscalls-1),%rax
15806 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
15807+
15808+ pax_erase_kstack
15809+
15810 jmp ia32_do_call
15811 END(ia32_syscall)
15812
15813diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15814index 8e0ceec..af13504 100644
15815--- a/arch/x86/ia32/sys_ia32.c
15816+++ b/arch/x86/ia32/sys_ia32.c
15817@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15818 */
15819 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15820 {
15821- typeof(ubuf->st_uid) uid = 0;
15822- typeof(ubuf->st_gid) gid = 0;
15823+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
15824+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
15825 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15826 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15827 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15828diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15829index 372231c..51b537d 100644
15830--- a/arch/x86/include/asm/alternative-asm.h
15831+++ b/arch/x86/include/asm/alternative-asm.h
15832@@ -18,6 +18,45 @@
15833 .endm
15834 #endif
15835
15836+#ifdef KERNEXEC_PLUGIN
15837+ .macro pax_force_retaddr_bts rip=0
15838+ btsq $63,\rip(%rsp)
15839+ .endm
15840+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15841+ .macro pax_force_retaddr rip=0, reload=0
15842+ btsq $63,\rip(%rsp)
15843+ .endm
15844+ .macro pax_force_fptr ptr
15845+ btsq $63,\ptr
15846+ .endm
15847+ .macro pax_set_fptr_mask
15848+ .endm
15849+#endif
15850+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15851+ .macro pax_force_retaddr rip=0, reload=0
15852+ .if \reload
15853+ pax_set_fptr_mask
15854+ .endif
15855+ orq %r12,\rip(%rsp)
15856+ .endm
15857+ .macro pax_force_fptr ptr
15858+ orq %r12,\ptr
15859+ .endm
15860+ .macro pax_set_fptr_mask
15861+ movabs $0x8000000000000000,%r12
15862+ .endm
15863+#endif
15864+#else
15865+ .macro pax_force_retaddr rip=0, reload=0
15866+ .endm
15867+ .macro pax_force_fptr ptr
15868+ .endm
15869+ .macro pax_force_retaddr_bts rip=0
15870+ .endm
15871+ .macro pax_set_fptr_mask
15872+ .endm
15873+#endif
15874+
15875 .macro altinstruction_entry orig alt feature orig_len alt_len
15876 .long \orig - .
15877 .long \alt - .
15878diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15879index 473bdbe..b1e3377 100644
15880--- a/arch/x86/include/asm/alternative.h
15881+++ b/arch/x86/include/asm/alternative.h
15882@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15883 ".pushsection .discard,\"aw\",@progbits\n" \
15884 DISCARD_ENTRY(1) \
15885 ".popsection\n" \
15886- ".pushsection .altinstr_replacement, \"ax\"\n" \
15887+ ".pushsection .altinstr_replacement, \"a\"\n" \
15888 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15889 ".popsection"
15890
15891@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15892 DISCARD_ENTRY(1) \
15893 DISCARD_ENTRY(2) \
15894 ".popsection\n" \
15895- ".pushsection .altinstr_replacement, \"ax\"\n" \
15896+ ".pushsection .altinstr_replacement, \"a\"\n" \
15897 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15898 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15899 ".popsection"
15900diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15901index 465b309..ab7e51f 100644
15902--- a/arch/x86/include/asm/apic.h
15903+++ b/arch/x86/include/asm/apic.h
15904@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15905
15906 #ifdef CONFIG_X86_LOCAL_APIC
15907
15908-extern unsigned int apic_verbosity;
15909+extern int apic_verbosity;
15910 extern int local_apic_timer_c2_ok;
15911
15912 extern int disable_apic;
15913diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15914index 20370c6..a2eb9b0 100644
15915--- a/arch/x86/include/asm/apm.h
15916+++ b/arch/x86/include/asm/apm.h
15917@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15918 __asm__ __volatile__(APM_DO_ZERO_SEGS
15919 "pushl %%edi\n\t"
15920 "pushl %%ebp\n\t"
15921- "lcall *%%cs:apm_bios_entry\n\t"
15922+ "lcall *%%ss:apm_bios_entry\n\t"
15923 "setc %%al\n\t"
15924 "popl %%ebp\n\t"
15925 "popl %%edi\n\t"
15926@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15927 __asm__ __volatile__(APM_DO_ZERO_SEGS
15928 "pushl %%edi\n\t"
15929 "pushl %%ebp\n\t"
15930- "lcall *%%cs:apm_bios_entry\n\t"
15931+ "lcall *%%ss:apm_bios_entry\n\t"
15932 "setc %%bl\n\t"
15933 "popl %%ebp\n\t"
15934 "popl %%edi\n\t"
15935diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15936index 6dd1c7dd..5a85bf2 100644
15937--- a/arch/x86/include/asm/atomic.h
15938+++ b/arch/x86/include/asm/atomic.h
15939@@ -24,7 +24,18 @@
15940 */
15941 static inline int atomic_read(const atomic_t *v)
15942 {
15943- return (*(volatile int *)&(v)->counter);
15944+ return (*(volatile const int *)&(v)->counter);
15945+}
15946+
15947+/**
15948+ * atomic_read_unchecked - read atomic variable
15949+ * @v: pointer of type atomic_unchecked_t
15950+ *
15951+ * Atomically reads the value of @v.
15952+ */
15953+static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15954+{
15955+ return (*(volatile const int *)&(v)->counter);
15956 }
15957
15958 /**
15959@@ -40,6 +51,18 @@ static inline void atomic_set(atomic_t *v, int i)
15960 }
15961
15962 /**
15963+ * atomic_set_unchecked - set atomic variable
15964+ * @v: pointer of type atomic_unchecked_t
15965+ * @i: required value
15966+ *
15967+ * Atomically sets the value of @v to @i.
15968+ */
15969+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15970+{
15971+ v->counter = i;
15972+}
15973+
15974+/**
15975 * atomic_add - add integer to atomic variable
15976 * @i: integer value to add
15977 * @v: pointer of type atomic_t
15978@@ -48,7 +71,29 @@ static inline void atomic_set(atomic_t *v, int i)
15979 */
15980 static inline void atomic_add(int i, atomic_t *v)
15981 {
15982- asm volatile(LOCK_PREFIX "addl %1,%0"
15983+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
15984+
15985+#ifdef CONFIG_PAX_REFCOUNT
15986+ "jno 0f\n"
15987+ LOCK_PREFIX "subl %1,%0\n"
15988+ "int $4\n0:\n"
15989+ _ASM_EXTABLE(0b, 0b)
15990+#endif
15991+
15992+ : "+m" (v->counter)
15993+ : "ir" (i));
15994+}
15995+
15996+/**
15997+ * atomic_add_unchecked - add integer to atomic variable
15998+ * @i: integer value to add
15999+ * @v: pointer of type atomic_unchecked_t
16000+ *
16001+ * Atomically adds @i to @v.
16002+ */
16003+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
16004+{
16005+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
16006 : "+m" (v->counter)
16007 : "ir" (i));
16008 }
16009@@ -62,7 +107,29 @@ static inline void atomic_add(int i, atomic_t *v)
16010 */
16011 static inline void atomic_sub(int i, atomic_t *v)
16012 {
16013- asm volatile(LOCK_PREFIX "subl %1,%0"
16014+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
16015+
16016+#ifdef CONFIG_PAX_REFCOUNT
16017+ "jno 0f\n"
16018+ LOCK_PREFIX "addl %1,%0\n"
16019+ "int $4\n0:\n"
16020+ _ASM_EXTABLE(0b, 0b)
16021+#endif
16022+
16023+ : "+m" (v->counter)
16024+ : "ir" (i));
16025+}
16026+
16027+/**
16028+ * atomic_sub_unchecked - subtract integer from atomic variable
16029+ * @i: integer value to subtract
16030+ * @v: pointer of type atomic_unchecked_t
16031+ *
16032+ * Atomically subtracts @i from @v.
16033+ */
16034+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
16035+{
16036+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
16037 : "+m" (v->counter)
16038 : "ir" (i));
16039 }
16040@@ -78,7 +145,7 @@ static inline void atomic_sub(int i, atomic_t *v)
16041 */
16042 static inline int atomic_sub_and_test(int i, atomic_t *v)
16043 {
16044- GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
16045+ GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
16046 }
16047
16048 /**
16049@@ -89,7 +156,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
16050 */
16051 static inline void atomic_inc(atomic_t *v)
16052 {
16053- asm volatile(LOCK_PREFIX "incl %0"
16054+ asm volatile(LOCK_PREFIX "incl %0\n"
16055+
16056+#ifdef CONFIG_PAX_REFCOUNT
16057+ "jno 0f\n"
16058+ LOCK_PREFIX "decl %0\n"
16059+ "int $4\n0:\n"
16060+ _ASM_EXTABLE(0b, 0b)
16061+#endif
16062+
16063+ : "+m" (v->counter));
16064+}
16065+
16066+/**
16067+ * atomic_inc_unchecked - increment atomic variable
16068+ * @v: pointer of type atomic_unchecked_t
16069+ *
16070+ * Atomically increments @v by 1.
16071+ */
16072+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
16073+{
16074+ asm volatile(LOCK_PREFIX "incl %0\n"
16075 : "+m" (v->counter));
16076 }
16077
16078@@ -101,7 +188,27 @@ static inline void atomic_inc(atomic_t *v)
16079 */
16080 static inline void atomic_dec(atomic_t *v)
16081 {
16082- asm volatile(LOCK_PREFIX "decl %0"
16083+ asm volatile(LOCK_PREFIX "decl %0\n"
16084+
16085+#ifdef CONFIG_PAX_REFCOUNT
16086+ "jno 0f\n"
16087+ LOCK_PREFIX "incl %0\n"
16088+ "int $4\n0:\n"
16089+ _ASM_EXTABLE(0b, 0b)
16090+#endif
16091+
16092+ : "+m" (v->counter));
16093+}
16094+
16095+/**
16096+ * atomic_dec_unchecked - decrement atomic variable
16097+ * @v: pointer of type atomic_unchecked_t
16098+ *
16099+ * Atomically decrements @v by 1.
16100+ */
16101+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
16102+{
16103+ asm volatile(LOCK_PREFIX "decl %0\n"
16104 : "+m" (v->counter));
16105 }
16106
16107@@ -115,7 +222,7 @@ static inline void atomic_dec(atomic_t *v)
16108 */
16109 static inline int atomic_dec_and_test(atomic_t *v)
16110 {
16111- GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
16112+ GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
16113 }
16114
16115 /**
16116@@ -128,7 +235,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
16117 */
16118 static inline int atomic_inc_and_test(atomic_t *v)
16119 {
16120- GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
16121+ GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
16122+}
16123+
16124+/**
16125+ * atomic_inc_and_test_unchecked - increment and test
16126+ * @v: pointer of type atomic_unchecked_t
16127+ *
16128+ * Atomically increments @v by 1
16129+ * and returns true if the result is zero, or false for all
16130+ * other cases.
16131+ */
16132+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
16133+{
16134+ GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
16135 }
16136
16137 /**
16138@@ -142,7 +262,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
16139 */
16140 static inline int atomic_add_negative(int i, atomic_t *v)
16141 {
16142- GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
16143+ GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
16144 }
16145
16146 /**
16147@@ -152,7 +272,19 @@ static inline int atomic_add_negative(int i, atomic_t *v)
16148 *
16149 * Atomically adds @i to @v and returns @i + @v
16150 */
16151-static inline int atomic_add_return(int i, atomic_t *v)
16152+static inline int __intentional_overflow(-1) atomic_add_return(int i, atomic_t *v)
16153+{
16154+ return i + xadd_check_overflow(&v->counter, i);
16155+}
16156+
16157+/**
16158+ * atomic_add_return_unchecked - add integer and return
16159+ * @i: integer value to add
16160+ * @v: pointer of type atomic_unchecked_t
16161+ *
16162+ * Atomically adds @i to @v and returns @i + @v
16163+ */
16164+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
16165 {
16166 return i + xadd(&v->counter, i);
16167 }
16168@@ -164,15 +296,24 @@ static inline int atomic_add_return(int i, atomic_t *v)
16169 *
16170 * Atomically subtracts @i from @v and returns @v - @i
16171 */
16172-static inline int atomic_sub_return(int i, atomic_t *v)
16173+static inline int __intentional_overflow(-1) atomic_sub_return(int i, atomic_t *v)
16174 {
16175 return atomic_add_return(-i, v);
16176 }
16177
16178 #define atomic_inc_return(v) (atomic_add_return(1, v))
16179+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
16180+{
16181+ return atomic_add_return_unchecked(1, v);
16182+}
16183 #define atomic_dec_return(v) (atomic_sub_return(1, v))
16184
16185-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
16186+static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
16187+{
16188+ return cmpxchg(&v->counter, old, new);
16189+}
16190+
16191+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
16192 {
16193 return cmpxchg(&v->counter, old, new);
16194 }
16195@@ -182,6 +323,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
16196 return xchg(&v->counter, new);
16197 }
16198
16199+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
16200+{
16201+ return xchg(&v->counter, new);
16202+}
16203+
16204 /**
16205 * __atomic_add_unless - add unless the number is already a given value
16206 * @v: pointer of type atomic_t
16207@@ -191,14 +337,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
16208 * Atomically adds @a to @v, so long as @v was not already @u.
16209 * Returns the old value of @v.
16210 */
16211-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
16212+static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
16213 {
16214- int c, old;
16215+ int c, old, new;
16216 c = atomic_read(v);
16217 for (;;) {
16218- if (unlikely(c == (u)))
16219+ if (unlikely(c == u))
16220 break;
16221- old = atomic_cmpxchg((v), c, c + (a));
16222+
16223+ asm volatile("addl %2,%0\n"
16224+
16225+#ifdef CONFIG_PAX_REFCOUNT
16226+ "jno 0f\n"
16227+ "subl %2,%0\n"
16228+ "int $4\n0:\n"
16229+ _ASM_EXTABLE(0b, 0b)
16230+#endif
16231+
16232+ : "=r" (new)
16233+ : "0" (c), "ir" (a));
16234+
16235+ old = atomic_cmpxchg(v, c, new);
16236 if (likely(old == c))
16237 break;
16238 c = old;
16239@@ -207,6 +366,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
16240 }
16241
16242 /**
16243+ * atomic_inc_not_zero_hint - increment if not null
16244+ * @v: pointer of type atomic_t
16245+ * @hint: probable value of the atomic before the increment
16246+ *
16247+ * This version of atomic_inc_not_zero() gives a hint of probable
16248+ * value of the atomic. This helps processor to not read the memory
16249+ * before doing the atomic read/modify/write cycle, lowering
16250+ * number of bus transactions on some arches.
16251+ *
16252+ * Returns: 0 if increment was not done, 1 otherwise.
16253+ */
16254+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
16255+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
16256+{
16257+ int val, c = hint, new;
16258+
16259+ /* sanity test, should be removed by compiler if hint is a constant */
16260+ if (!hint)
16261+ return __atomic_add_unless(v, 1, 0);
16262+
16263+ do {
16264+ asm volatile("incl %0\n"
16265+
16266+#ifdef CONFIG_PAX_REFCOUNT
16267+ "jno 0f\n"
16268+ "decl %0\n"
16269+ "int $4\n0:\n"
16270+ _ASM_EXTABLE(0b, 0b)
16271+#endif
16272+
16273+ : "=r" (new)
16274+ : "0" (c));
16275+
16276+ val = atomic_cmpxchg(v, c, new);
16277+ if (val == c)
16278+ return 1;
16279+ c = val;
16280+ } while (c);
16281+
16282+ return 0;
16283+}
16284+
16285+/**
16286 * atomic_inc_short - increment of a short integer
16287 * @v: pointer to type int
16288 *
16289@@ -235,14 +437,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
16290 #endif
16291
16292 /* These are x86-specific, used by some header files */
16293-#define atomic_clear_mask(mask, addr) \
16294- asm volatile(LOCK_PREFIX "andl %0,%1" \
16295- : : "r" (~(mask)), "m" (*(addr)) : "memory")
16296+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
16297+{
16298+ asm volatile(LOCK_PREFIX "andl %1,%0"
16299+ : "+m" (v->counter)
16300+ : "r" (~(mask))
16301+ : "memory");
16302+}
16303
16304-#define atomic_set_mask(mask, addr) \
16305- asm volatile(LOCK_PREFIX "orl %0,%1" \
16306- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
16307- : "memory")
16308+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
16309+{
16310+ asm volatile(LOCK_PREFIX "andl %1,%0"
16311+ : "+m" (v->counter)
16312+ : "r" (~(mask))
16313+ : "memory");
16314+}
16315+
16316+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
16317+{
16318+ asm volatile(LOCK_PREFIX "orl %1,%0"
16319+ : "+m" (v->counter)
16320+ : "r" (mask)
16321+ : "memory");
16322+}
16323+
16324+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
16325+{
16326+ asm volatile(LOCK_PREFIX "orl %1,%0"
16327+ : "+m" (v->counter)
16328+ : "r" (mask)
16329+ : "memory");
16330+}
16331
16332 #ifdef CONFIG_X86_32
16333 # include <asm/atomic64_32.h>
16334diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
16335index b154de7..bf18a5a 100644
16336--- a/arch/x86/include/asm/atomic64_32.h
16337+++ b/arch/x86/include/asm/atomic64_32.h
16338@@ -12,6 +12,14 @@ typedef struct {
16339 u64 __aligned(8) counter;
16340 } atomic64_t;
16341
16342+#ifdef CONFIG_PAX_REFCOUNT
16343+typedef struct {
16344+ u64 __aligned(8) counter;
16345+} atomic64_unchecked_t;
16346+#else
16347+typedef atomic64_t atomic64_unchecked_t;
16348+#endif
16349+
16350 #define ATOMIC64_INIT(val) { (val) }
16351
16352 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
16353@@ -37,21 +45,31 @@ typedef struct {
16354 ATOMIC64_DECL_ONE(sym##_386)
16355
16356 ATOMIC64_DECL_ONE(add_386);
16357+ATOMIC64_DECL_ONE(add_unchecked_386);
16358 ATOMIC64_DECL_ONE(sub_386);
16359+ATOMIC64_DECL_ONE(sub_unchecked_386);
16360 ATOMIC64_DECL_ONE(inc_386);
16361+ATOMIC64_DECL_ONE(inc_unchecked_386);
16362 ATOMIC64_DECL_ONE(dec_386);
16363+ATOMIC64_DECL_ONE(dec_unchecked_386);
16364 #endif
16365
16366 #define alternative_atomic64(f, out, in...) \
16367 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
16368
16369 ATOMIC64_DECL(read);
16370+ATOMIC64_DECL(read_unchecked);
16371 ATOMIC64_DECL(set);
16372+ATOMIC64_DECL(set_unchecked);
16373 ATOMIC64_DECL(xchg);
16374 ATOMIC64_DECL(add_return);
16375+ATOMIC64_DECL(add_return_unchecked);
16376 ATOMIC64_DECL(sub_return);
16377+ATOMIC64_DECL(sub_return_unchecked);
16378 ATOMIC64_DECL(inc_return);
16379+ATOMIC64_DECL(inc_return_unchecked);
16380 ATOMIC64_DECL(dec_return);
16381+ATOMIC64_DECL(dec_return_unchecked);
16382 ATOMIC64_DECL(dec_if_positive);
16383 ATOMIC64_DECL(inc_not_zero);
16384 ATOMIC64_DECL(add_unless);
16385@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
16386 }
16387
16388 /**
16389+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
16390+ * @p: pointer to type atomic64_unchecked_t
16391+ * @o: expected value
16392+ * @n: new value
16393+ *
16394+ * Atomically sets @v to @n if it was equal to @o and returns
16395+ * the old value.
16396+ */
16397+
16398+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
16399+{
16400+ return cmpxchg64(&v->counter, o, n);
16401+}
16402+
16403+/**
16404 * atomic64_xchg - xchg atomic64 variable
16405 * @v: pointer to type atomic64_t
16406 * @n: value to assign
16407@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
16408 }
16409
16410 /**
16411+ * atomic64_set_unchecked - set atomic64 variable
16412+ * @v: pointer to type atomic64_unchecked_t
16413+ * @n: value to assign
16414+ *
16415+ * Atomically sets the value of @v to @n.
16416+ */
16417+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
16418+{
16419+ unsigned high = (unsigned)(i >> 32);
16420+ unsigned low = (unsigned)i;
16421+ alternative_atomic64(set, /* no output */,
16422+ "S" (v), "b" (low), "c" (high)
16423+ : "eax", "edx", "memory");
16424+}
16425+
16426+/**
16427 * atomic64_read - read atomic64 variable
16428 * @v: pointer to type atomic64_t
16429 *
16430@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
16431 }
16432
16433 /**
16434+ * atomic64_read_unchecked - read atomic64 variable
16435+ * @v: pointer to type atomic64_unchecked_t
16436+ *
16437+ * Atomically reads the value of @v and returns it.
16438+ */
16439+static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
16440+{
16441+ long long r;
16442+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
16443+ return r;
16444+ }
16445+
16446+/**
16447 * atomic64_add_return - add and return
16448 * @i: integer value to add
16449 * @v: pointer to type atomic64_t
16450@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
16451 return i;
16452 }
16453
16454+/**
16455+ * atomic64_add_return_unchecked - add and return
16456+ * @i: integer value to add
16457+ * @v: pointer to type atomic64_unchecked_t
16458+ *
16459+ * Atomically adds @i to @v and returns @i + *@v
16460+ */
16461+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
16462+{
16463+ alternative_atomic64(add_return_unchecked,
16464+ ASM_OUTPUT2("+A" (i), "+c" (v)),
16465+ ASM_NO_INPUT_CLOBBER("memory"));
16466+ return i;
16467+}
16468+
16469 /*
16470 * Other variants with different arithmetic operators:
16471 */
16472@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
16473 return a;
16474 }
16475
16476+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
16477+{
16478+ long long a;
16479+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
16480+ "S" (v) : "memory", "ecx");
16481+ return a;
16482+}
16483+
16484 static inline long long atomic64_dec_return(atomic64_t *v)
16485 {
16486 long long a;
16487@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
16488 }
16489
16490 /**
16491+ * atomic64_add_unchecked - add integer to atomic64 variable
16492+ * @i: integer value to add
16493+ * @v: pointer to type atomic64_unchecked_t
16494+ *
16495+ * Atomically adds @i to @v.
16496+ */
16497+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
16498+{
16499+ __alternative_atomic64(add_unchecked, add_return_unchecked,
16500+ ASM_OUTPUT2("+A" (i), "+c" (v)),
16501+ ASM_NO_INPUT_CLOBBER("memory"));
16502+ return i;
16503+}
16504+
16505+/**
16506 * atomic64_sub - subtract the atomic64 variable
16507 * @i: integer value to subtract
16508 * @v: pointer to type atomic64_t
16509diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
16510index 46e9052..ae45136 100644
16511--- a/arch/x86/include/asm/atomic64_64.h
16512+++ b/arch/x86/include/asm/atomic64_64.h
16513@@ -18,7 +18,19 @@
16514 */
16515 static inline long atomic64_read(const atomic64_t *v)
16516 {
16517- return (*(volatile long *)&(v)->counter);
16518+ return (*(volatile const long *)&(v)->counter);
16519+}
16520+
16521+/**
16522+ * atomic64_read_unchecked - read atomic64 variable
16523+ * @v: pointer of type atomic64_unchecked_t
16524+ *
16525+ * Atomically reads the value of @v.
16526+ * Doesn't imply a read memory barrier.
16527+ */
16528+static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
16529+{
16530+ return (*(volatile const long *)&(v)->counter);
16531 }
16532
16533 /**
16534@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
16535 }
16536
16537 /**
16538+ * atomic64_set_unchecked - set atomic64 variable
16539+ * @v: pointer to type atomic64_unchecked_t
16540+ * @i: required value
16541+ *
16542+ * Atomically sets the value of @v to @i.
16543+ */
16544+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
16545+{
16546+ v->counter = i;
16547+}
16548+
16549+/**
16550 * atomic64_add - add integer to atomic64 variable
16551 * @i: integer value to add
16552 * @v: pointer to type atomic64_t
16553@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
16554 */
16555 static inline void atomic64_add(long i, atomic64_t *v)
16556 {
16557+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
16558+
16559+#ifdef CONFIG_PAX_REFCOUNT
16560+ "jno 0f\n"
16561+ LOCK_PREFIX "subq %1,%0\n"
16562+ "int $4\n0:\n"
16563+ _ASM_EXTABLE(0b, 0b)
16564+#endif
16565+
16566+ : "=m" (v->counter)
16567+ : "er" (i), "m" (v->counter));
16568+}
16569+
16570+/**
16571+ * atomic64_add_unchecked - add integer to atomic64 variable
16572+ * @i: integer value to add
16573+ * @v: pointer to type atomic64_unchecked_t
16574+ *
16575+ * Atomically adds @i to @v.
16576+ */
16577+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
16578+{
16579 asm volatile(LOCK_PREFIX "addq %1,%0"
16580 : "=m" (v->counter)
16581 : "er" (i), "m" (v->counter));
16582@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
16583 */
16584 static inline void atomic64_sub(long i, atomic64_t *v)
16585 {
16586- asm volatile(LOCK_PREFIX "subq %1,%0"
16587+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
16588+
16589+#ifdef CONFIG_PAX_REFCOUNT
16590+ "jno 0f\n"
16591+ LOCK_PREFIX "addq %1,%0\n"
16592+ "int $4\n0:\n"
16593+ _ASM_EXTABLE(0b, 0b)
16594+#endif
16595+
16596+ : "=m" (v->counter)
16597+ : "er" (i), "m" (v->counter));
16598+}
16599+
16600+/**
16601+ * atomic64_sub_unchecked - subtract the atomic64 variable
16602+ * @i: integer value to subtract
16603+ * @v: pointer to type atomic64_unchecked_t
16604+ *
16605+ * Atomically subtracts @i from @v.
16606+ */
16607+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
16608+{
16609+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
16610 : "=m" (v->counter)
16611 : "er" (i), "m" (v->counter));
16612 }
16613@@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
16614 */
16615 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
16616 {
16617- GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
16618+ GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
16619 }
16620
16621 /**
16622@@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
16623 */
16624 static inline void atomic64_inc(atomic64_t *v)
16625 {
16626+ asm volatile(LOCK_PREFIX "incq %0\n"
16627+
16628+#ifdef CONFIG_PAX_REFCOUNT
16629+ "jno 0f\n"
16630+ LOCK_PREFIX "decq %0\n"
16631+ "int $4\n0:\n"
16632+ _ASM_EXTABLE(0b, 0b)
16633+#endif
16634+
16635+ : "=m" (v->counter)
16636+ : "m" (v->counter));
16637+}
16638+
16639+/**
16640+ * atomic64_inc_unchecked - increment atomic64 variable
16641+ * @v: pointer to type atomic64_unchecked_t
16642+ *
16643+ * Atomically increments @v by 1.
16644+ */
16645+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
16646+{
16647 asm volatile(LOCK_PREFIX "incq %0"
16648 : "=m" (v->counter)
16649 : "m" (v->counter));
16650@@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
16651 */
16652 static inline void atomic64_dec(atomic64_t *v)
16653 {
16654- asm volatile(LOCK_PREFIX "decq %0"
16655+ asm volatile(LOCK_PREFIX "decq %0\n"
16656+
16657+#ifdef CONFIG_PAX_REFCOUNT
16658+ "jno 0f\n"
16659+ LOCK_PREFIX "incq %0\n"
16660+ "int $4\n0:\n"
16661+ _ASM_EXTABLE(0b, 0b)
16662+#endif
16663+
16664+ : "=m" (v->counter)
16665+ : "m" (v->counter));
16666+}
16667+
16668+/**
16669+ * atomic64_dec_unchecked - decrement atomic64 variable
16670+ * @v: pointer to type atomic64_t
16671+ *
16672+ * Atomically decrements @v by 1.
16673+ */
16674+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
16675+{
16676+ asm volatile(LOCK_PREFIX "decq %0\n"
16677 : "=m" (v->counter)
16678 : "m" (v->counter));
16679 }
16680@@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
16681 */
16682 static inline int atomic64_dec_and_test(atomic64_t *v)
16683 {
16684- GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
16685+ GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
16686 }
16687
16688 /**
16689@@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
16690 */
16691 static inline int atomic64_inc_and_test(atomic64_t *v)
16692 {
16693- GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
16694+ GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
16695 }
16696
16697 /**
16698@@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
16699 */
16700 static inline int atomic64_add_negative(long i, atomic64_t *v)
16701 {
16702- GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
16703+ GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
16704 }
16705
16706 /**
16707@@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
16708 */
16709 static inline long atomic64_add_return(long i, atomic64_t *v)
16710 {
16711+ return i + xadd_check_overflow(&v->counter, i);
16712+}
16713+
16714+/**
16715+ * atomic64_add_return_unchecked - add and return
16716+ * @i: integer value to add
16717+ * @v: pointer to type atomic64_unchecked_t
16718+ *
16719+ * Atomically adds @i to @v and returns @i + @v
16720+ */
16721+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
16722+{
16723 return i + xadd(&v->counter, i);
16724 }
16725
16726@@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
16727 }
16728
16729 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
16730+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
16731+{
16732+ return atomic64_add_return_unchecked(1, v);
16733+}
16734 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
16735
16736 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16737@@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16738 return cmpxchg(&v->counter, old, new);
16739 }
16740
16741+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
16742+{
16743+ return cmpxchg(&v->counter, old, new);
16744+}
16745+
16746 static inline long atomic64_xchg(atomic64_t *v, long new)
16747 {
16748 return xchg(&v->counter, new);
16749@@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
16750 */
16751 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
16752 {
16753- long c, old;
16754+ long c, old, new;
16755 c = atomic64_read(v);
16756 for (;;) {
16757- if (unlikely(c == (u)))
16758+ if (unlikely(c == u))
16759 break;
16760- old = atomic64_cmpxchg((v), c, c + (a));
16761+
16762+ asm volatile("add %2,%0\n"
16763+
16764+#ifdef CONFIG_PAX_REFCOUNT
16765+ "jno 0f\n"
16766+ "sub %2,%0\n"
16767+ "int $4\n0:\n"
16768+ _ASM_EXTABLE(0b, 0b)
16769+#endif
16770+
16771+ : "=r" (new)
16772+ : "0" (c), "ir" (a));
16773+
16774+ old = atomic64_cmpxchg(v, c, new);
16775 if (likely(old == c))
16776 break;
16777 c = old;
16778 }
16779- return c != (u);
16780+ return c != u;
16781 }
16782
16783 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
16784diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
16785index 0f4460b..fa1ee19 100644
16786--- a/arch/x86/include/asm/barrier.h
16787+++ b/arch/x86/include/asm/barrier.h
16788@@ -107,7 +107,7 @@
16789 do { \
16790 compiletime_assert_atomic_type(*p); \
16791 smp_mb(); \
16792- ACCESS_ONCE(*p) = (v); \
16793+ ACCESS_ONCE_RW(*p) = (v); \
16794 } while (0)
16795
16796 #define smp_load_acquire(p) \
16797@@ -124,7 +124,7 @@ do { \
16798 do { \
16799 compiletime_assert_atomic_type(*p); \
16800 barrier(); \
16801- ACCESS_ONCE(*p) = (v); \
16802+ ACCESS_ONCE_RW(*p) = (v); \
16803 } while (0)
16804
16805 #define smp_load_acquire(p) \
16806diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
16807index cfe3b95..d01b118 100644
16808--- a/arch/x86/include/asm/bitops.h
16809+++ b/arch/x86/include/asm/bitops.h
16810@@ -50,7 +50,7 @@
16811 * a mask operation on a byte.
16812 */
16813 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16814-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16815+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16816 #define CONST_MASK(nr) (1 << ((nr) & 7))
16817
16818 /**
16819@@ -203,7 +203,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16820 */
16821 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16822 {
16823- GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16824+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16825 }
16826
16827 /**
16828@@ -249,7 +249,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16829 */
16830 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16831 {
16832- GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16833+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16834 }
16835
16836 /**
16837@@ -302,7 +302,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16838 */
16839 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16840 {
16841- GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16842+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16843 }
16844
16845 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16846@@ -343,7 +343,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16847 *
16848 * Undefined if no bit exists, so code should check against 0 first.
16849 */
16850-static inline unsigned long __ffs(unsigned long word)
16851+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16852 {
16853 asm("rep; bsf %1,%0"
16854 : "=r" (word)
16855@@ -357,7 +357,7 @@ static inline unsigned long __ffs(unsigned long word)
16856 *
16857 * Undefined if no zero exists, so code should check against ~0UL first.
16858 */
16859-static inline unsigned long ffz(unsigned long word)
16860+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16861 {
16862 asm("rep; bsf %1,%0"
16863 : "=r" (word)
16864@@ -371,7 +371,7 @@ static inline unsigned long ffz(unsigned long word)
16865 *
16866 * Undefined if no set bit exists, so code should check against 0 first.
16867 */
16868-static inline unsigned long __fls(unsigned long word)
16869+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16870 {
16871 asm("bsr %1,%0"
16872 : "=r" (word)
16873@@ -434,7 +434,7 @@ static inline int ffs(int x)
16874 * set bit if value is nonzero. The last (most significant) bit is
16875 * at position 32.
16876 */
16877-static inline int fls(int x)
16878+static inline int __intentional_overflow(-1) fls(int x)
16879 {
16880 int r;
16881
16882@@ -476,7 +476,7 @@ static inline int fls(int x)
16883 * at position 64.
16884 */
16885 #ifdef CONFIG_X86_64
16886-static __always_inline int fls64(__u64 x)
16887+static __always_inline __intentional_overflow(-1) int fls64(__u64 x)
16888 {
16889 int bitpos = -1;
16890 /*
16891diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16892index 4fa687a..60f2d39 100644
16893--- a/arch/x86/include/asm/boot.h
16894+++ b/arch/x86/include/asm/boot.h
16895@@ -6,10 +6,15 @@
16896 #include <uapi/asm/boot.h>
16897
16898 /* Physical address where kernel should be loaded. */
16899-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16900+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16901 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16902 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16903
16904+#ifndef __ASSEMBLY__
16905+extern unsigned char __LOAD_PHYSICAL_ADDR[];
16906+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16907+#endif
16908+
16909 /* Minimum kernel alignment, as a power of two */
16910 #ifdef CONFIG_X86_64
16911 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16912diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16913index 48f99f1..d78ebf9 100644
16914--- a/arch/x86/include/asm/cache.h
16915+++ b/arch/x86/include/asm/cache.h
16916@@ -5,12 +5,13 @@
16917
16918 /* L1 cache line size */
16919 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16920-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16921+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16922
16923 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16924+#define __read_only __attribute__((__section__(".data..read_only")))
16925
16926 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16927-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16928+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16929
16930 #ifdef CONFIG_X86_VSMP
16931 #ifdef CONFIG_SMP
16932diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16933index 9863ee3..4a1f8e1 100644
16934--- a/arch/x86/include/asm/cacheflush.h
16935+++ b/arch/x86/include/asm/cacheflush.h
16936@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16937 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16938
16939 if (pg_flags == _PGMT_DEFAULT)
16940- return -1;
16941+ return ~0UL;
16942 else if (pg_flags == _PGMT_WC)
16943 return _PAGE_CACHE_WC;
16944 else if (pg_flags == _PGMT_UC_MINUS)
16945diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16946index cb4c73b..c473c29 100644
16947--- a/arch/x86/include/asm/calling.h
16948+++ b/arch/x86/include/asm/calling.h
16949@@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
16950 #define RSP 152
16951 #define SS 160
16952
16953-#define ARGOFFSET R11
16954-#define SWFRAME ORIG_RAX
16955+#define ARGOFFSET R15
16956
16957 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
16958- subq $9*8+\addskip, %rsp
16959- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16960- movq_cfi rdi, 8*8
16961- movq_cfi rsi, 7*8
16962- movq_cfi rdx, 6*8
16963+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16964+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16965+ movq_cfi rdi, RDI
16966+ movq_cfi rsi, RSI
16967+ movq_cfi rdx, RDX
16968
16969 .if \save_rcx
16970- movq_cfi rcx, 5*8
16971+ movq_cfi rcx, RCX
16972 .endif
16973
16974- movq_cfi rax, 4*8
16975+ movq_cfi rax, RAX
16976
16977 .if \save_r891011
16978- movq_cfi r8, 3*8
16979- movq_cfi r9, 2*8
16980- movq_cfi r10, 1*8
16981- movq_cfi r11, 0*8
16982+ movq_cfi r8, R8
16983+ movq_cfi r9, R9
16984+ movq_cfi r10, R10
16985+ movq_cfi r11, R11
16986 .endif
16987
16988+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16989+ movq_cfi r12, R12
16990+#endif
16991+
16992 .endm
16993
16994-#define ARG_SKIP (9*8)
16995+#define ARG_SKIP ORIG_RAX
16996
16997 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
16998 rstor_r8910=1, rstor_rdx=1
16999+
17000+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
17001+ movq_cfi_restore R12, r12
17002+#endif
17003+
17004 .if \rstor_r11
17005- movq_cfi_restore 0*8, r11
17006+ movq_cfi_restore R11, r11
17007 .endif
17008
17009 .if \rstor_r8910
17010- movq_cfi_restore 1*8, r10
17011- movq_cfi_restore 2*8, r9
17012- movq_cfi_restore 3*8, r8
17013+ movq_cfi_restore R10, r10
17014+ movq_cfi_restore R9, r9
17015+ movq_cfi_restore R8, r8
17016 .endif
17017
17018 .if \rstor_rax
17019- movq_cfi_restore 4*8, rax
17020+ movq_cfi_restore RAX, rax
17021 .endif
17022
17023 .if \rstor_rcx
17024- movq_cfi_restore 5*8, rcx
17025+ movq_cfi_restore RCX, rcx
17026 .endif
17027
17028 .if \rstor_rdx
17029- movq_cfi_restore 6*8, rdx
17030+ movq_cfi_restore RDX, rdx
17031 .endif
17032
17033- movq_cfi_restore 7*8, rsi
17034- movq_cfi_restore 8*8, rdi
17035+ movq_cfi_restore RSI, rsi
17036+ movq_cfi_restore RDI, rdi
17037
17038- .if ARG_SKIP+\addskip > 0
17039- addq $ARG_SKIP+\addskip, %rsp
17040- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
17041+ .if ORIG_RAX+\addskip > 0
17042+ addq $ORIG_RAX+\addskip, %rsp
17043+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
17044 .endif
17045 .endm
17046
17047- .macro LOAD_ARGS offset, skiprax=0
17048- movq \offset(%rsp), %r11
17049- movq \offset+8(%rsp), %r10
17050- movq \offset+16(%rsp), %r9
17051- movq \offset+24(%rsp), %r8
17052- movq \offset+40(%rsp), %rcx
17053- movq \offset+48(%rsp), %rdx
17054- movq \offset+56(%rsp), %rsi
17055- movq \offset+64(%rsp), %rdi
17056+ .macro LOAD_ARGS skiprax=0
17057+ movq R11(%rsp), %r11
17058+ movq R10(%rsp), %r10
17059+ movq R9(%rsp), %r9
17060+ movq R8(%rsp), %r8
17061+ movq RCX(%rsp), %rcx
17062+ movq RDX(%rsp), %rdx
17063+ movq RSI(%rsp), %rsi
17064+ movq RDI(%rsp), %rdi
17065 .if \skiprax
17066 .else
17067- movq \offset+72(%rsp), %rax
17068+ movq RAX(%rsp), %rax
17069 .endif
17070 .endm
17071
17072-#define REST_SKIP (6*8)
17073-
17074 .macro SAVE_REST
17075- subq $REST_SKIP, %rsp
17076- CFI_ADJUST_CFA_OFFSET REST_SKIP
17077- movq_cfi rbx, 5*8
17078- movq_cfi rbp, 4*8
17079- movq_cfi r12, 3*8
17080- movq_cfi r13, 2*8
17081- movq_cfi r14, 1*8
17082- movq_cfi r15, 0*8
17083+ movq_cfi rbx, RBX
17084+ movq_cfi rbp, RBP
17085+
17086+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
17087+ movq_cfi r12, R12
17088+#endif
17089+
17090+ movq_cfi r13, R13
17091+ movq_cfi r14, R14
17092+ movq_cfi r15, R15
17093 .endm
17094
17095 .macro RESTORE_REST
17096- movq_cfi_restore 0*8, r15
17097- movq_cfi_restore 1*8, r14
17098- movq_cfi_restore 2*8, r13
17099- movq_cfi_restore 3*8, r12
17100- movq_cfi_restore 4*8, rbp
17101- movq_cfi_restore 5*8, rbx
17102- addq $REST_SKIP, %rsp
17103- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
17104+ movq_cfi_restore R15, r15
17105+ movq_cfi_restore R14, r14
17106+ movq_cfi_restore R13, r13
17107+
17108+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
17109+ movq_cfi_restore R12, r12
17110+#endif
17111+
17112+ movq_cfi_restore RBP, rbp
17113+ movq_cfi_restore RBX, rbx
17114 .endm
17115
17116 .macro SAVE_ALL
17117diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
17118index f50de69..2b0a458 100644
17119--- a/arch/x86/include/asm/checksum_32.h
17120+++ b/arch/x86/include/asm/checksum_32.h
17121@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
17122 int len, __wsum sum,
17123 int *src_err_ptr, int *dst_err_ptr);
17124
17125+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
17126+ int len, __wsum sum,
17127+ int *src_err_ptr, int *dst_err_ptr);
17128+
17129+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
17130+ int len, __wsum sum,
17131+ int *src_err_ptr, int *dst_err_ptr);
17132+
17133 /*
17134 * Note: when you get a NULL pointer exception here this means someone
17135 * passed in an incorrect kernel address to one of these functions.
17136@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
17137
17138 might_sleep();
17139 stac();
17140- ret = csum_partial_copy_generic((__force void *)src, dst,
17141+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
17142 len, sum, err_ptr, NULL);
17143 clac();
17144
17145@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
17146 might_sleep();
17147 if (access_ok(VERIFY_WRITE, dst, len)) {
17148 stac();
17149- ret = csum_partial_copy_generic(src, (__force void *)dst,
17150+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
17151 len, sum, NULL, err_ptr);
17152 clac();
17153 return ret;
17154diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
17155index 99c105d7..2f667ac 100644
17156--- a/arch/x86/include/asm/cmpxchg.h
17157+++ b/arch/x86/include/asm/cmpxchg.h
17158@@ -16,8 +16,12 @@ extern void __cmpxchg_wrong_size(void)
17159 __compiletime_error("Bad argument size for cmpxchg");
17160 extern void __xadd_wrong_size(void)
17161 __compiletime_error("Bad argument size for xadd");
17162+extern void __xadd_check_overflow_wrong_size(void)
17163+ __compiletime_error("Bad argument size for xadd_check_overflow");
17164 extern void __add_wrong_size(void)
17165 __compiletime_error("Bad argument size for add");
17166+extern void __add_check_overflow_wrong_size(void)
17167+ __compiletime_error("Bad argument size for add_check_overflow");
17168
17169 /*
17170 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
17171@@ -69,6 +73,38 @@ extern void __add_wrong_size(void)
17172 __ret; \
17173 })
17174
17175+#ifdef CONFIG_PAX_REFCOUNT
17176+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
17177+ ({ \
17178+ __typeof__ (*(ptr)) __ret = (arg); \
17179+ switch (sizeof(*(ptr))) { \
17180+ case __X86_CASE_L: \
17181+ asm volatile (lock #op "l %0, %1\n" \
17182+ "jno 0f\n" \
17183+ "mov %0,%1\n" \
17184+ "int $4\n0:\n" \
17185+ _ASM_EXTABLE(0b, 0b) \
17186+ : "+r" (__ret), "+m" (*(ptr)) \
17187+ : : "memory", "cc"); \
17188+ break; \
17189+ case __X86_CASE_Q: \
17190+ asm volatile (lock #op "q %q0, %1\n" \
17191+ "jno 0f\n" \
17192+ "mov %0,%1\n" \
17193+ "int $4\n0:\n" \
17194+ _ASM_EXTABLE(0b, 0b) \
17195+ : "+r" (__ret), "+m" (*(ptr)) \
17196+ : : "memory", "cc"); \
17197+ break; \
17198+ default: \
17199+ __ ## op ## _check_overflow_wrong_size(); \
17200+ } \
17201+ __ret; \
17202+ })
17203+#else
17204+#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
17205+#endif
17206+
17207 /*
17208 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
17209 * Since this is generally used to protect other memory information, we
17210@@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
17211 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
17212 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
17213
17214+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
17215+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
17216+
17217 #define __add(ptr, inc, lock) \
17218 ({ \
17219 __typeof__ (*(ptr)) __ret = (inc); \
17220diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
17221index 59c6c40..5e0b22c 100644
17222--- a/arch/x86/include/asm/compat.h
17223+++ b/arch/x86/include/asm/compat.h
17224@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
17225 typedef u32 compat_uint_t;
17226 typedef u32 compat_ulong_t;
17227 typedef u64 __attribute__((aligned(4))) compat_u64;
17228-typedef u32 compat_uptr_t;
17229+typedef u32 __user compat_uptr_t;
17230
17231 struct compat_timespec {
17232 compat_time_t tv_sec;
17233diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
17234index 2075e6c..4d368b4 100644
17235--- a/arch/x86/include/asm/cpufeature.h
17236+++ b/arch/x86/include/asm/cpufeature.h
17237@@ -203,7 +203,7 @@
17238 #define X86_FEATURE_PAUSEFILTER ( 8*32+13) /* AMD filtered pause intercept */
17239 #define X86_FEATURE_PFTHRESHOLD ( 8*32+14) /* AMD pause filter threshold */
17240 #define X86_FEATURE_VMMCALL ( 8*32+15) /* Prefer vmmcall to vmcall */
17241-
17242+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
17243
17244 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
17245 #define X86_FEATURE_FSGSBASE ( 9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
17246@@ -211,7 +211,7 @@
17247 #define X86_FEATURE_BMI1 ( 9*32+ 3) /* 1st group bit manipulation extensions */
17248 #define X86_FEATURE_HLE ( 9*32+ 4) /* Hardware Lock Elision */
17249 #define X86_FEATURE_AVX2 ( 9*32+ 5) /* AVX2 instructions */
17250-#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Protection */
17251+#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Prevention */
17252 #define X86_FEATURE_BMI2 ( 9*32+ 8) /* 2nd group bit manipulation extensions */
17253 #define X86_FEATURE_ERMS ( 9*32+ 9) /* Enhanced REP MOVSB/STOSB */
17254 #define X86_FEATURE_INVPCID ( 9*32+10) /* Invalidate Processor Context ID */
17255@@ -371,6 +371,7 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
17256 #undef cpu_has_centaur_mcr
17257 #define cpu_has_centaur_mcr 0
17258
17259+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
17260 #endif /* CONFIG_X86_64 */
17261
17262 #if __GNUC__ >= 4
17263@@ -423,7 +424,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
17264
17265 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
17266 t_warn:
17267- warn_pre_alternatives();
17268+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
17269+ warn_pre_alternatives();
17270 return false;
17271 #endif
17272
17273@@ -443,7 +445,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
17274 ".section .discard,\"aw\",@progbits\n"
17275 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
17276 ".previous\n"
17277- ".section .altinstr_replacement,\"ax\"\n"
17278+ ".section .altinstr_replacement,\"a\"\n"
17279 "3: movb $1,%0\n"
17280 "4:\n"
17281 ".previous\n"
17282@@ -480,7 +482,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
17283 " .byte 2b - 1b\n" /* src len */
17284 " .byte 4f - 3f\n" /* repl len */
17285 ".previous\n"
17286- ".section .altinstr_replacement,\"ax\"\n"
17287+ ".section .altinstr_replacement,\"a\"\n"
17288 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
17289 "4:\n"
17290 ".previous\n"
17291@@ -513,7 +515,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
17292 ".section .discard,\"aw\",@progbits\n"
17293 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
17294 ".previous\n"
17295- ".section .altinstr_replacement,\"ax\"\n"
17296+ ".section .altinstr_replacement,\"a\"\n"
17297 "3: movb $0,%0\n"
17298 "4:\n"
17299 ".previous\n"
17300@@ -527,7 +529,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
17301 ".section .discard,\"aw\",@progbits\n"
17302 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
17303 ".previous\n"
17304- ".section .altinstr_replacement,\"ax\"\n"
17305+ ".section .altinstr_replacement,\"a\"\n"
17306 "5: movb $1,%0\n"
17307 "6:\n"
17308 ".previous\n"
17309diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
17310index 50d033a..37deb26 100644
17311--- a/arch/x86/include/asm/desc.h
17312+++ b/arch/x86/include/asm/desc.h
17313@@ -4,6 +4,7 @@
17314 #include <asm/desc_defs.h>
17315 #include <asm/ldt.h>
17316 #include <asm/mmu.h>
17317+#include <asm/pgtable.h>
17318
17319 #include <linux/smp.h>
17320 #include <linux/percpu.h>
17321@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
17322
17323 desc->type = (info->read_exec_only ^ 1) << 1;
17324 desc->type |= info->contents << 2;
17325+ desc->type |= info->seg_not_present ^ 1;
17326
17327 desc->s = 1;
17328 desc->dpl = 0x3;
17329@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
17330 }
17331
17332 extern struct desc_ptr idt_descr;
17333-extern gate_desc idt_table[];
17334-extern struct desc_ptr debug_idt_descr;
17335-extern gate_desc debug_idt_table[];
17336-
17337-struct gdt_page {
17338- struct desc_struct gdt[GDT_ENTRIES];
17339-} __attribute__((aligned(PAGE_SIZE)));
17340-
17341-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
17342+extern gate_desc idt_table[IDT_ENTRIES];
17343+extern const struct desc_ptr debug_idt_descr;
17344+extern gate_desc debug_idt_table[IDT_ENTRIES];
17345
17346+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
17347 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
17348 {
17349- return per_cpu(gdt_page, cpu).gdt;
17350+ return cpu_gdt_table[cpu];
17351 }
17352
17353 #ifdef CONFIG_X86_64
17354@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
17355 unsigned long base, unsigned dpl, unsigned flags,
17356 unsigned short seg)
17357 {
17358- gate->a = (seg << 16) | (base & 0xffff);
17359- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
17360+ gate->gate.offset_low = base;
17361+ gate->gate.seg = seg;
17362+ gate->gate.reserved = 0;
17363+ gate->gate.type = type;
17364+ gate->gate.s = 0;
17365+ gate->gate.dpl = dpl;
17366+ gate->gate.p = 1;
17367+ gate->gate.offset_high = base >> 16;
17368 }
17369
17370 #endif
17371@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
17372
17373 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
17374 {
17375+ pax_open_kernel();
17376 memcpy(&idt[entry], gate, sizeof(*gate));
17377+ pax_close_kernel();
17378 }
17379
17380 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
17381 {
17382+ pax_open_kernel();
17383 memcpy(&ldt[entry], desc, 8);
17384+ pax_close_kernel();
17385 }
17386
17387 static inline void
17388@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
17389 default: size = sizeof(*gdt); break;
17390 }
17391
17392+ pax_open_kernel();
17393 memcpy(&gdt[entry], desc, size);
17394+ pax_close_kernel();
17395 }
17396
17397 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
17398@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
17399
17400 static inline void native_load_tr_desc(void)
17401 {
17402+ pax_open_kernel();
17403 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
17404+ pax_close_kernel();
17405 }
17406
17407 static inline void native_load_gdt(const struct desc_ptr *dtr)
17408@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
17409 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
17410 unsigned int i;
17411
17412+ pax_open_kernel();
17413 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
17414 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
17415+ pax_close_kernel();
17416 }
17417
17418 #define _LDT_empty(info) \
17419@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
17420 preempt_enable();
17421 }
17422
17423-static inline unsigned long get_desc_base(const struct desc_struct *desc)
17424+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
17425 {
17426 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
17427 }
17428@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
17429 }
17430
17431 #ifdef CONFIG_X86_64
17432-static inline void set_nmi_gate(int gate, void *addr)
17433+static inline void set_nmi_gate(int gate, const void *addr)
17434 {
17435 gate_desc s;
17436
17437@@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
17438 #endif
17439
17440 #ifdef CONFIG_TRACING
17441-extern struct desc_ptr trace_idt_descr;
17442-extern gate_desc trace_idt_table[];
17443+extern const struct desc_ptr trace_idt_descr;
17444+extern gate_desc trace_idt_table[IDT_ENTRIES];
17445 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
17446 {
17447 write_idt_entry(trace_idt_table, entry, gate);
17448 }
17449
17450-static inline void _trace_set_gate(int gate, unsigned type, void *addr,
17451+static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
17452 unsigned dpl, unsigned ist, unsigned seg)
17453 {
17454 gate_desc s;
17455@@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
17456 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
17457 #endif
17458
17459-static inline void _set_gate(int gate, unsigned type, void *addr,
17460+static inline void _set_gate(int gate, unsigned type, const void *addr,
17461 unsigned dpl, unsigned ist, unsigned seg)
17462 {
17463 gate_desc s;
17464@@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
17465 #define set_intr_gate(n, addr) \
17466 do { \
17467 BUG_ON((unsigned)n > 0xFF); \
17468- _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
17469+ _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
17470 __KERNEL_CS); \
17471- _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
17472+ _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
17473 0, 0, __KERNEL_CS); \
17474 } while (0)
17475
17476@@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
17477 /*
17478 * This routine sets up an interrupt gate at directory privilege level 3.
17479 */
17480-static inline void set_system_intr_gate(unsigned int n, void *addr)
17481+static inline void set_system_intr_gate(unsigned int n, const void *addr)
17482 {
17483 BUG_ON((unsigned)n > 0xFF);
17484 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
17485 }
17486
17487-static inline void set_system_trap_gate(unsigned int n, void *addr)
17488+static inline void set_system_trap_gate(unsigned int n, const void *addr)
17489 {
17490 BUG_ON((unsigned)n > 0xFF);
17491 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
17492 }
17493
17494-static inline void set_trap_gate(unsigned int n, void *addr)
17495+static inline void set_trap_gate(unsigned int n, const void *addr)
17496 {
17497 BUG_ON((unsigned)n > 0xFF);
17498 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
17499@@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
17500 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
17501 {
17502 BUG_ON((unsigned)n > 0xFF);
17503- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
17504+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
17505 }
17506
17507-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
17508+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
17509 {
17510 BUG_ON((unsigned)n > 0xFF);
17511 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
17512 }
17513
17514-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
17515+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
17516 {
17517 BUG_ON((unsigned)n > 0xFF);
17518 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
17519@@ -503,4 +516,17 @@ static inline void load_current_idt(void)
17520 else
17521 load_idt((const struct desc_ptr *)&idt_descr);
17522 }
17523+
17524+#ifdef CONFIG_X86_32
17525+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
17526+{
17527+ struct desc_struct d;
17528+
17529+ if (likely(limit))
17530+ limit = (limit - 1UL) >> PAGE_SHIFT;
17531+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
17532+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
17533+}
17534+#endif
17535+
17536 #endif /* _ASM_X86_DESC_H */
17537diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
17538index 278441f..b95a174 100644
17539--- a/arch/x86/include/asm/desc_defs.h
17540+++ b/arch/x86/include/asm/desc_defs.h
17541@@ -31,6 +31,12 @@ struct desc_struct {
17542 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
17543 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
17544 };
17545+ struct {
17546+ u16 offset_low;
17547+ u16 seg;
17548+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
17549+ unsigned offset_high: 16;
17550+ } gate;
17551 };
17552 } __attribute__((packed));
17553
17554diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
17555index ced283a..ffe04cc 100644
17556--- a/arch/x86/include/asm/div64.h
17557+++ b/arch/x86/include/asm/div64.h
17558@@ -39,7 +39,7 @@
17559 __mod; \
17560 })
17561
17562-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
17563+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
17564 {
17565 union {
17566 u64 v64;
17567diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
17568index ca3347a..1a5082a 100644
17569--- a/arch/x86/include/asm/elf.h
17570+++ b/arch/x86/include/asm/elf.h
17571@@ -75,9 +75,6 @@ typedef struct user_fxsr_struct elf_fpxregset_t;
17572
17573 #include <asm/vdso.h>
17574
17575-#ifdef CONFIG_X86_64
17576-extern unsigned int vdso64_enabled;
17577-#endif
17578 #if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT)
17579 extern unsigned int vdso32_enabled;
17580 #endif
17581@@ -249,7 +246,25 @@ extern int force_personality32;
17582 the loader. We need to make sure that it is out of the way of the program
17583 that it will "exec", and that there is sufficient room for the brk. */
17584
17585+#ifdef CONFIG_PAX_SEGMEXEC
17586+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
17587+#else
17588 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
17589+#endif
17590+
17591+#ifdef CONFIG_PAX_ASLR
17592+#ifdef CONFIG_X86_32
17593+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
17594+
17595+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
17596+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
17597+#else
17598+#define PAX_ELF_ET_DYN_BASE 0x400000UL
17599+
17600+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
17601+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
17602+#endif
17603+#endif
17604
17605 /* This yields a mask that user programs can use to figure out what
17606 instruction set this CPU supports. This could be done in user space,
17607@@ -298,17 +313,13 @@ do { \
17608
17609 #define ARCH_DLINFO \
17610 do { \
17611- if (vdso64_enabled) \
17612- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
17613- (unsigned long __force)current->mm->context.vdso); \
17614+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
17615 } while (0)
17616
17617 /* As a historical oddity, the x32 and x86_64 vDSOs are controlled together. */
17618 #define ARCH_DLINFO_X32 \
17619 do { \
17620- if (vdso64_enabled) \
17621- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
17622- (unsigned long __force)current->mm->context.vdso); \
17623+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
17624 } while (0)
17625
17626 #define AT_SYSINFO 32
17627@@ -323,10 +334,10 @@ else \
17628
17629 #endif /* !CONFIG_X86_32 */
17630
17631-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
17632+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
17633
17634 #define VDSO_ENTRY \
17635- ((unsigned long)current->mm->context.vdso + \
17636+ (current->mm->context.vdso + \
17637 selected_vdso32->sym___kernel_vsyscall)
17638
17639 struct linux_binprm;
17640@@ -338,9 +349,6 @@ extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
17641 int uses_interp);
17642 #define compat_arch_setup_additional_pages compat_arch_setup_additional_pages
17643
17644-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
17645-#define arch_randomize_brk arch_randomize_brk
17646-
17647 /*
17648 * True on X86_32 or when emulating IA32 on X86_64
17649 */
17650diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
17651index 77a99ac..39ff7f5 100644
17652--- a/arch/x86/include/asm/emergency-restart.h
17653+++ b/arch/x86/include/asm/emergency-restart.h
17654@@ -1,6 +1,6 @@
17655 #ifndef _ASM_X86_EMERGENCY_RESTART_H
17656 #define _ASM_X86_EMERGENCY_RESTART_H
17657
17658-extern void machine_emergency_restart(void);
17659+extern void machine_emergency_restart(void) __noreturn;
17660
17661 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
17662diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
17663index 1c7eefe..d0e4702 100644
17664--- a/arch/x86/include/asm/floppy.h
17665+++ b/arch/x86/include/asm/floppy.h
17666@@ -229,18 +229,18 @@ static struct fd_routine_l {
17667 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
17668 } fd_routine[] = {
17669 {
17670- request_dma,
17671- free_dma,
17672- get_dma_residue,
17673- dma_mem_alloc,
17674- hard_dma_setup
17675+ ._request_dma = request_dma,
17676+ ._free_dma = free_dma,
17677+ ._get_dma_residue = get_dma_residue,
17678+ ._dma_mem_alloc = dma_mem_alloc,
17679+ ._dma_setup = hard_dma_setup
17680 },
17681 {
17682- vdma_request_dma,
17683- vdma_nop,
17684- vdma_get_dma_residue,
17685- vdma_mem_alloc,
17686- vdma_dma_setup
17687+ ._request_dma = vdma_request_dma,
17688+ ._free_dma = vdma_nop,
17689+ ._get_dma_residue = vdma_get_dma_residue,
17690+ ._dma_mem_alloc = vdma_mem_alloc,
17691+ ._dma_setup = vdma_dma_setup
17692 }
17693 };
17694
17695diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
17696index 412ecec..c1ea43a 100644
17697--- a/arch/x86/include/asm/fpu-internal.h
17698+++ b/arch/x86/include/asm/fpu-internal.h
17699@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
17700 #define user_insn(insn, output, input...) \
17701 ({ \
17702 int err; \
17703+ pax_open_userland(); \
17704 asm volatile(ASM_STAC "\n" \
17705- "1:" #insn "\n\t" \
17706+ "1:" \
17707+ __copyuser_seg \
17708+ #insn "\n\t" \
17709 "2: " ASM_CLAC "\n" \
17710 ".section .fixup,\"ax\"\n" \
17711 "3: movl $-1,%[err]\n" \
17712@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
17713 _ASM_EXTABLE(1b, 3b) \
17714 : [err] "=r" (err), output \
17715 : "0"(0), input); \
17716+ pax_close_userland(); \
17717 err; \
17718 })
17719
17720@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
17721 "fnclex\n\t"
17722 "emms\n\t"
17723 "fildl %P[addr]" /* set F?P to defined value */
17724- : : [addr] "m" (tsk->thread.fpu.has_fpu));
17725+ : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
17726 }
17727
17728 return fpu_restore_checking(&tsk->thread.fpu);
17729diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
17730index b4c1f54..e290c08 100644
17731--- a/arch/x86/include/asm/futex.h
17732+++ b/arch/x86/include/asm/futex.h
17733@@ -12,6 +12,7 @@
17734 #include <asm/smap.h>
17735
17736 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
17737+ typecheck(u32 __user *, uaddr); \
17738 asm volatile("\t" ASM_STAC "\n" \
17739 "1:\t" insn "\n" \
17740 "2:\t" ASM_CLAC "\n" \
17741@@ -20,15 +21,16 @@
17742 "\tjmp\t2b\n" \
17743 "\t.previous\n" \
17744 _ASM_EXTABLE(1b, 3b) \
17745- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
17746+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
17747 : "i" (-EFAULT), "0" (oparg), "1" (0))
17748
17749 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
17750+ typecheck(u32 __user *, uaddr); \
17751 asm volatile("\t" ASM_STAC "\n" \
17752 "1:\tmovl %2, %0\n" \
17753 "\tmovl\t%0, %3\n" \
17754 "\t" insn "\n" \
17755- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
17756+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
17757 "\tjnz\t1b\n" \
17758 "3:\t" ASM_CLAC "\n" \
17759 "\t.section .fixup,\"ax\"\n" \
17760@@ -38,7 +40,7 @@
17761 _ASM_EXTABLE(1b, 4b) \
17762 _ASM_EXTABLE(2b, 4b) \
17763 : "=&a" (oldval), "=&r" (ret), \
17764- "+m" (*uaddr), "=&r" (tem) \
17765+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
17766 : "r" (oparg), "i" (-EFAULT), "1" (0))
17767
17768 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17769@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17770
17771 pagefault_disable();
17772
17773+ pax_open_userland();
17774 switch (op) {
17775 case FUTEX_OP_SET:
17776- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
17777+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
17778 break;
17779 case FUTEX_OP_ADD:
17780- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
17781+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
17782 uaddr, oparg);
17783 break;
17784 case FUTEX_OP_OR:
17785@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17786 default:
17787 ret = -ENOSYS;
17788 }
17789+ pax_close_userland();
17790
17791 pagefault_enable();
17792
17793diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
17794index 4615906..788c817 100644
17795--- a/arch/x86/include/asm/hw_irq.h
17796+++ b/arch/x86/include/asm/hw_irq.h
17797@@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
17798 extern void enable_IO_APIC(void);
17799
17800 /* Statistics */
17801-extern atomic_t irq_err_count;
17802-extern atomic_t irq_mis_count;
17803+extern atomic_unchecked_t irq_err_count;
17804+extern atomic_unchecked_t irq_mis_count;
17805
17806 /* EISA */
17807 extern void eisa_set_level_irq(unsigned int irq);
17808diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
17809index ccffa53..3c90c87 100644
17810--- a/arch/x86/include/asm/i8259.h
17811+++ b/arch/x86/include/asm/i8259.h
17812@@ -62,7 +62,7 @@ struct legacy_pic {
17813 void (*init)(int auto_eoi);
17814 int (*irq_pending)(unsigned int irq);
17815 void (*make_irq)(unsigned int irq);
17816-};
17817+} __do_const;
17818
17819 extern struct legacy_pic *legacy_pic;
17820 extern struct legacy_pic null_legacy_pic;
17821diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17822index b8237d8..3e8864e 100644
17823--- a/arch/x86/include/asm/io.h
17824+++ b/arch/x86/include/asm/io.h
17825@@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17826 "m" (*(volatile type __force *)addr) barrier); }
17827
17828 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17829-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17830-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17831+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17832+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17833
17834 build_mmio_read(__readb, "b", unsigned char, "=q", )
17835-build_mmio_read(__readw, "w", unsigned short, "=r", )
17836-build_mmio_read(__readl, "l", unsigned int, "=r", )
17837+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17838+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17839
17840 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17841 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17842@@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
17843 * this function
17844 */
17845
17846-static inline phys_addr_t virt_to_phys(volatile void *address)
17847+static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
17848 {
17849 return __pa(address);
17850 }
17851@@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17852 return ioremap_nocache(offset, size);
17853 }
17854
17855-extern void iounmap(volatile void __iomem *addr);
17856+extern void iounmap(const volatile void __iomem *addr);
17857
17858 extern void set_iounmap_nonlazy(void);
17859
17860@@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
17861
17862 #include <linux/vmalloc.h>
17863
17864+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17865+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17866+{
17867+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17868+}
17869+
17870+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17871+{
17872+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17873+}
17874+
17875 /*
17876 * Convert a virtual cached pointer to an uncached pointer
17877 */
17878diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17879index 0a8b519..80e7d5b 100644
17880--- a/arch/x86/include/asm/irqflags.h
17881+++ b/arch/x86/include/asm/irqflags.h
17882@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17883 sti; \
17884 sysexit
17885
17886+#define GET_CR0_INTO_RDI mov %cr0, %rdi
17887+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17888+#define GET_CR3_INTO_RDI mov %cr3, %rdi
17889+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17890+
17891 #else
17892 #define INTERRUPT_RETURN iret
17893 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17894diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17895index 53cdfb2..d1369e6 100644
17896--- a/arch/x86/include/asm/kprobes.h
17897+++ b/arch/x86/include/asm/kprobes.h
17898@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
17899 #define RELATIVEJUMP_SIZE 5
17900 #define RELATIVECALL_OPCODE 0xe8
17901 #define RELATIVE_ADDR_SIZE 4
17902-#define MAX_STACK_SIZE 64
17903-#define MIN_STACK_SIZE(ADDR) \
17904- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17905- THREAD_SIZE - (unsigned long)(ADDR))) \
17906- ? (MAX_STACK_SIZE) \
17907- : (((unsigned long)current_thread_info()) + \
17908- THREAD_SIZE - (unsigned long)(ADDR)))
17909+#define MAX_STACK_SIZE 64UL
17910+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17911
17912 #define flush_insn_slot(p) do { } while (0)
17913
17914diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17915index 4ad6560..75c7bdd 100644
17916--- a/arch/x86/include/asm/local.h
17917+++ b/arch/x86/include/asm/local.h
17918@@ -10,33 +10,97 @@ typedef struct {
17919 atomic_long_t a;
17920 } local_t;
17921
17922+typedef struct {
17923+ atomic_long_unchecked_t a;
17924+} local_unchecked_t;
17925+
17926 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17927
17928 #define local_read(l) atomic_long_read(&(l)->a)
17929+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17930 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17931+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17932
17933 static inline void local_inc(local_t *l)
17934 {
17935- asm volatile(_ASM_INC "%0"
17936+ asm volatile(_ASM_INC "%0\n"
17937+
17938+#ifdef CONFIG_PAX_REFCOUNT
17939+ "jno 0f\n"
17940+ _ASM_DEC "%0\n"
17941+ "int $4\n0:\n"
17942+ _ASM_EXTABLE(0b, 0b)
17943+#endif
17944+
17945+ : "+m" (l->a.counter));
17946+}
17947+
17948+static inline void local_inc_unchecked(local_unchecked_t *l)
17949+{
17950+ asm volatile(_ASM_INC "%0\n"
17951 : "+m" (l->a.counter));
17952 }
17953
17954 static inline void local_dec(local_t *l)
17955 {
17956- asm volatile(_ASM_DEC "%0"
17957+ asm volatile(_ASM_DEC "%0\n"
17958+
17959+#ifdef CONFIG_PAX_REFCOUNT
17960+ "jno 0f\n"
17961+ _ASM_INC "%0\n"
17962+ "int $4\n0:\n"
17963+ _ASM_EXTABLE(0b, 0b)
17964+#endif
17965+
17966+ : "+m" (l->a.counter));
17967+}
17968+
17969+static inline void local_dec_unchecked(local_unchecked_t *l)
17970+{
17971+ asm volatile(_ASM_DEC "%0\n"
17972 : "+m" (l->a.counter));
17973 }
17974
17975 static inline void local_add(long i, local_t *l)
17976 {
17977- asm volatile(_ASM_ADD "%1,%0"
17978+ asm volatile(_ASM_ADD "%1,%0\n"
17979+
17980+#ifdef CONFIG_PAX_REFCOUNT
17981+ "jno 0f\n"
17982+ _ASM_SUB "%1,%0\n"
17983+ "int $4\n0:\n"
17984+ _ASM_EXTABLE(0b, 0b)
17985+#endif
17986+
17987+ : "+m" (l->a.counter)
17988+ : "ir" (i));
17989+}
17990+
17991+static inline void local_add_unchecked(long i, local_unchecked_t *l)
17992+{
17993+ asm volatile(_ASM_ADD "%1,%0\n"
17994 : "+m" (l->a.counter)
17995 : "ir" (i));
17996 }
17997
17998 static inline void local_sub(long i, local_t *l)
17999 {
18000- asm volatile(_ASM_SUB "%1,%0"
18001+ asm volatile(_ASM_SUB "%1,%0\n"
18002+
18003+#ifdef CONFIG_PAX_REFCOUNT
18004+ "jno 0f\n"
18005+ _ASM_ADD "%1,%0\n"
18006+ "int $4\n0:\n"
18007+ _ASM_EXTABLE(0b, 0b)
18008+#endif
18009+
18010+ : "+m" (l->a.counter)
18011+ : "ir" (i));
18012+}
18013+
18014+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
18015+{
18016+ asm volatile(_ASM_SUB "%1,%0\n"
18017 : "+m" (l->a.counter)
18018 : "ir" (i));
18019 }
18020@@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
18021 */
18022 static inline int local_sub_and_test(long i, local_t *l)
18023 {
18024- GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
18025+ GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
18026 }
18027
18028 /**
18029@@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
18030 */
18031 static inline int local_dec_and_test(local_t *l)
18032 {
18033- GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
18034+ GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
18035 }
18036
18037 /**
18038@@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
18039 */
18040 static inline int local_inc_and_test(local_t *l)
18041 {
18042- GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
18043+ GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
18044 }
18045
18046 /**
18047@@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
18048 */
18049 static inline int local_add_negative(long i, local_t *l)
18050 {
18051- GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
18052+ GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
18053 }
18054
18055 /**
18056@@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
18057 static inline long local_add_return(long i, local_t *l)
18058 {
18059 long __i = i;
18060+ asm volatile(_ASM_XADD "%0, %1\n"
18061+
18062+#ifdef CONFIG_PAX_REFCOUNT
18063+ "jno 0f\n"
18064+ _ASM_MOV "%0,%1\n"
18065+ "int $4\n0:\n"
18066+ _ASM_EXTABLE(0b, 0b)
18067+#endif
18068+
18069+ : "+r" (i), "+m" (l->a.counter)
18070+ : : "memory");
18071+ return i + __i;
18072+}
18073+
18074+/**
18075+ * local_add_return_unchecked - add and return
18076+ * @i: integer value to add
18077+ * @l: pointer to type local_unchecked_t
18078+ *
18079+ * Atomically adds @i to @l and returns @i + @l
18080+ */
18081+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
18082+{
18083+ long __i = i;
18084 asm volatile(_ASM_XADD "%0, %1;"
18085 : "+r" (i), "+m" (l->a.counter)
18086 : : "memory");
18087@@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
18088
18089 #define local_cmpxchg(l, o, n) \
18090 (cmpxchg_local(&((l)->a.counter), (o), (n)))
18091+#define local_cmpxchg_unchecked(l, o, n) \
18092+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
18093 /* Always has a lock prefix */
18094 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
18095
18096diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
18097new file mode 100644
18098index 0000000..2bfd3ba
18099--- /dev/null
18100+++ b/arch/x86/include/asm/mman.h
18101@@ -0,0 +1,15 @@
18102+#ifndef _X86_MMAN_H
18103+#define _X86_MMAN_H
18104+
18105+#include <uapi/asm/mman.h>
18106+
18107+#ifdef __KERNEL__
18108+#ifndef __ASSEMBLY__
18109+#ifdef CONFIG_X86_32
18110+#define arch_mmap_check i386_mmap_check
18111+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
18112+#endif
18113+#endif
18114+#endif
18115+
18116+#endif /* X86_MMAN_H */
18117diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
18118index 876e74e..e20bfb1 100644
18119--- a/arch/x86/include/asm/mmu.h
18120+++ b/arch/x86/include/asm/mmu.h
18121@@ -9,7 +9,7 @@
18122 * we put the segment information here.
18123 */
18124 typedef struct {
18125- void *ldt;
18126+ struct desc_struct *ldt;
18127 int size;
18128
18129 #ifdef CONFIG_X86_64
18130@@ -18,7 +18,19 @@ typedef struct {
18131 #endif
18132
18133 struct mutex lock;
18134- void __user *vdso;
18135+ unsigned long vdso;
18136+
18137+#ifdef CONFIG_X86_32
18138+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18139+ unsigned long user_cs_base;
18140+ unsigned long user_cs_limit;
18141+
18142+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18143+ cpumask_t cpu_user_cs_mask;
18144+#endif
18145+
18146+#endif
18147+#endif
18148 } mm_context_t;
18149
18150 #ifdef CONFIG_SMP
18151diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
18152index 166af2a..648c200 100644
18153--- a/arch/x86/include/asm/mmu_context.h
18154+++ b/arch/x86/include/asm/mmu_context.h
18155@@ -28,6 +28,20 @@ void destroy_context(struct mm_struct *mm);
18156
18157 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
18158 {
18159+
18160+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18161+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
18162+ unsigned int i;
18163+ pgd_t *pgd;
18164+
18165+ pax_open_kernel();
18166+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
18167+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
18168+ set_pgd_batched(pgd+i, native_make_pgd(0));
18169+ pax_close_kernel();
18170+ }
18171+#endif
18172+
18173 #ifdef CONFIG_SMP
18174 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
18175 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
18176@@ -38,16 +52,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
18177 struct task_struct *tsk)
18178 {
18179 unsigned cpu = smp_processor_id();
18180+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
18181+ int tlbstate = TLBSTATE_OK;
18182+#endif
18183
18184 if (likely(prev != next)) {
18185 #ifdef CONFIG_SMP
18186+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
18187+ tlbstate = this_cpu_read(cpu_tlbstate.state);
18188+#endif
18189 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
18190 this_cpu_write(cpu_tlbstate.active_mm, next);
18191 #endif
18192 cpumask_set_cpu(cpu, mm_cpumask(next));
18193
18194 /* Re-load page tables */
18195+#ifdef CONFIG_PAX_PER_CPU_PGD
18196+ pax_open_kernel();
18197+
18198+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18199+ if (static_cpu_has(X86_FEATURE_PCID))
18200+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
18201+ else
18202+#endif
18203+
18204+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
18205+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
18206+ pax_close_kernel();
18207+ 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));
18208+
18209+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18210+ if (static_cpu_has(X86_FEATURE_PCID)) {
18211+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
18212+ u64 descriptor[2];
18213+ descriptor[0] = PCID_USER;
18214+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
18215+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
18216+ descriptor[0] = PCID_KERNEL;
18217+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
18218+ }
18219+ } else {
18220+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
18221+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
18222+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
18223+ else
18224+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
18225+ }
18226+ } else
18227+#endif
18228+
18229+ load_cr3(get_cpu_pgd(cpu, kernel));
18230+#else
18231 load_cr3(next->pgd);
18232+#endif
18233 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
18234
18235 /* Stop flush ipis for the previous mm */
18236@@ -56,9 +113,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
18237 /* Load the LDT, if the LDT is different: */
18238 if (unlikely(prev->context.ldt != next->context.ldt))
18239 load_LDT_nolock(&next->context);
18240+
18241+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18242+ if (!(__supported_pte_mask & _PAGE_NX)) {
18243+ smp_mb__before_atomic();
18244+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
18245+ smp_mb__after_atomic();
18246+ cpu_set(cpu, next->context.cpu_user_cs_mask);
18247+ }
18248+#endif
18249+
18250+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
18251+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
18252+ prev->context.user_cs_limit != next->context.user_cs_limit))
18253+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
18254+#ifdef CONFIG_SMP
18255+ else if (unlikely(tlbstate != TLBSTATE_OK))
18256+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
18257+#endif
18258+#endif
18259+
18260 }
18261+ else {
18262+
18263+#ifdef CONFIG_PAX_PER_CPU_PGD
18264+ pax_open_kernel();
18265+
18266+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18267+ if (static_cpu_has(X86_FEATURE_PCID))
18268+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
18269+ else
18270+#endif
18271+
18272+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
18273+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
18274+ pax_close_kernel();
18275+ 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));
18276+
18277+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18278+ if (static_cpu_has(X86_FEATURE_PCID)) {
18279+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
18280+ u64 descriptor[2];
18281+ descriptor[0] = PCID_USER;
18282+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
18283+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
18284+ descriptor[0] = PCID_KERNEL;
18285+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
18286+ }
18287+ } else {
18288+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
18289+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
18290+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
18291+ else
18292+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
18293+ }
18294+ } else
18295+#endif
18296+
18297+ load_cr3(get_cpu_pgd(cpu, kernel));
18298+#endif
18299+
18300 #ifdef CONFIG_SMP
18301- else {
18302 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
18303 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
18304
18305@@ -75,12 +190,29 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
18306 * tlb flush IPI delivery. We must reload CR3
18307 * to make sure to use no freed page tables.
18308 */
18309+
18310+#ifndef CONFIG_PAX_PER_CPU_PGD
18311 load_cr3(next->pgd);
18312 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
18313+#endif
18314+
18315 load_LDT_nolock(&next->context);
18316+
18317+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
18318+ if (!(__supported_pte_mask & _PAGE_NX))
18319+ cpu_set(cpu, next->context.cpu_user_cs_mask);
18320+#endif
18321+
18322+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
18323+#ifdef CONFIG_PAX_PAGEEXEC
18324+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
18325+#endif
18326+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
18327+#endif
18328+
18329 }
18330+#endif
18331 }
18332-#endif
18333 }
18334
18335 #define activate_mm(prev, next) \
18336diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
18337index e3b7819..b257c64 100644
18338--- a/arch/x86/include/asm/module.h
18339+++ b/arch/x86/include/asm/module.h
18340@@ -5,6 +5,7 @@
18341
18342 #ifdef CONFIG_X86_64
18343 /* X86_64 does not define MODULE_PROC_FAMILY */
18344+#define MODULE_PROC_FAMILY ""
18345 #elif defined CONFIG_M486
18346 #define MODULE_PROC_FAMILY "486 "
18347 #elif defined CONFIG_M586
18348@@ -57,8 +58,20 @@
18349 #error unknown processor family
18350 #endif
18351
18352-#ifdef CONFIG_X86_32
18353-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
18354+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
18355+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
18356+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
18357+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
18358+#else
18359+#define MODULE_PAX_KERNEXEC ""
18360 #endif
18361
18362+#ifdef CONFIG_PAX_MEMORY_UDEREF
18363+#define MODULE_PAX_UDEREF "UDEREF "
18364+#else
18365+#define MODULE_PAX_UDEREF ""
18366+#endif
18367+
18368+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
18369+
18370 #endif /* _ASM_X86_MODULE_H */
18371diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
18372index 5f2fc44..106caa6 100644
18373--- a/arch/x86/include/asm/nmi.h
18374+++ b/arch/x86/include/asm/nmi.h
18375@@ -36,26 +36,35 @@ enum {
18376
18377 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
18378
18379+struct nmiaction;
18380+
18381+struct nmiwork {
18382+ const struct nmiaction *action;
18383+ u64 max_duration;
18384+ struct irq_work irq_work;
18385+};
18386+
18387 struct nmiaction {
18388 struct list_head list;
18389 nmi_handler_t handler;
18390- u64 max_duration;
18391- struct irq_work irq_work;
18392 unsigned long flags;
18393 const char *name;
18394-};
18395+ struct nmiwork *work;
18396+} __do_const;
18397
18398 #define register_nmi_handler(t, fn, fg, n, init...) \
18399 ({ \
18400- static struct nmiaction init fn##_na = { \
18401+ static struct nmiwork fn##_nw; \
18402+ static const struct nmiaction init fn##_na = { \
18403 .handler = (fn), \
18404 .name = (n), \
18405 .flags = (fg), \
18406+ .work = &fn##_nw, \
18407 }; \
18408 __register_nmi_handler((t), &fn##_na); \
18409 })
18410
18411-int __register_nmi_handler(unsigned int, struct nmiaction *);
18412+int __register_nmi_handler(unsigned int, const struct nmiaction *);
18413
18414 void unregister_nmi_handler(unsigned int, const char *);
18415
18416diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
18417index 802dde3..9183e68 100644
18418--- a/arch/x86/include/asm/page.h
18419+++ b/arch/x86/include/asm/page.h
18420@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
18421 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
18422
18423 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
18424+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
18425
18426 #define __boot_va(x) __va(x)
18427 #define __boot_pa(x) __pa(x)
18428@@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
18429 * virt_to_page(kaddr) returns a valid pointer if and only if
18430 * virt_addr_valid(kaddr) returns true.
18431 */
18432-#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
18433 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
18434 extern bool __virt_addr_valid(unsigned long kaddr);
18435 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
18436
18437+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
18438+#define virt_to_page(kaddr) \
18439+ ({ \
18440+ const void *__kaddr = (const void *)(kaddr); \
18441+ BUG_ON(!virt_addr_valid(__kaddr)); \
18442+ pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
18443+ })
18444+#else
18445+#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
18446+#endif
18447+
18448 #endif /* __ASSEMBLY__ */
18449
18450 #include <asm-generic/memory_model.h>
18451diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
18452index f408caf..4a0455e 100644
18453--- a/arch/x86/include/asm/page_64.h
18454+++ b/arch/x86/include/asm/page_64.h
18455@@ -7,9 +7,9 @@
18456
18457 /* duplicated to the one in bootmem.h */
18458 extern unsigned long max_pfn;
18459-extern unsigned long phys_base;
18460+extern const unsigned long phys_base;
18461
18462-static inline unsigned long __phys_addr_nodebug(unsigned long x)
18463+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
18464 {
18465 unsigned long y = x - __START_KERNEL_map;
18466
18467diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
18468index cd6e1610..70f4418 100644
18469--- a/arch/x86/include/asm/paravirt.h
18470+++ b/arch/x86/include/asm/paravirt.h
18471@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
18472 return (pmd_t) { ret };
18473 }
18474
18475-static inline pmdval_t pmd_val(pmd_t pmd)
18476+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
18477 {
18478 pmdval_t ret;
18479
18480@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
18481 val);
18482 }
18483
18484+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18485+{
18486+ pgdval_t val = native_pgd_val(pgd);
18487+
18488+ if (sizeof(pgdval_t) > sizeof(long))
18489+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
18490+ val, (u64)val >> 32);
18491+ else
18492+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
18493+ val);
18494+}
18495+
18496 static inline void pgd_clear(pgd_t *pgdp)
18497 {
18498 set_pgd(pgdp, __pgd(0));
18499@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
18500 pv_mmu_ops.set_fixmap(idx, phys, flags);
18501 }
18502
18503+#ifdef CONFIG_PAX_KERNEXEC
18504+static inline unsigned long pax_open_kernel(void)
18505+{
18506+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
18507+}
18508+
18509+static inline unsigned long pax_close_kernel(void)
18510+{
18511+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
18512+}
18513+#else
18514+static inline unsigned long pax_open_kernel(void) { return 0; }
18515+static inline unsigned long pax_close_kernel(void) { return 0; }
18516+#endif
18517+
18518 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
18519
18520 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
18521@@ -906,7 +933,7 @@ extern void default_banner(void);
18522
18523 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
18524 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
18525-#define PARA_INDIRECT(addr) *%cs:addr
18526+#define PARA_INDIRECT(addr) *%ss:addr
18527 #endif
18528
18529 #define INTERRUPT_RETURN \
18530@@ -981,6 +1008,21 @@ extern void default_banner(void);
18531 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
18532 CLBR_NONE, \
18533 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
18534+
18535+#define GET_CR0_INTO_RDI \
18536+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
18537+ mov %rax,%rdi
18538+
18539+#define SET_RDI_INTO_CR0 \
18540+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
18541+
18542+#define GET_CR3_INTO_RDI \
18543+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
18544+ mov %rax,%rdi
18545+
18546+#define SET_RDI_INTO_CR3 \
18547+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
18548+
18549 #endif /* CONFIG_X86_32 */
18550
18551 #endif /* __ASSEMBLY__ */
18552diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
18553index 7549b8b..f0edfda 100644
18554--- a/arch/x86/include/asm/paravirt_types.h
18555+++ b/arch/x86/include/asm/paravirt_types.h
18556@@ -84,7 +84,7 @@ struct pv_init_ops {
18557 */
18558 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
18559 unsigned long addr, unsigned len);
18560-};
18561+} __no_const __no_randomize_layout;
18562
18563
18564 struct pv_lazy_ops {
18565@@ -92,13 +92,13 @@ struct pv_lazy_ops {
18566 void (*enter)(void);
18567 void (*leave)(void);
18568 void (*flush)(void);
18569-};
18570+} __no_randomize_layout;
18571
18572 struct pv_time_ops {
18573 unsigned long long (*sched_clock)(void);
18574 unsigned long long (*steal_clock)(int cpu);
18575 unsigned long (*get_tsc_khz)(void);
18576-};
18577+} __no_const __no_randomize_layout;
18578
18579 struct pv_cpu_ops {
18580 /* hooks for various privileged instructions */
18581@@ -192,7 +192,7 @@ struct pv_cpu_ops {
18582
18583 void (*start_context_switch)(struct task_struct *prev);
18584 void (*end_context_switch)(struct task_struct *next);
18585-};
18586+} __no_const __no_randomize_layout;
18587
18588 struct pv_irq_ops {
18589 /*
18590@@ -215,7 +215,7 @@ struct pv_irq_ops {
18591 #ifdef CONFIG_X86_64
18592 void (*adjust_exception_frame)(void);
18593 #endif
18594-};
18595+} __no_randomize_layout;
18596
18597 struct pv_apic_ops {
18598 #ifdef CONFIG_X86_LOCAL_APIC
18599@@ -223,7 +223,7 @@ struct pv_apic_ops {
18600 unsigned long start_eip,
18601 unsigned long start_esp);
18602 #endif
18603-};
18604+} __no_const __no_randomize_layout;
18605
18606 struct pv_mmu_ops {
18607 unsigned long (*read_cr2)(void);
18608@@ -313,6 +313,7 @@ struct pv_mmu_ops {
18609 struct paravirt_callee_save make_pud;
18610
18611 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
18612+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
18613 #endif /* PAGETABLE_LEVELS == 4 */
18614 #endif /* PAGETABLE_LEVELS >= 3 */
18615
18616@@ -324,7 +325,13 @@ struct pv_mmu_ops {
18617 an mfn. We can tell which is which from the index. */
18618 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
18619 phys_addr_t phys, pgprot_t flags);
18620-};
18621+
18622+#ifdef CONFIG_PAX_KERNEXEC
18623+ unsigned long (*pax_open_kernel)(void);
18624+ unsigned long (*pax_close_kernel)(void);
18625+#endif
18626+
18627+} __no_randomize_layout;
18628
18629 struct arch_spinlock;
18630 #ifdef CONFIG_SMP
18631@@ -336,11 +343,14 @@ typedef u16 __ticket_t;
18632 struct pv_lock_ops {
18633 struct paravirt_callee_save lock_spinning;
18634 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
18635-};
18636+} __no_randomize_layout;
18637
18638 /* This contains all the paravirt structures: we get a convenient
18639 * number for each function using the offset which we use to indicate
18640- * what to patch. */
18641+ * what to patch.
18642+ * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
18643+ */
18644+
18645 struct paravirt_patch_template {
18646 struct pv_init_ops pv_init_ops;
18647 struct pv_time_ops pv_time_ops;
18648@@ -349,7 +359,7 @@ struct paravirt_patch_template {
18649 struct pv_apic_ops pv_apic_ops;
18650 struct pv_mmu_ops pv_mmu_ops;
18651 struct pv_lock_ops pv_lock_ops;
18652-};
18653+} __no_randomize_layout;
18654
18655 extern struct pv_info pv_info;
18656 extern struct pv_init_ops pv_init_ops;
18657diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
18658index c4412e9..90e88c5 100644
18659--- a/arch/x86/include/asm/pgalloc.h
18660+++ b/arch/x86/include/asm/pgalloc.h
18661@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
18662 pmd_t *pmd, pte_t *pte)
18663 {
18664 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
18665+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
18666+}
18667+
18668+static inline void pmd_populate_user(struct mm_struct *mm,
18669+ pmd_t *pmd, pte_t *pte)
18670+{
18671+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
18672 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
18673 }
18674
18675@@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
18676
18677 #ifdef CONFIG_X86_PAE
18678 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
18679+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
18680+{
18681+ pud_populate(mm, pudp, pmd);
18682+}
18683 #else /* !CONFIG_X86_PAE */
18684 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
18685 {
18686 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
18687 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
18688 }
18689+
18690+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
18691+{
18692+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
18693+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
18694+}
18695 #endif /* CONFIG_X86_PAE */
18696
18697 #if PAGETABLE_LEVELS > 3
18698@@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
18699 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
18700 }
18701
18702+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
18703+{
18704+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
18705+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
18706+}
18707+
18708 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
18709 {
18710 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
18711diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
18712index 206a87f..1623b06 100644
18713--- a/arch/x86/include/asm/pgtable-2level.h
18714+++ b/arch/x86/include/asm/pgtable-2level.h
18715@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
18716
18717 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18718 {
18719+ pax_open_kernel();
18720 *pmdp = pmd;
18721+ pax_close_kernel();
18722 }
18723
18724 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18725diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
18726index 81bb91b..9392125 100644
18727--- a/arch/x86/include/asm/pgtable-3level.h
18728+++ b/arch/x86/include/asm/pgtable-3level.h
18729@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18730
18731 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18732 {
18733+ pax_open_kernel();
18734 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
18735+ pax_close_kernel();
18736 }
18737
18738 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18739 {
18740+ pax_open_kernel();
18741 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
18742+ pax_close_kernel();
18743 }
18744
18745 /*
18746diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
18747index aa97a07..5c53c32 100644
18748--- a/arch/x86/include/asm/pgtable.h
18749+++ b/arch/x86/include/asm/pgtable.h
18750@@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18751
18752 #ifndef __PAGETABLE_PUD_FOLDED
18753 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
18754+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
18755 #define pgd_clear(pgd) native_pgd_clear(pgd)
18756 #endif
18757
18758@@ -83,12 +84,53 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18759
18760 #define arch_end_context_switch(prev) do {} while(0)
18761
18762+#define pax_open_kernel() native_pax_open_kernel()
18763+#define pax_close_kernel() native_pax_close_kernel()
18764 #endif /* CONFIG_PARAVIRT */
18765
18766+#define __HAVE_ARCH_PAX_OPEN_KERNEL
18767+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
18768+
18769+#ifdef CONFIG_PAX_KERNEXEC
18770+static inline unsigned long native_pax_open_kernel(void)
18771+{
18772+ unsigned long cr0;
18773+
18774+ preempt_disable();
18775+ barrier();
18776+ cr0 = read_cr0() ^ X86_CR0_WP;
18777+ BUG_ON(cr0 & X86_CR0_WP);
18778+ write_cr0(cr0);
18779+ barrier();
18780+ return cr0 ^ X86_CR0_WP;
18781+}
18782+
18783+static inline unsigned long native_pax_close_kernel(void)
18784+{
18785+ unsigned long cr0;
18786+
18787+ barrier();
18788+ cr0 = read_cr0() ^ X86_CR0_WP;
18789+ BUG_ON(!(cr0 & X86_CR0_WP));
18790+ write_cr0(cr0);
18791+ barrier();
18792+ preempt_enable_no_resched();
18793+ return cr0 ^ X86_CR0_WP;
18794+}
18795+#else
18796+static inline unsigned long native_pax_open_kernel(void) { return 0; }
18797+static inline unsigned long native_pax_close_kernel(void) { return 0; }
18798+#endif
18799+
18800 /*
18801 * The following only work if pte_present() is true.
18802 * Undefined behaviour if not..
18803 */
18804+static inline int pte_user(pte_t pte)
18805+{
18806+ return pte_val(pte) & _PAGE_USER;
18807+}
18808+
18809 static inline int pte_dirty(pte_t pte)
18810 {
18811 return pte_flags(pte) & _PAGE_DIRTY;
18812@@ -155,6 +197,11 @@ static inline unsigned long pud_pfn(pud_t pud)
18813 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
18814 }
18815
18816+static inline unsigned long pgd_pfn(pgd_t pgd)
18817+{
18818+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
18819+}
18820+
18821 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
18822
18823 static inline int pmd_large(pmd_t pte)
18824@@ -208,9 +255,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
18825 return pte_clear_flags(pte, _PAGE_RW);
18826 }
18827
18828+static inline pte_t pte_mkread(pte_t pte)
18829+{
18830+ return __pte(pte_val(pte) | _PAGE_USER);
18831+}
18832+
18833 static inline pte_t pte_mkexec(pte_t pte)
18834 {
18835- return pte_clear_flags(pte, _PAGE_NX);
18836+#ifdef CONFIG_X86_PAE
18837+ if (__supported_pte_mask & _PAGE_NX)
18838+ return pte_clear_flags(pte, _PAGE_NX);
18839+ else
18840+#endif
18841+ return pte_set_flags(pte, _PAGE_USER);
18842+}
18843+
18844+static inline pte_t pte_exprotect(pte_t pte)
18845+{
18846+#ifdef CONFIG_X86_PAE
18847+ if (__supported_pte_mask & _PAGE_NX)
18848+ return pte_set_flags(pte, _PAGE_NX);
18849+ else
18850+#endif
18851+ return pte_clear_flags(pte, _PAGE_USER);
18852 }
18853
18854 static inline pte_t pte_mkdirty(pte_t pte)
18855@@ -440,6 +507,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
18856 #endif
18857
18858 #ifndef __ASSEMBLY__
18859+
18860+#ifdef CONFIG_PAX_PER_CPU_PGD
18861+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
18862+enum cpu_pgd_type {kernel = 0, user = 1};
18863+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
18864+{
18865+ return cpu_pgd[cpu][type];
18866+}
18867+#endif
18868+
18869 #include <linux/mm_types.h>
18870 #include <linux/mmdebug.h>
18871 #include <linux/log2.h>
18872@@ -586,7 +663,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18873 * Currently stuck as a macro due to indirect forward reference to
18874 * linux/mmzone.h's __section_mem_map_addr() definition:
18875 */
18876-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18877+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18878
18879 /* Find an entry in the second-level page table.. */
18880 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18881@@ -626,7 +703,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18882 * Currently stuck as a macro due to indirect forward reference to
18883 * linux/mmzone.h's __section_mem_map_addr() definition:
18884 */
18885-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18886+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18887
18888 /* to find an entry in a page-table-directory. */
18889 static inline unsigned long pud_index(unsigned long address)
18890@@ -641,7 +718,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18891
18892 static inline int pgd_bad(pgd_t pgd)
18893 {
18894- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18895+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18896 }
18897
18898 static inline int pgd_none(pgd_t pgd)
18899@@ -664,7 +741,12 @@ static inline int pgd_none(pgd_t pgd)
18900 * pgd_offset() returns a (pgd_t *)
18901 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18902 */
18903-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18904+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18905+
18906+#ifdef CONFIG_PAX_PER_CPU_PGD
18907+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18908+#endif
18909+
18910 /*
18911 * a shortcut which implies the use of the kernel's pgd, instead
18912 * of a process's
18913@@ -675,6 +757,23 @@ static inline int pgd_none(pgd_t pgd)
18914 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18915 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18916
18917+#ifdef CONFIG_X86_32
18918+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18919+#else
18920+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18921+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18922+
18923+#ifdef CONFIG_PAX_MEMORY_UDEREF
18924+#ifdef __ASSEMBLY__
18925+#define pax_user_shadow_base pax_user_shadow_base(%rip)
18926+#else
18927+extern unsigned long pax_user_shadow_base;
18928+extern pgdval_t clone_pgd_mask;
18929+#endif
18930+#endif
18931+
18932+#endif
18933+
18934 #ifndef __ASSEMBLY__
18935
18936 extern int direct_gbpages;
18937@@ -841,11 +940,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18938 * dst and src can be on the same page, but the range must not overlap,
18939 * and must not cross a page boundary.
18940 */
18941-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18942+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18943 {
18944- memcpy(dst, src, count * sizeof(pgd_t));
18945+ pax_open_kernel();
18946+ while (count--)
18947+ *dst++ = *src++;
18948+ pax_close_kernel();
18949 }
18950
18951+#ifdef CONFIG_PAX_PER_CPU_PGD
18952+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18953+#endif
18954+
18955+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18956+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18957+#else
18958+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18959+#endif
18960+
18961 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18962 static inline int page_level_shift(enum pg_level level)
18963 {
18964diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18965index 9ee3221..b979c6b 100644
18966--- a/arch/x86/include/asm/pgtable_32.h
18967+++ b/arch/x86/include/asm/pgtable_32.h
18968@@ -25,9 +25,6 @@
18969 struct mm_struct;
18970 struct vm_area_struct;
18971
18972-extern pgd_t swapper_pg_dir[1024];
18973-extern pgd_t initial_page_table[1024];
18974-
18975 static inline void pgtable_cache_init(void) { }
18976 static inline void check_pgt_cache(void) { }
18977 void paging_init(void);
18978@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18979 # include <asm/pgtable-2level.h>
18980 #endif
18981
18982+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18983+extern pgd_t initial_page_table[PTRS_PER_PGD];
18984+#ifdef CONFIG_X86_PAE
18985+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18986+#endif
18987+
18988 #if defined(CONFIG_HIGHPTE)
18989 #define pte_offset_map(dir, address) \
18990 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18991@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18992 /* Clear a kernel PTE and flush it from the TLB */
18993 #define kpte_clear_flush(ptep, vaddr) \
18994 do { \
18995+ pax_open_kernel(); \
18996 pte_clear(&init_mm, (vaddr), (ptep)); \
18997+ pax_close_kernel(); \
18998 __flush_tlb_one((vaddr)); \
18999 } while (0)
19000
19001 #endif /* !__ASSEMBLY__ */
19002
19003+#define HAVE_ARCH_UNMAPPED_AREA
19004+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
19005+
19006 /*
19007 * kern_addr_valid() is (1) for FLATMEM and (0) for
19008 * SPARSEMEM and DISCONTIGMEM
19009diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
19010index ed5903b..c7fe163 100644
19011--- a/arch/x86/include/asm/pgtable_32_types.h
19012+++ b/arch/x86/include/asm/pgtable_32_types.h
19013@@ -8,7 +8,7 @@
19014 */
19015 #ifdef CONFIG_X86_PAE
19016 # include <asm/pgtable-3level_types.h>
19017-# define PMD_SIZE (1UL << PMD_SHIFT)
19018+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
19019 # define PMD_MASK (~(PMD_SIZE - 1))
19020 #else
19021 # include <asm/pgtable-2level_types.h>
19022@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
19023 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
19024 #endif
19025
19026+#ifdef CONFIG_PAX_KERNEXEC
19027+#ifndef __ASSEMBLY__
19028+extern unsigned char MODULES_EXEC_VADDR[];
19029+extern unsigned char MODULES_EXEC_END[];
19030+#endif
19031+#include <asm/boot.h>
19032+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
19033+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
19034+#else
19035+#define ktla_ktva(addr) (addr)
19036+#define ktva_ktla(addr) (addr)
19037+#endif
19038+
19039 #define MODULES_VADDR VMALLOC_START
19040 #define MODULES_END VMALLOC_END
19041 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
19042diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
19043index 3874693..d7906ac 100644
19044--- a/arch/x86/include/asm/pgtable_64.h
19045+++ b/arch/x86/include/asm/pgtable_64.h
19046@@ -16,11 +16,16 @@
19047
19048 extern pud_t level3_kernel_pgt[512];
19049 extern pud_t level3_ident_pgt[512];
19050+extern pud_t level3_vmalloc_start_pgt[512];
19051+extern pud_t level3_vmalloc_end_pgt[512];
19052+extern pud_t level3_vmemmap_pgt[512];
19053+extern pud_t level2_vmemmap_pgt[512];
19054 extern pmd_t level2_kernel_pgt[512];
19055 extern pmd_t level2_fixmap_pgt[512];
19056-extern pmd_t level2_ident_pgt[512];
19057+extern pmd_t level2_ident_pgt[512*2];
19058 extern pte_t level1_fixmap_pgt[512];
19059-extern pgd_t init_level4_pgt[];
19060+extern pte_t level1_vsyscall_pgt[512];
19061+extern pgd_t init_level4_pgt[512];
19062
19063 #define swapper_pg_dir init_level4_pgt
19064
19065@@ -62,7 +67,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
19066
19067 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
19068 {
19069+ pax_open_kernel();
19070 *pmdp = pmd;
19071+ pax_close_kernel();
19072 }
19073
19074 static inline void native_pmd_clear(pmd_t *pmd)
19075@@ -98,7 +105,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
19076
19077 static inline void native_set_pud(pud_t *pudp, pud_t pud)
19078 {
19079+ pax_open_kernel();
19080 *pudp = pud;
19081+ pax_close_kernel();
19082 }
19083
19084 static inline void native_pud_clear(pud_t *pud)
19085@@ -108,6 +117,13 @@ static inline void native_pud_clear(pud_t *pud)
19086
19087 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
19088 {
19089+ pax_open_kernel();
19090+ *pgdp = pgd;
19091+ pax_close_kernel();
19092+}
19093+
19094+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
19095+{
19096 *pgdp = pgd;
19097 }
19098
19099diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
19100index 7166e25..baaa6fe 100644
19101--- a/arch/x86/include/asm/pgtable_64_types.h
19102+++ b/arch/x86/include/asm/pgtable_64_types.h
19103@@ -61,9 +61,14 @@ typedef struct { pteval_t pte; } pte_t;
19104 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
19105 #define MODULES_END _AC(0xffffffffff000000, UL)
19106 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
19107+#define MODULES_EXEC_VADDR MODULES_VADDR
19108+#define MODULES_EXEC_END MODULES_END
19109 #define ESPFIX_PGD_ENTRY _AC(-2, UL)
19110 #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << PGDIR_SHIFT)
19111
19112+#define ktla_ktva(addr) (addr)
19113+#define ktva_ktla(addr) (addr)
19114+
19115 #define EARLY_DYNAMIC_PAGE_TABLES 64
19116
19117 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
19118diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
19119index f216963..6bd7c21 100644
19120--- a/arch/x86/include/asm/pgtable_types.h
19121+++ b/arch/x86/include/asm/pgtable_types.h
19122@@ -111,8 +111,10 @@
19123
19124 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
19125 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
19126-#else
19127+#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
19128 #define _PAGE_NX (_AT(pteval_t, 0))
19129+#else
19130+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
19131 #endif
19132
19133 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
19134@@ -151,6 +153,9 @@
19135 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
19136 _PAGE_ACCESSED)
19137
19138+#define PAGE_READONLY_NOEXEC PAGE_READONLY
19139+#define PAGE_SHARED_NOEXEC PAGE_SHARED
19140+
19141 #define __PAGE_KERNEL_EXEC \
19142 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
19143 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
19144@@ -161,7 +166,7 @@
19145 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
19146 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
19147 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
19148-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
19149+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
19150 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
19151 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
19152 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
19153@@ -218,7 +223,7 @@
19154 #ifdef CONFIG_X86_64
19155 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
19156 #else
19157-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
19158+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
19159 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
19160 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
19161 #endif
19162@@ -257,7 +262,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
19163 {
19164 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
19165 }
19166+#endif
19167
19168+#if PAGETABLE_LEVELS == 3
19169+#include <asm-generic/pgtable-nopud.h>
19170+#endif
19171+
19172+#if PAGETABLE_LEVELS == 2
19173+#include <asm-generic/pgtable-nopmd.h>
19174+#endif
19175+
19176+#ifndef __ASSEMBLY__
19177 #if PAGETABLE_LEVELS > 3
19178 typedef struct { pudval_t pud; } pud_t;
19179
19180@@ -271,8 +286,6 @@ static inline pudval_t native_pud_val(pud_t pud)
19181 return pud.pud;
19182 }
19183 #else
19184-#include <asm-generic/pgtable-nopud.h>
19185-
19186 static inline pudval_t native_pud_val(pud_t pud)
19187 {
19188 return native_pgd_val(pud.pgd);
19189@@ -292,8 +305,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
19190 return pmd.pmd;
19191 }
19192 #else
19193-#include <asm-generic/pgtable-nopmd.h>
19194-
19195 static inline pmdval_t native_pmd_val(pmd_t pmd)
19196 {
19197 return native_pgd_val(pmd.pud.pgd);
19198@@ -333,7 +344,6 @@ typedef struct page *pgtable_t;
19199
19200 extern pteval_t __supported_pte_mask;
19201 extern void set_nx(void);
19202-extern int nx_enabled;
19203
19204 #define pgprot_writecombine pgprot_writecombine
19205 extern pgprot_t pgprot_writecombine(pgprot_t prot);
19206diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
19207index 7024c12..71c46b9 100644
19208--- a/arch/x86/include/asm/preempt.h
19209+++ b/arch/x86/include/asm/preempt.h
19210@@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
19211 */
19212 static __always_inline bool __preempt_count_dec_and_test(void)
19213 {
19214- GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
19215+ GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
19216 }
19217
19218 /*
19219diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
19220index eb71ec7..f06532a 100644
19221--- a/arch/x86/include/asm/processor.h
19222+++ b/arch/x86/include/asm/processor.h
19223@@ -127,7 +127,7 @@ struct cpuinfo_x86 {
19224 /* Index into per_cpu list: */
19225 u16 cpu_index;
19226 u32 microcode;
19227-} __attribute__((__aligned__(SMP_CACHE_BYTES)));
19228+} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
19229
19230 #define X86_VENDOR_INTEL 0
19231 #define X86_VENDOR_CYRIX 1
19232@@ -198,9 +198,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
19233 : "memory");
19234 }
19235
19236+/* invpcid (%rdx),%rax */
19237+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
19238+
19239+#define INVPCID_SINGLE_ADDRESS 0UL
19240+#define INVPCID_SINGLE_CONTEXT 1UL
19241+#define INVPCID_ALL_GLOBAL 2UL
19242+#define INVPCID_ALL_NONGLOBAL 3UL
19243+
19244+#define PCID_KERNEL 0UL
19245+#define PCID_USER 1UL
19246+#define PCID_NOFLUSH (1UL << 63)
19247+
19248 static inline void load_cr3(pgd_t *pgdir)
19249 {
19250- write_cr3(__pa(pgdir));
19251+ write_cr3(__pa(pgdir) | PCID_KERNEL);
19252 }
19253
19254 #ifdef CONFIG_X86_32
19255@@ -282,7 +294,7 @@ struct tss_struct {
19256
19257 } ____cacheline_aligned;
19258
19259-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
19260+extern struct tss_struct init_tss[NR_CPUS];
19261
19262 /*
19263 * Save the original ist values for checking stack pointers during debugging
19264@@ -478,6 +490,7 @@ struct thread_struct {
19265 unsigned short ds;
19266 unsigned short fsindex;
19267 unsigned short gsindex;
19268+ unsigned short ss;
19269 #endif
19270 #ifdef CONFIG_X86_32
19271 unsigned long ip;
19272@@ -587,29 +600,8 @@ static inline void load_sp0(struct tss_struct *tss,
19273 extern unsigned long mmu_cr4_features;
19274 extern u32 *trampoline_cr4_features;
19275
19276-static inline void set_in_cr4(unsigned long mask)
19277-{
19278- unsigned long cr4;
19279-
19280- mmu_cr4_features |= mask;
19281- if (trampoline_cr4_features)
19282- *trampoline_cr4_features = mmu_cr4_features;
19283- cr4 = read_cr4();
19284- cr4 |= mask;
19285- write_cr4(cr4);
19286-}
19287-
19288-static inline void clear_in_cr4(unsigned long mask)
19289-{
19290- unsigned long cr4;
19291-
19292- mmu_cr4_features &= ~mask;
19293- if (trampoline_cr4_features)
19294- *trampoline_cr4_features = mmu_cr4_features;
19295- cr4 = read_cr4();
19296- cr4 &= ~mask;
19297- write_cr4(cr4);
19298-}
19299+extern void set_in_cr4(unsigned long mask);
19300+extern void clear_in_cr4(unsigned long mask);
19301
19302 typedef struct {
19303 unsigned long seg;
19304@@ -837,11 +829,18 @@ static inline void spin_lock_prefetch(const void *x)
19305 */
19306 #define TASK_SIZE PAGE_OFFSET
19307 #define TASK_SIZE_MAX TASK_SIZE
19308+
19309+#ifdef CONFIG_PAX_SEGMEXEC
19310+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
19311+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
19312+#else
19313 #define STACK_TOP TASK_SIZE
19314-#define STACK_TOP_MAX STACK_TOP
19315+#endif
19316+
19317+#define STACK_TOP_MAX TASK_SIZE
19318
19319 #define INIT_THREAD { \
19320- .sp0 = sizeof(init_stack) + (long)&init_stack, \
19321+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
19322 .vm86_info = NULL, \
19323 .sysenter_cs = __KERNEL_CS, \
19324 .io_bitmap_ptr = NULL, \
19325@@ -855,7 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
19326 */
19327 #define INIT_TSS { \
19328 .x86_tss = { \
19329- .sp0 = sizeof(init_stack) + (long)&init_stack, \
19330+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
19331 .ss0 = __KERNEL_DS, \
19332 .ss1 = __KERNEL_CS, \
19333 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
19334@@ -866,11 +865,7 @@ static inline void spin_lock_prefetch(const void *x)
19335 extern unsigned long thread_saved_pc(struct task_struct *tsk);
19336
19337 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
19338-#define KSTK_TOP(info) \
19339-({ \
19340- unsigned long *__ptr = (unsigned long *)(info); \
19341- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
19342-})
19343+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
19344
19345 /*
19346 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
19347@@ -885,7 +880,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
19348 #define task_pt_regs(task) \
19349 ({ \
19350 struct pt_regs *__regs__; \
19351- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
19352+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
19353 __regs__ - 1; \
19354 })
19355
19356@@ -895,13 +890,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
19357 /*
19358 * User space process size. 47bits minus one guard page.
19359 */
19360-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
19361+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
19362
19363 /* This decides where the kernel will search for a free chunk of vm
19364 * space during mmap's.
19365 */
19366 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
19367- 0xc0000000 : 0xFFFFe000)
19368+ 0xc0000000 : 0xFFFFf000)
19369
19370 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
19371 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
19372@@ -912,11 +907,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
19373 #define STACK_TOP_MAX TASK_SIZE_MAX
19374
19375 #define INIT_THREAD { \
19376- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
19377+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
19378 }
19379
19380 #define INIT_TSS { \
19381- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
19382+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
19383 }
19384
19385 /*
19386@@ -944,6 +939,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
19387 */
19388 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
19389
19390+#ifdef CONFIG_PAX_SEGMEXEC
19391+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
19392+#endif
19393+
19394 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
19395
19396 /* Get/set a process' ability to use the timestamp counter instruction */
19397@@ -970,7 +969,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
19398 return 0;
19399 }
19400
19401-extern unsigned long arch_align_stack(unsigned long sp);
19402+#define arch_align_stack(x) ((x) & ~0xfUL)
19403 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
19404
19405 void default_idle(void);
19406@@ -980,6 +979,6 @@ bool xen_set_default_idle(void);
19407 #define xen_set_default_idle 0
19408 #endif
19409
19410-void stop_this_cpu(void *dummy);
19411+void stop_this_cpu(void *dummy) __noreturn;
19412 void df_debug(struct pt_regs *regs, long error_code);
19413 #endif /* _ASM_X86_PROCESSOR_H */
19414diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
19415index 6205f0c..688a3a9 100644
19416--- a/arch/x86/include/asm/ptrace.h
19417+++ b/arch/x86/include/asm/ptrace.h
19418@@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
19419 }
19420
19421 /*
19422- * user_mode_vm(regs) determines whether a register set came from user mode.
19423+ * user_mode(regs) determines whether a register set came from user mode.
19424 * This is true if V8086 mode was enabled OR if the register set was from
19425 * protected mode with RPL-3 CS value. This tricky test checks that with
19426 * one comparison. Many places in the kernel can bypass this full check
19427- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
19428+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
19429+ * be used.
19430 */
19431-static inline int user_mode(struct pt_regs *regs)
19432+static inline int user_mode_novm(struct pt_regs *regs)
19433 {
19434 #ifdef CONFIG_X86_32
19435 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
19436 #else
19437- return !!(regs->cs & 3);
19438+ return !!(regs->cs & SEGMENT_RPL_MASK);
19439 #endif
19440 }
19441
19442-static inline int user_mode_vm(struct pt_regs *regs)
19443+static inline int user_mode(struct pt_regs *regs)
19444 {
19445 #ifdef CONFIG_X86_32
19446 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
19447 USER_RPL;
19448 #else
19449- return user_mode(regs);
19450+ return user_mode_novm(regs);
19451 #endif
19452 }
19453
19454@@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
19455 #ifdef CONFIG_X86_64
19456 static inline bool user_64bit_mode(struct pt_regs *regs)
19457 {
19458+ unsigned long cs = regs->cs & 0xffff;
19459 #ifndef CONFIG_PARAVIRT
19460 /*
19461 * On non-paravirt systems, this is the only long mode CPL 3
19462 * selector. We do not allow long mode selectors in the LDT.
19463 */
19464- return regs->cs == __USER_CS;
19465+ return cs == __USER_CS;
19466 #else
19467 /* Headers are too twisted for this to go in paravirt.h. */
19468- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
19469+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
19470 #endif
19471 }
19472
19473@@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
19474 * Traps from the kernel do not save sp and ss.
19475 * Use the helper function to retrieve sp.
19476 */
19477- if (offset == offsetof(struct pt_regs, sp) &&
19478- regs->cs == __KERNEL_CS)
19479- return kernel_stack_pointer(regs);
19480+ if (offset == offsetof(struct pt_regs, sp)) {
19481+ unsigned long cs = regs->cs & 0xffff;
19482+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
19483+ return kernel_stack_pointer(regs);
19484+ }
19485 #endif
19486 return *(unsigned long *)((unsigned long)regs + offset);
19487 }
19488diff --git a/arch/x86/include/asm/qrwlock.h b/arch/x86/include/asm/qrwlock.h
19489index ae0e241..e80b10b 100644
19490--- a/arch/x86/include/asm/qrwlock.h
19491+++ b/arch/x86/include/asm/qrwlock.h
19492@@ -7,8 +7,8 @@
19493 #define queue_write_unlock queue_write_unlock
19494 static inline void queue_write_unlock(struct qrwlock *lock)
19495 {
19496- barrier();
19497- ACCESS_ONCE(*(u8 *)&lock->cnts) = 0;
19498+ barrier();
19499+ ACCESS_ONCE_RW(*(u8 *)&lock->cnts) = 0;
19500 }
19501 #endif
19502
19503diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
19504index 9c6b890..5305f53 100644
19505--- a/arch/x86/include/asm/realmode.h
19506+++ b/arch/x86/include/asm/realmode.h
19507@@ -22,16 +22,14 @@ struct real_mode_header {
19508 #endif
19509 /* APM/BIOS reboot */
19510 u32 machine_real_restart_asm;
19511-#ifdef CONFIG_X86_64
19512 u32 machine_real_restart_seg;
19513-#endif
19514 };
19515
19516 /* This must match data at trampoline_32/64.S */
19517 struct trampoline_header {
19518 #ifdef CONFIG_X86_32
19519 u32 start;
19520- u16 gdt_pad;
19521+ u16 boot_cs;
19522 u16 gdt_limit;
19523 u32 gdt_base;
19524 #else
19525diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
19526index a82c4f1..ac45053 100644
19527--- a/arch/x86/include/asm/reboot.h
19528+++ b/arch/x86/include/asm/reboot.h
19529@@ -6,13 +6,13 @@
19530 struct pt_regs;
19531
19532 struct machine_ops {
19533- void (*restart)(char *cmd);
19534- void (*halt)(void);
19535- void (*power_off)(void);
19536+ void (* __noreturn restart)(char *cmd);
19537+ void (* __noreturn halt)(void);
19538+ void (* __noreturn power_off)(void);
19539 void (*shutdown)(void);
19540 void (*crash_shutdown)(struct pt_regs *);
19541- void (*emergency_restart)(void);
19542-};
19543+ void (* __noreturn emergency_restart)(void);
19544+} __no_const;
19545
19546 extern struct machine_ops machine_ops;
19547
19548diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
19549index 8f7866a..e442f20 100644
19550--- a/arch/x86/include/asm/rmwcc.h
19551+++ b/arch/x86/include/asm/rmwcc.h
19552@@ -3,7 +3,34 @@
19553
19554 #ifdef CC_HAVE_ASM_GOTO
19555
19556-#define __GEN_RMWcc(fullop, var, cc, ...) \
19557+#ifdef CONFIG_PAX_REFCOUNT
19558+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19559+do { \
19560+ asm_volatile_goto (fullop \
19561+ ";jno 0f\n" \
19562+ fullantiop \
19563+ ";int $4\n0:\n" \
19564+ _ASM_EXTABLE(0b, 0b) \
19565+ ";j" cc " %l[cc_label]" \
19566+ : : "m" (var), ## __VA_ARGS__ \
19567+ : "memory" : cc_label); \
19568+ return 0; \
19569+cc_label: \
19570+ return 1; \
19571+} while (0)
19572+#else
19573+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19574+do { \
19575+ asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
19576+ : : "m" (var), ## __VA_ARGS__ \
19577+ : "memory" : cc_label); \
19578+ return 0; \
19579+cc_label: \
19580+ return 1; \
19581+} while (0)
19582+#endif
19583+
19584+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
19585 do { \
19586 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
19587 : : "m" (var), ## __VA_ARGS__ \
19588@@ -13,15 +40,46 @@ cc_label: \
19589 return 1; \
19590 } while (0)
19591
19592-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
19593- __GEN_RMWcc(op " " arg0, var, cc)
19594+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
19595+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
19596
19597-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
19598- __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
19599+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
19600+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
19601+
19602+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
19603+ __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
19604+
19605+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
19606+ __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
19607
19608 #else /* !CC_HAVE_ASM_GOTO */
19609
19610-#define __GEN_RMWcc(fullop, var, cc, ...) \
19611+#ifdef CONFIG_PAX_REFCOUNT
19612+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19613+do { \
19614+ char c; \
19615+ asm volatile (fullop \
19616+ ";jno 0f\n" \
19617+ fullantiop \
19618+ ";int $4\n0:\n" \
19619+ _ASM_EXTABLE(0b, 0b) \
19620+ "; set" cc " %1" \
19621+ : "+m" (var), "=qm" (c) \
19622+ : __VA_ARGS__ : "memory"); \
19623+ return c != 0; \
19624+} while (0)
19625+#else
19626+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19627+do { \
19628+ char c; \
19629+ asm volatile (fullop "; set" cc " %1" \
19630+ : "+m" (var), "=qm" (c) \
19631+ : __VA_ARGS__ : "memory"); \
19632+ return c != 0; \
19633+} while (0)
19634+#endif
19635+
19636+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
19637 do { \
19638 char c; \
19639 asm volatile (fullop "; set" cc " %1" \
19640@@ -30,11 +88,17 @@ do { \
19641 return c != 0; \
19642 } while (0)
19643
19644-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
19645- __GEN_RMWcc(op " " arg0, var, cc)
19646+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
19647+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
19648+
19649+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
19650+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
19651+
19652+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
19653+ __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
19654
19655-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
19656- __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
19657+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
19658+ __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
19659
19660 #endif /* CC_HAVE_ASM_GOTO */
19661
19662diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
19663index cad82c9..2e5c5c1 100644
19664--- a/arch/x86/include/asm/rwsem.h
19665+++ b/arch/x86/include/asm/rwsem.h
19666@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
19667 {
19668 asm volatile("# beginning down_read\n\t"
19669 LOCK_PREFIX _ASM_INC "(%1)\n\t"
19670+
19671+#ifdef CONFIG_PAX_REFCOUNT
19672+ "jno 0f\n"
19673+ LOCK_PREFIX _ASM_DEC "(%1)\n"
19674+ "int $4\n0:\n"
19675+ _ASM_EXTABLE(0b, 0b)
19676+#endif
19677+
19678 /* adds 0x00000001 */
19679 " jns 1f\n"
19680 " call call_rwsem_down_read_failed\n"
19681@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
19682 "1:\n\t"
19683 " mov %1,%2\n\t"
19684 " add %3,%2\n\t"
19685+
19686+#ifdef CONFIG_PAX_REFCOUNT
19687+ "jno 0f\n"
19688+ "sub %3,%2\n"
19689+ "int $4\n0:\n"
19690+ _ASM_EXTABLE(0b, 0b)
19691+#endif
19692+
19693 " jle 2f\n\t"
19694 LOCK_PREFIX " cmpxchg %2,%0\n\t"
19695 " jnz 1b\n\t"
19696@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
19697 long tmp;
19698 asm volatile("# beginning down_write\n\t"
19699 LOCK_PREFIX " xadd %1,(%2)\n\t"
19700+
19701+#ifdef CONFIG_PAX_REFCOUNT
19702+ "jno 0f\n"
19703+ "mov %1,(%2)\n"
19704+ "int $4\n0:\n"
19705+ _ASM_EXTABLE(0b, 0b)
19706+#endif
19707+
19708 /* adds 0xffff0001, returns the old value */
19709 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
19710 /* was the active mask 0 before? */
19711@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
19712 long tmp;
19713 asm volatile("# beginning __up_read\n\t"
19714 LOCK_PREFIX " xadd %1,(%2)\n\t"
19715+
19716+#ifdef CONFIG_PAX_REFCOUNT
19717+ "jno 0f\n"
19718+ "mov %1,(%2)\n"
19719+ "int $4\n0:\n"
19720+ _ASM_EXTABLE(0b, 0b)
19721+#endif
19722+
19723 /* subtracts 1, returns the old value */
19724 " jns 1f\n\t"
19725 " call call_rwsem_wake\n" /* expects old value in %edx */
19726@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
19727 long tmp;
19728 asm volatile("# beginning __up_write\n\t"
19729 LOCK_PREFIX " xadd %1,(%2)\n\t"
19730+
19731+#ifdef CONFIG_PAX_REFCOUNT
19732+ "jno 0f\n"
19733+ "mov %1,(%2)\n"
19734+ "int $4\n0:\n"
19735+ _ASM_EXTABLE(0b, 0b)
19736+#endif
19737+
19738 /* subtracts 0xffff0001, returns the old value */
19739 " jns 1f\n\t"
19740 " call call_rwsem_wake\n" /* expects old value in %edx */
19741@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19742 {
19743 asm volatile("# beginning __downgrade_write\n\t"
19744 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
19745+
19746+#ifdef CONFIG_PAX_REFCOUNT
19747+ "jno 0f\n"
19748+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
19749+ "int $4\n0:\n"
19750+ _ASM_EXTABLE(0b, 0b)
19751+#endif
19752+
19753 /*
19754 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
19755 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
19756@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19757 */
19758 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19759 {
19760- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
19761+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
19762+
19763+#ifdef CONFIG_PAX_REFCOUNT
19764+ "jno 0f\n"
19765+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
19766+ "int $4\n0:\n"
19767+ _ASM_EXTABLE(0b, 0b)
19768+#endif
19769+
19770 : "+m" (sem->count)
19771 : "er" (delta));
19772 }
19773@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19774 */
19775 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
19776 {
19777- return delta + xadd(&sem->count, delta);
19778+ return delta + xadd_check_overflow(&sem->count, delta);
19779 }
19780
19781 #endif /* __KERNEL__ */
19782diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
19783index 6f1c3a8..7744f19 100644
19784--- a/arch/x86/include/asm/segment.h
19785+++ b/arch/x86/include/asm/segment.h
19786@@ -64,10 +64,15 @@
19787 * 26 - ESPFIX small SS
19788 * 27 - per-cpu [ offset to per-cpu data area ]
19789 * 28 - stack_canary-20 [ for stack protector ]
19790- * 29 - unused
19791- * 30 - unused
19792+ * 29 - PCI BIOS CS
19793+ * 30 - PCI BIOS DS
19794 * 31 - TSS for double fault handler
19795 */
19796+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
19797+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
19798+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
19799+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
19800+
19801 #define GDT_ENTRY_TLS_MIN 6
19802 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
19803
19804@@ -79,6 +84,8 @@
19805
19806 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
19807
19808+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
19809+
19810 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
19811
19812 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
19813@@ -104,6 +111,12 @@
19814 #define __KERNEL_STACK_CANARY 0
19815 #endif
19816
19817+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
19818+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
19819+
19820+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
19821+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
19822+
19823 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
19824
19825 /*
19826@@ -141,7 +154,7 @@
19827 */
19828
19829 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
19830-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
19831+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
19832
19833
19834 #else
19835@@ -165,6 +178,8 @@
19836 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
19837 #define __USER32_DS __USER_DS
19838
19839+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
19840+
19841 #define GDT_ENTRY_TSS 8 /* needs two entries */
19842 #define GDT_ENTRY_LDT 10 /* needs two entries */
19843 #define GDT_ENTRY_TLS_MIN 12
19844@@ -173,6 +188,8 @@
19845 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
19846 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
19847
19848+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
19849+
19850 /* TLS indexes for 64bit - hardcoded in arch_prctl */
19851 #define FS_TLS 0
19852 #define GS_TLS 1
19853@@ -180,12 +197,14 @@
19854 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
19855 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
19856
19857-#define GDT_ENTRIES 16
19858+#define GDT_ENTRIES 17
19859
19860 #endif
19861
19862 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19863+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19864 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19865+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19866 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19867 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19868 #ifndef CONFIG_PARAVIRT
19869@@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19870 {
19871 unsigned long __limit;
19872 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19873- return __limit + 1;
19874+ return __limit;
19875 }
19876
19877 #endif /* !__ASSEMBLY__ */
19878diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19879index 8d3120f..352b440 100644
19880--- a/arch/x86/include/asm/smap.h
19881+++ b/arch/x86/include/asm/smap.h
19882@@ -25,11 +25,40 @@
19883
19884 #include <asm/alternative-asm.h>
19885
19886+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19887+#define ASM_PAX_OPEN_USERLAND \
19888+ 661: jmp 663f; \
19889+ .pushsection .altinstr_replacement, "a" ; \
19890+ 662: pushq %rax; nop; \
19891+ .popsection ; \
19892+ .pushsection .altinstructions, "a" ; \
19893+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19894+ .popsection ; \
19895+ call __pax_open_userland; \
19896+ popq %rax; \
19897+ 663:
19898+
19899+#define ASM_PAX_CLOSE_USERLAND \
19900+ 661: jmp 663f; \
19901+ .pushsection .altinstr_replacement, "a" ; \
19902+ 662: pushq %rax; nop; \
19903+ .popsection; \
19904+ .pushsection .altinstructions, "a" ; \
19905+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19906+ .popsection; \
19907+ call __pax_close_userland; \
19908+ popq %rax; \
19909+ 663:
19910+#else
19911+#define ASM_PAX_OPEN_USERLAND
19912+#define ASM_PAX_CLOSE_USERLAND
19913+#endif
19914+
19915 #ifdef CONFIG_X86_SMAP
19916
19917 #define ASM_CLAC \
19918 661: ASM_NOP3 ; \
19919- .pushsection .altinstr_replacement, "ax" ; \
19920+ .pushsection .altinstr_replacement, "a" ; \
19921 662: __ASM_CLAC ; \
19922 .popsection ; \
19923 .pushsection .altinstructions, "a" ; \
19924@@ -38,7 +67,7 @@
19925
19926 #define ASM_STAC \
19927 661: ASM_NOP3 ; \
19928- .pushsection .altinstr_replacement, "ax" ; \
19929+ .pushsection .altinstr_replacement, "a" ; \
19930 662: __ASM_STAC ; \
19931 .popsection ; \
19932 .pushsection .altinstructions, "a" ; \
19933@@ -56,6 +85,37 @@
19934
19935 #include <asm/alternative.h>
19936
19937+#define __HAVE_ARCH_PAX_OPEN_USERLAND
19938+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19939+
19940+extern void __pax_open_userland(void);
19941+static __always_inline unsigned long pax_open_userland(void)
19942+{
19943+
19944+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19945+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19946+ :
19947+ : [open] "i" (__pax_open_userland)
19948+ : "memory", "rax");
19949+#endif
19950+
19951+ return 0;
19952+}
19953+
19954+extern void __pax_close_userland(void);
19955+static __always_inline unsigned long pax_close_userland(void)
19956+{
19957+
19958+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19959+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19960+ :
19961+ : [close] "i" (__pax_close_userland)
19962+ : "memory", "rax");
19963+#endif
19964+
19965+ return 0;
19966+}
19967+
19968 #ifdef CONFIG_X86_SMAP
19969
19970 static __always_inline void clac(void)
19971diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19972index 8cd27e0..7f05ec8 100644
19973--- a/arch/x86/include/asm/smp.h
19974+++ b/arch/x86/include/asm/smp.h
19975@@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19976 /* cpus sharing the last level cache: */
19977 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19978 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19979-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19980+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19981
19982 static inline struct cpumask *cpu_sibling_mask(int cpu)
19983 {
19984@@ -78,7 +78,7 @@ struct smp_ops {
19985
19986 void (*send_call_func_ipi)(const struct cpumask *mask);
19987 void (*send_call_func_single_ipi)(int cpu);
19988-};
19989+} __no_const;
19990
19991 /* Globals due to paravirt */
19992 extern void set_cpu_sibling_map(int cpu);
19993@@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
19994 extern int safe_smp_processor_id(void);
19995
19996 #elif defined(CONFIG_X86_64_SMP)
19997-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19998-
19999-#define stack_smp_processor_id() \
20000-({ \
20001- struct thread_info *ti; \
20002- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
20003- ti->cpu; \
20004-})
20005+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
20006+#define stack_smp_processor_id() raw_smp_processor_id()
20007 #define safe_smp_processor_id() smp_processor_id()
20008
20009 #endif
20010diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
20011index 54f1c80..39362a5 100644
20012--- a/arch/x86/include/asm/spinlock.h
20013+++ b/arch/x86/include/asm/spinlock.h
20014@@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
20015 static inline void arch_read_lock(arch_rwlock_t *rw)
20016 {
20017 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
20018+
20019+#ifdef CONFIG_PAX_REFCOUNT
20020+ "jno 0f\n"
20021+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
20022+ "int $4\n0:\n"
20023+ _ASM_EXTABLE(0b, 0b)
20024+#endif
20025+
20026 "jns 1f\n"
20027 "call __read_lock_failed\n\t"
20028 "1:\n"
20029@@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
20030 static inline void arch_write_lock(arch_rwlock_t *rw)
20031 {
20032 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
20033+
20034+#ifdef CONFIG_PAX_REFCOUNT
20035+ "jno 0f\n"
20036+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
20037+ "int $4\n0:\n"
20038+ _ASM_EXTABLE(0b, 0b)
20039+#endif
20040+
20041 "jz 1f\n"
20042 "call __write_lock_failed\n\t"
20043 "1:\n"
20044@@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
20045
20046 static inline void arch_read_unlock(arch_rwlock_t *rw)
20047 {
20048- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
20049+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
20050+
20051+#ifdef CONFIG_PAX_REFCOUNT
20052+ "jno 0f\n"
20053+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
20054+ "int $4\n0:\n"
20055+ _ASM_EXTABLE(0b, 0b)
20056+#endif
20057+
20058 :"+m" (rw->lock) : : "memory");
20059 }
20060
20061 static inline void arch_write_unlock(arch_rwlock_t *rw)
20062 {
20063- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
20064+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
20065+
20066+#ifdef CONFIG_PAX_REFCOUNT
20067+ "jno 0f\n"
20068+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
20069+ "int $4\n0:\n"
20070+ _ASM_EXTABLE(0b, 0b)
20071+#endif
20072+
20073 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
20074 }
20075 #else
20076diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
20077index 6a99859..03cb807 100644
20078--- a/arch/x86/include/asm/stackprotector.h
20079+++ b/arch/x86/include/asm/stackprotector.h
20080@@ -47,7 +47,7 @@
20081 * head_32 for boot CPU and setup_per_cpu_areas() for others.
20082 */
20083 #define GDT_STACK_CANARY_INIT \
20084- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
20085+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
20086
20087 /*
20088 * Initialize the stackprotector canary value.
20089@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
20090
20091 static inline void load_stack_canary_segment(void)
20092 {
20093-#ifdef CONFIG_X86_32
20094+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
20095 asm volatile ("mov %0, %%gs" : : "r" (0));
20096 #endif
20097 }
20098diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
20099index 70bbe39..4ae2bd4 100644
20100--- a/arch/x86/include/asm/stacktrace.h
20101+++ b/arch/x86/include/asm/stacktrace.h
20102@@ -11,28 +11,20 @@
20103
20104 extern int kstack_depth_to_print;
20105
20106-struct thread_info;
20107+struct task_struct;
20108 struct stacktrace_ops;
20109
20110-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
20111- unsigned long *stack,
20112- unsigned long bp,
20113- const struct stacktrace_ops *ops,
20114- void *data,
20115- unsigned long *end,
20116- int *graph);
20117+typedef unsigned long walk_stack_t(struct task_struct *task,
20118+ void *stack_start,
20119+ unsigned long *stack,
20120+ unsigned long bp,
20121+ const struct stacktrace_ops *ops,
20122+ void *data,
20123+ unsigned long *end,
20124+ int *graph);
20125
20126-extern unsigned long
20127-print_context_stack(struct thread_info *tinfo,
20128- unsigned long *stack, unsigned long bp,
20129- const struct stacktrace_ops *ops, void *data,
20130- unsigned long *end, int *graph);
20131-
20132-extern unsigned long
20133-print_context_stack_bp(struct thread_info *tinfo,
20134- unsigned long *stack, unsigned long bp,
20135- const struct stacktrace_ops *ops, void *data,
20136- unsigned long *end, int *graph);
20137+extern walk_stack_t print_context_stack;
20138+extern walk_stack_t print_context_stack_bp;
20139
20140 /* Generic stack tracer with callbacks */
20141
20142@@ -40,7 +32,7 @@ struct stacktrace_ops {
20143 void (*address)(void *data, unsigned long address, int reliable);
20144 /* On negative return stop dumping */
20145 int (*stack)(void *data, char *name);
20146- walk_stack_t walk_stack;
20147+ walk_stack_t *walk_stack;
20148 };
20149
20150 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
20151diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
20152index d7f3b3b..3cc39f1 100644
20153--- a/arch/x86/include/asm/switch_to.h
20154+++ b/arch/x86/include/asm/switch_to.h
20155@@ -108,7 +108,7 @@ do { \
20156 "call __switch_to\n\t" \
20157 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
20158 __switch_canary \
20159- "movq %P[thread_info](%%rsi),%%r8\n\t" \
20160+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
20161 "movq %%rax,%%rdi\n\t" \
20162 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
20163 "jnz ret_from_fork\n\t" \
20164@@ -119,7 +119,7 @@ do { \
20165 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
20166 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
20167 [_tif_fork] "i" (_TIF_FORK), \
20168- [thread_info] "i" (offsetof(struct task_struct, stack)), \
20169+ [thread_info] "m" (current_tinfo), \
20170 [current_task] "m" (current_task) \
20171 __switch_canary_iparam \
20172 : "memory", "cc" __EXTRA_CLOBBER)
20173diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
20174index 547e344..6be1175 100644
20175--- a/arch/x86/include/asm/thread_info.h
20176+++ b/arch/x86/include/asm/thread_info.h
20177@@ -24,7 +24,6 @@ struct exec_domain;
20178 #include <linux/atomic.h>
20179
20180 struct thread_info {
20181- struct task_struct *task; /* main task structure */
20182 struct exec_domain *exec_domain; /* execution domain */
20183 __u32 flags; /* low level flags */
20184 __u32 status; /* thread synchronous flags */
20185@@ -33,13 +32,13 @@ struct thread_info {
20186 mm_segment_t addr_limit;
20187 struct restart_block restart_block;
20188 void __user *sysenter_return;
20189+ unsigned long lowest_stack;
20190 unsigned int sig_on_uaccess_error:1;
20191 unsigned int uaccess_err:1; /* uaccess failed */
20192 };
20193
20194-#define INIT_THREAD_INFO(tsk) \
20195+#define INIT_THREAD_INFO \
20196 { \
20197- .task = &tsk, \
20198 .exec_domain = &default_exec_domain, \
20199 .flags = 0, \
20200 .cpu = 0, \
20201@@ -50,7 +49,7 @@ struct thread_info {
20202 }, \
20203 }
20204
20205-#define init_thread_info (init_thread_union.thread_info)
20206+#define init_thread_info (init_thread_union.stack)
20207 #define init_stack (init_thread_union.stack)
20208
20209 #else /* !__ASSEMBLY__ */
20210@@ -91,6 +90,7 @@ struct thread_info {
20211 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
20212 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
20213 #define TIF_X32 30 /* 32-bit native x86-64 binary */
20214+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
20215
20216 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
20217 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
20218@@ -115,17 +115,18 @@ struct thread_info {
20219 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
20220 #define _TIF_ADDR32 (1 << TIF_ADDR32)
20221 #define _TIF_X32 (1 << TIF_X32)
20222+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
20223
20224 /* work to do in syscall_trace_enter() */
20225 #define _TIF_WORK_SYSCALL_ENTRY \
20226 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
20227 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
20228- _TIF_NOHZ)
20229+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
20230
20231 /* work to do in syscall_trace_leave() */
20232 #define _TIF_WORK_SYSCALL_EXIT \
20233 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
20234- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
20235+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
20236
20237 /* work to do on interrupt/exception return */
20238 #define _TIF_WORK_MASK \
20239@@ -136,7 +137,7 @@ struct thread_info {
20240 /* work to do on any return to user space */
20241 #define _TIF_ALLWORK_MASK \
20242 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
20243- _TIF_NOHZ)
20244+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
20245
20246 /* Only used for 64 bit */
20247 #define _TIF_DO_NOTIFY_MASK \
20248@@ -151,7 +152,6 @@ struct thread_info {
20249 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
20250
20251 #define STACK_WARN (THREAD_SIZE/8)
20252-#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
20253
20254 /*
20255 * macros/functions for gaining access to the thread information structure
20256@@ -162,26 +162,18 @@ struct thread_info {
20257
20258 DECLARE_PER_CPU(unsigned long, kernel_stack);
20259
20260+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
20261+
20262 static inline struct thread_info *current_thread_info(void)
20263 {
20264- struct thread_info *ti;
20265- ti = (void *)(this_cpu_read_stable(kernel_stack) +
20266- KERNEL_STACK_OFFSET - THREAD_SIZE);
20267- return ti;
20268+ return this_cpu_read_stable(current_tinfo);
20269 }
20270
20271 #else /* !__ASSEMBLY__ */
20272
20273 /* how to get the thread information struct from ASM */
20274 #define GET_THREAD_INFO(reg) \
20275- _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
20276- _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
20277-
20278-/*
20279- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
20280- * a certain register (to be used in assembler memory operands).
20281- */
20282-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
20283+ _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
20284
20285 #endif
20286
20287@@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
20288 extern void arch_task_cache_init(void);
20289 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
20290 extern void arch_release_task_struct(struct task_struct *tsk);
20291+
20292+#define __HAVE_THREAD_FUNCTIONS
20293+#define task_thread_info(task) (&(task)->tinfo)
20294+#define task_stack_page(task) ((task)->stack)
20295+#define setup_thread_stack(p, org) do {} while (0)
20296+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
20297+
20298 #endif
20299 #endif /* _ASM_X86_THREAD_INFO_H */
20300diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
20301index 04905bf..1178cdf 100644
20302--- a/arch/x86/include/asm/tlbflush.h
20303+++ b/arch/x86/include/asm/tlbflush.h
20304@@ -17,18 +17,44 @@
20305
20306 static inline void __native_flush_tlb(void)
20307 {
20308+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
20309+ u64 descriptor[2];
20310+
20311+ descriptor[0] = PCID_KERNEL;
20312+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_NONGLOBAL) : "memory");
20313+ return;
20314+ }
20315+
20316+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20317+ if (static_cpu_has(X86_FEATURE_PCID)) {
20318+ unsigned int cpu = raw_get_cpu();
20319+
20320+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
20321+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
20322+ raw_put_cpu_no_resched();
20323+ return;
20324+ }
20325+#endif
20326+
20327 native_write_cr3(native_read_cr3());
20328 }
20329
20330 static inline void __native_flush_tlb_global_irq_disabled(void)
20331 {
20332- unsigned long cr4;
20333+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
20334+ u64 descriptor[2];
20335
20336- cr4 = native_read_cr4();
20337- /* clear PGE */
20338- native_write_cr4(cr4 & ~X86_CR4_PGE);
20339- /* write old PGE again and flush TLBs */
20340- native_write_cr4(cr4);
20341+ descriptor[0] = PCID_KERNEL;
20342+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
20343+ } else {
20344+ unsigned long cr4;
20345+
20346+ cr4 = native_read_cr4();
20347+ /* clear PGE */
20348+ native_write_cr4(cr4 & ~X86_CR4_PGE);
20349+ /* write old PGE again and flush TLBs */
20350+ native_write_cr4(cr4);
20351+ }
20352 }
20353
20354 static inline void __native_flush_tlb_global(void)
20355@@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
20356
20357 static inline void __native_flush_tlb_single(unsigned long addr)
20358 {
20359+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
20360+ u64 descriptor[2];
20361+
20362+ descriptor[0] = PCID_KERNEL;
20363+ descriptor[1] = addr;
20364+
20365+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20366+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
20367+ if (addr < TASK_SIZE_MAX)
20368+ descriptor[1] += pax_user_shadow_base;
20369+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
20370+ }
20371+
20372+ descriptor[0] = PCID_USER;
20373+ descriptor[1] = addr;
20374+#endif
20375+
20376+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
20377+ return;
20378+ }
20379+
20380+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20381+ if (static_cpu_has(X86_FEATURE_PCID)) {
20382+ unsigned int cpu = raw_get_cpu();
20383+
20384+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
20385+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
20386+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
20387+ raw_put_cpu_no_resched();
20388+
20389+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
20390+ addr += pax_user_shadow_base;
20391+ }
20392+#endif
20393+
20394 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
20395 }
20396
20397diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
20398index 0d592e0..526f797 100644
20399--- a/arch/x86/include/asm/uaccess.h
20400+++ b/arch/x86/include/asm/uaccess.h
20401@@ -7,6 +7,7 @@
20402 #include <linux/compiler.h>
20403 #include <linux/thread_info.h>
20404 #include <linux/string.h>
20405+#include <linux/spinlock.h>
20406 #include <asm/asm.h>
20407 #include <asm/page.h>
20408 #include <asm/smap.h>
20409@@ -29,7 +30,12 @@
20410
20411 #define get_ds() (KERNEL_DS)
20412 #define get_fs() (current_thread_info()->addr_limit)
20413+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20414+void __set_fs(mm_segment_t x);
20415+void set_fs(mm_segment_t x);
20416+#else
20417 #define set_fs(x) (current_thread_info()->addr_limit = (x))
20418+#endif
20419
20420 #define segment_eq(a, b) ((a).seg == (b).seg)
20421
20422@@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
20423 * checks that the pointer is in the user space range - after calling
20424 * this function, memory access functions may still return -EFAULT.
20425 */
20426-#define access_ok(type, addr, size) \
20427- likely(!__range_not_ok(addr, size, user_addr_max()))
20428+extern int _cond_resched(void);
20429+#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
20430+#define access_ok(type, addr, size) \
20431+({ \
20432+ unsigned long __size = size; \
20433+ unsigned long __addr = (unsigned long)addr; \
20434+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
20435+ if (__ret_ao && __size) { \
20436+ unsigned long __addr_ao = __addr & PAGE_MASK; \
20437+ unsigned long __end_ao = __addr + __size - 1; \
20438+ if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
20439+ while (__addr_ao <= __end_ao) { \
20440+ char __c_ao; \
20441+ __addr_ao += PAGE_SIZE; \
20442+ if (__size > PAGE_SIZE) \
20443+ _cond_resched(); \
20444+ if (__get_user(__c_ao, (char __user *)__addr)) \
20445+ break; \
20446+ if (type != VERIFY_WRITE) { \
20447+ __addr = __addr_ao; \
20448+ continue; \
20449+ } \
20450+ if (__put_user(__c_ao, (char __user *)__addr)) \
20451+ break; \
20452+ __addr = __addr_ao; \
20453+ } \
20454+ } \
20455+ } \
20456+ __ret_ao; \
20457+})
20458
20459 /*
20460 * The exception table consists of pairs of addresses relative to the
20461@@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
20462 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
20463 __chk_user_ptr(ptr); \
20464 might_fault(); \
20465+ pax_open_userland(); \
20466 asm volatile("call __get_user_%P3" \
20467 : "=a" (__ret_gu), "=r" (__val_gu) \
20468 : "0" (ptr), "i" (sizeof(*(ptr)))); \
20469 (x) = (__typeof__(*(ptr))) __val_gu; \
20470+ pax_close_userland(); \
20471 __ret_gu; \
20472 })
20473
20474@@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
20475 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
20476 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
20477
20478-
20479+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20480+#define __copyuser_seg "gs;"
20481+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
20482+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
20483+#else
20484+#define __copyuser_seg
20485+#define __COPYUSER_SET_ES
20486+#define __COPYUSER_RESTORE_ES
20487+#endif
20488
20489 #ifdef CONFIG_X86_32
20490 #define __put_user_asm_u64(x, addr, err, errret) \
20491 asm volatile(ASM_STAC "\n" \
20492- "1: movl %%eax,0(%2)\n" \
20493- "2: movl %%edx,4(%2)\n" \
20494+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
20495+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
20496 "3: " ASM_CLAC "\n" \
20497 ".section .fixup,\"ax\"\n" \
20498 "4: movl %3,%0\n" \
20499@@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
20500
20501 #define __put_user_asm_ex_u64(x, addr) \
20502 asm volatile(ASM_STAC "\n" \
20503- "1: movl %%eax,0(%1)\n" \
20504- "2: movl %%edx,4(%1)\n" \
20505+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
20506+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
20507 "3: " ASM_CLAC "\n" \
20508 _ASM_EXTABLE_EX(1b, 2b) \
20509 _ASM_EXTABLE_EX(2b, 3b) \
20510@@ -257,7 +301,8 @@ extern void __put_user_8(void);
20511 __typeof__(*(ptr)) __pu_val; \
20512 __chk_user_ptr(ptr); \
20513 might_fault(); \
20514- __pu_val = x; \
20515+ __pu_val = (x); \
20516+ pax_open_userland(); \
20517 switch (sizeof(*(ptr))) { \
20518 case 1: \
20519 __put_user_x(1, __pu_val, ptr, __ret_pu); \
20520@@ -275,6 +320,7 @@ extern void __put_user_8(void);
20521 __put_user_x(X, __pu_val, ptr, __ret_pu); \
20522 break; \
20523 } \
20524+ pax_close_userland(); \
20525 __ret_pu; \
20526 })
20527
20528@@ -355,8 +401,10 @@ do { \
20529 } while (0)
20530
20531 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
20532+do { \
20533+ pax_open_userland(); \
20534 asm volatile(ASM_STAC "\n" \
20535- "1: mov"itype" %2,%"rtype"1\n" \
20536+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
20537 "2: " ASM_CLAC "\n" \
20538 ".section .fixup,\"ax\"\n" \
20539 "3: mov %3,%0\n" \
20540@@ -364,8 +412,10 @@ do { \
20541 " jmp 2b\n" \
20542 ".previous\n" \
20543 _ASM_EXTABLE(1b, 3b) \
20544- : "=r" (err), ltype(x) \
20545- : "m" (__m(addr)), "i" (errret), "0" (err))
20546+ : "=r" (err), ltype (x) \
20547+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
20548+ pax_close_userland(); \
20549+} while (0)
20550
20551 #define __get_user_size_ex(x, ptr, size) \
20552 do { \
20553@@ -389,7 +439,7 @@ do { \
20554 } while (0)
20555
20556 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
20557- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
20558+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
20559 "2:\n" \
20560 _ASM_EXTABLE_EX(1b, 2b) \
20561 : ltype(x) : "m" (__m(addr)))
20562@@ -406,13 +456,24 @@ do { \
20563 int __gu_err; \
20564 unsigned long __gu_val; \
20565 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
20566- (x) = (__force __typeof__(*(ptr)))__gu_val; \
20567+ (x) = (__typeof__(*(ptr)))__gu_val; \
20568 __gu_err; \
20569 })
20570
20571 /* FIXME: this hack is definitely wrong -AK */
20572 struct __large_struct { unsigned long buf[100]; };
20573-#define __m(x) (*(struct __large_struct __user *)(x))
20574+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20575+#define ____m(x) \
20576+({ \
20577+ unsigned long ____x = (unsigned long)(x); \
20578+ if (____x < pax_user_shadow_base) \
20579+ ____x += pax_user_shadow_base; \
20580+ (typeof(x))____x; \
20581+})
20582+#else
20583+#define ____m(x) (x)
20584+#endif
20585+#define __m(x) (*(struct __large_struct __user *)____m(x))
20586
20587 /*
20588 * Tell gcc we read from memory instead of writing: this is because
20589@@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
20590 * aliasing issues.
20591 */
20592 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
20593+do { \
20594+ pax_open_userland(); \
20595 asm volatile(ASM_STAC "\n" \
20596- "1: mov"itype" %"rtype"1,%2\n" \
20597+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
20598 "2: " ASM_CLAC "\n" \
20599 ".section .fixup,\"ax\"\n" \
20600 "3: mov %3,%0\n" \
20601@@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
20602 ".previous\n" \
20603 _ASM_EXTABLE(1b, 3b) \
20604 : "=r"(err) \
20605- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
20606+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
20607+ pax_close_userland(); \
20608+} while (0)
20609
20610 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
20611- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
20612+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
20613 "2:\n" \
20614 _ASM_EXTABLE_EX(1b, 2b) \
20615 : : ltype(x), "m" (__m(addr)))
20616@@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
20617 */
20618 #define uaccess_try do { \
20619 current_thread_info()->uaccess_err = 0; \
20620+ pax_open_userland(); \
20621 stac(); \
20622 barrier();
20623
20624 #define uaccess_catch(err) \
20625 clac(); \
20626+ pax_close_userland(); \
20627 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
20628 } while (0)
20629
20630@@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
20631 * On error, the variable @x is set to zero.
20632 */
20633
20634+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20635+#define __get_user(x, ptr) get_user((x), (ptr))
20636+#else
20637 #define __get_user(x, ptr) \
20638 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
20639+#endif
20640
20641 /**
20642 * __put_user: - Write a simple value into user space, with less checking.
20643@@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
20644 * Returns zero on success, or -EFAULT on error.
20645 */
20646
20647+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20648+#define __put_user(x, ptr) put_user((x), (ptr))
20649+#else
20650 #define __put_user(x, ptr) \
20651 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
20652+#endif
20653
20654 #define __get_user_unaligned __get_user
20655 #define __put_user_unaligned __put_user
20656@@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
20657 #define get_user_ex(x, ptr) do { \
20658 unsigned long __gue_val; \
20659 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
20660- (x) = (__force __typeof__(*(ptr)))__gue_val; \
20661+ (x) = (__typeof__(*(ptr)))__gue_val; \
20662 } while (0)
20663
20664 #define put_user_try uaccess_try
20665@@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
20666 __typeof__(ptr) __uval = (uval); \
20667 __typeof__(*(ptr)) __old = (old); \
20668 __typeof__(*(ptr)) __new = (new); \
20669+ pax_open_userland(); \
20670 switch (size) { \
20671 case 1: \
20672 { \
20673 asm volatile("\t" ASM_STAC "\n" \
20674- "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
20675+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
20676 "2:\t" ASM_CLAC "\n" \
20677 "\t.section .fixup, \"ax\"\n" \
20678 "3:\tmov %3, %0\n" \
20679 "\tjmp 2b\n" \
20680 "\t.previous\n" \
20681 _ASM_EXTABLE(1b, 3b) \
20682- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20683+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20684 : "i" (-EFAULT), "q" (__new), "1" (__old) \
20685 : "memory" \
20686 ); \
20687@@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
20688 case 2: \
20689 { \
20690 asm volatile("\t" ASM_STAC "\n" \
20691- "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
20692+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
20693 "2:\t" ASM_CLAC "\n" \
20694 "\t.section .fixup, \"ax\"\n" \
20695 "3:\tmov %3, %0\n" \
20696 "\tjmp 2b\n" \
20697 "\t.previous\n" \
20698 _ASM_EXTABLE(1b, 3b) \
20699- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20700+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20701 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20702 : "memory" \
20703 ); \
20704@@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
20705 case 4: \
20706 { \
20707 asm volatile("\t" ASM_STAC "\n" \
20708- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
20709+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
20710 "2:\t" ASM_CLAC "\n" \
20711 "\t.section .fixup, \"ax\"\n" \
20712 "3:\tmov %3, %0\n" \
20713 "\tjmp 2b\n" \
20714 "\t.previous\n" \
20715 _ASM_EXTABLE(1b, 3b) \
20716- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20717+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20718 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20719 : "memory" \
20720 ); \
20721@@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
20722 __cmpxchg_wrong_size(); \
20723 \
20724 asm volatile("\t" ASM_STAC "\n" \
20725- "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
20726+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
20727 "2:\t" ASM_CLAC "\n" \
20728 "\t.section .fixup, \"ax\"\n" \
20729 "3:\tmov %3, %0\n" \
20730 "\tjmp 2b\n" \
20731 "\t.previous\n" \
20732 _ASM_EXTABLE(1b, 3b) \
20733- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20734+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20735 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20736 : "memory" \
20737 ); \
20738@@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
20739 default: \
20740 __cmpxchg_wrong_size(); \
20741 } \
20742+ pax_close_userland(); \
20743 *__uval = __old; \
20744 __ret; \
20745 })
20746@@ -636,17 +713,6 @@ extern struct movsl_mask {
20747
20748 #define ARCH_HAS_NOCACHE_UACCESS 1
20749
20750-#ifdef CONFIG_X86_32
20751-# include <asm/uaccess_32.h>
20752-#else
20753-# include <asm/uaccess_64.h>
20754-#endif
20755-
20756-unsigned long __must_check _copy_from_user(void *to, const void __user *from,
20757- unsigned n);
20758-unsigned long __must_check _copy_to_user(void __user *to, const void *from,
20759- unsigned n);
20760-
20761 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
20762 # define copy_user_diag __compiletime_error
20763 #else
20764@@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
20765 extern void copy_user_diag("copy_from_user() buffer size is too small")
20766 copy_from_user_overflow(void);
20767 extern void copy_user_diag("copy_to_user() buffer size is too small")
20768-copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
20769+copy_to_user_overflow(void);
20770
20771 #undef copy_user_diag
20772
20773@@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
20774
20775 extern void
20776 __compiletime_warning("copy_to_user() buffer size is not provably correct")
20777-__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
20778+__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
20779 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
20780
20781 #else
20782@@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
20783
20784 #endif
20785
20786+#ifdef CONFIG_X86_32
20787+# include <asm/uaccess_32.h>
20788+#else
20789+# include <asm/uaccess_64.h>
20790+#endif
20791+
20792 static inline unsigned long __must_check
20793 copy_from_user(void *to, const void __user *from, unsigned long n)
20794 {
20795- int sz = __compiletime_object_size(to);
20796+ size_t sz = __compiletime_object_size(to);
20797
20798 might_fault();
20799
20800@@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20801 * case, and do only runtime checking for non-constant sizes.
20802 */
20803
20804- if (likely(sz < 0 || sz >= n))
20805- n = _copy_from_user(to, from, n);
20806- else if(__builtin_constant_p(n))
20807- copy_from_user_overflow();
20808- else
20809- __copy_from_user_overflow(sz, n);
20810+ if (likely(sz != (size_t)-1 && sz < n)) {
20811+ if(__builtin_constant_p(n))
20812+ copy_from_user_overflow();
20813+ else
20814+ __copy_from_user_overflow(sz, n);
20815+ } else if (access_ok(VERIFY_READ, from, n))
20816+ n = __copy_from_user(to, from, n);
20817+ else if ((long)n > 0)
20818+ memset(to, 0, n);
20819
20820 return n;
20821 }
20822@@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20823 static inline unsigned long __must_check
20824 copy_to_user(void __user *to, const void *from, unsigned long n)
20825 {
20826- int sz = __compiletime_object_size(from);
20827+ size_t sz = __compiletime_object_size(from);
20828
20829 might_fault();
20830
20831 /* See the comment in copy_from_user() above. */
20832- if (likely(sz < 0 || sz >= n))
20833- n = _copy_to_user(to, from, n);
20834- else if(__builtin_constant_p(n))
20835- copy_to_user_overflow();
20836- else
20837- __copy_to_user_overflow(sz, n);
20838+ if (likely(sz != (size_t)-1 && sz < n)) {
20839+ if(__builtin_constant_p(n))
20840+ copy_to_user_overflow();
20841+ else
20842+ __copy_to_user_overflow(sz, n);
20843+ } else if (access_ok(VERIFY_WRITE, to, n))
20844+ n = __copy_to_user(to, from, n);
20845
20846 return n;
20847 }
20848diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
20849index 3c03a5d..1071638 100644
20850--- a/arch/x86/include/asm/uaccess_32.h
20851+++ b/arch/x86/include/asm/uaccess_32.h
20852@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20853 static __always_inline unsigned long __must_check
20854 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20855 {
20856+ if ((long)n < 0)
20857+ return n;
20858+
20859+ check_object_size(from, n, true);
20860+
20861 if (__builtin_constant_p(n)) {
20862 unsigned long ret;
20863
20864@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20865 __copy_to_user(void __user *to, const void *from, unsigned long n)
20866 {
20867 might_fault();
20868+
20869 return __copy_to_user_inatomic(to, from, n);
20870 }
20871
20872 static __always_inline unsigned long
20873 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20874 {
20875+ if ((long)n < 0)
20876+ return n;
20877+
20878 /* Avoid zeroing the tail if the copy fails..
20879 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20880 * but as the zeroing behaviour is only significant when n is not
20881@@ -137,6 +146,12 @@ static __always_inline unsigned long
20882 __copy_from_user(void *to, const void __user *from, unsigned long n)
20883 {
20884 might_fault();
20885+
20886+ if ((long)n < 0)
20887+ return n;
20888+
20889+ check_object_size(to, n, false);
20890+
20891 if (__builtin_constant_p(n)) {
20892 unsigned long ret;
20893
20894@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20895 const void __user *from, unsigned long n)
20896 {
20897 might_fault();
20898+
20899+ if ((long)n < 0)
20900+ return n;
20901+
20902 if (__builtin_constant_p(n)) {
20903 unsigned long ret;
20904
20905@@ -181,7 +200,10 @@ static __always_inline unsigned long
20906 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20907 unsigned long n)
20908 {
20909- return __copy_from_user_ll_nocache_nozero(to, from, n);
20910+ if ((long)n < 0)
20911+ return n;
20912+
20913+ return __copy_from_user_ll_nocache_nozero(to, from, n);
20914 }
20915
20916 #endif /* _ASM_X86_UACCESS_32_H */
20917diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20918index 12a26b9..206c200 100644
20919--- a/arch/x86/include/asm/uaccess_64.h
20920+++ b/arch/x86/include/asm/uaccess_64.h
20921@@ -10,6 +10,9 @@
20922 #include <asm/alternative.h>
20923 #include <asm/cpufeature.h>
20924 #include <asm/page.h>
20925+#include <asm/pgtable.h>
20926+
20927+#define set_fs(x) (current_thread_info()->addr_limit = (x))
20928
20929 /*
20930 * Copy To/From Userspace
20931@@ -17,14 +20,14 @@
20932
20933 /* Handles exceptions in both to and from, but doesn't do access_ok */
20934 __must_check unsigned long
20935-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20936+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20937 __must_check unsigned long
20938-copy_user_generic_string(void *to, const void *from, unsigned len);
20939+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20940 __must_check unsigned long
20941-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20942+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20943
20944 static __always_inline __must_check unsigned long
20945-copy_user_generic(void *to, const void *from, unsigned len)
20946+copy_user_generic(void *to, const void *from, unsigned long len)
20947 {
20948 unsigned ret;
20949
20950@@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20951 }
20952
20953 __must_check unsigned long
20954-copy_in_user(void __user *to, const void __user *from, unsigned len);
20955+copy_in_user(void __user *to, const void __user *from, unsigned long len);
20956
20957 static __always_inline __must_check
20958-int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20959+unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20960 {
20961- int ret = 0;
20962+ size_t sz = __compiletime_object_size(dst);
20963+ unsigned ret = 0;
20964+
20965+ if (size > INT_MAX)
20966+ return size;
20967+
20968+ check_object_size(dst, size, false);
20969+
20970+#ifdef CONFIG_PAX_MEMORY_UDEREF
20971+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20972+ return size;
20973+#endif
20974+
20975+ if (unlikely(sz != (size_t)-1 && sz < size)) {
20976+ if(__builtin_constant_p(size))
20977+ copy_from_user_overflow();
20978+ else
20979+ __copy_from_user_overflow(sz, size);
20980+ return size;
20981+ }
20982
20983 if (!__builtin_constant_p(size))
20984- return copy_user_generic(dst, (__force void *)src, size);
20985+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20986 switch (size) {
20987- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20988+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20989 ret, "b", "b", "=q", 1);
20990 return ret;
20991- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20992+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20993 ret, "w", "w", "=r", 2);
20994 return ret;
20995- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20996+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20997 ret, "l", "k", "=r", 4);
20998 return ret;
20999- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
21000+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
21001 ret, "q", "", "=r", 8);
21002 return ret;
21003 case 10:
21004- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
21005+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
21006 ret, "q", "", "=r", 10);
21007 if (unlikely(ret))
21008 return ret;
21009 __get_user_asm(*(u16 *)(8 + (char *)dst),
21010- (u16 __user *)(8 + (char __user *)src),
21011+ (const u16 __user *)(8 + (const char __user *)src),
21012 ret, "w", "w", "=r", 2);
21013 return ret;
21014 case 16:
21015- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
21016+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
21017 ret, "q", "", "=r", 16);
21018 if (unlikely(ret))
21019 return ret;
21020 __get_user_asm(*(u64 *)(8 + (char *)dst),
21021- (u64 __user *)(8 + (char __user *)src),
21022+ (const u64 __user *)(8 + (const char __user *)src),
21023 ret, "q", "", "=r", 8);
21024 return ret;
21025 default:
21026- return copy_user_generic(dst, (__force void *)src, size);
21027+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
21028 }
21029 }
21030
21031 static __always_inline __must_check
21032-int __copy_from_user(void *dst, const void __user *src, unsigned size)
21033+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
21034 {
21035 might_fault();
21036 return __copy_from_user_nocheck(dst, src, size);
21037 }
21038
21039 static __always_inline __must_check
21040-int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
21041+unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
21042 {
21043- int ret = 0;
21044+ size_t sz = __compiletime_object_size(src);
21045+ unsigned ret = 0;
21046+
21047+ if (size > INT_MAX)
21048+ return size;
21049+
21050+ check_object_size(src, size, true);
21051+
21052+#ifdef CONFIG_PAX_MEMORY_UDEREF
21053+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
21054+ return size;
21055+#endif
21056+
21057+ if (unlikely(sz != (size_t)-1 && sz < size)) {
21058+ if(__builtin_constant_p(size))
21059+ copy_to_user_overflow();
21060+ else
21061+ __copy_to_user_overflow(sz, size);
21062+ return size;
21063+ }
21064
21065 if (!__builtin_constant_p(size))
21066- return copy_user_generic((__force void *)dst, src, size);
21067+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
21068 switch (size) {
21069- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
21070+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
21071 ret, "b", "b", "iq", 1);
21072 return ret;
21073- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
21074+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
21075 ret, "w", "w", "ir", 2);
21076 return ret;
21077- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
21078+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
21079 ret, "l", "k", "ir", 4);
21080 return ret;
21081- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
21082+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
21083 ret, "q", "", "er", 8);
21084 return ret;
21085 case 10:
21086- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
21087+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
21088 ret, "q", "", "er", 10);
21089 if (unlikely(ret))
21090 return ret;
21091 asm("":::"memory");
21092- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
21093+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
21094 ret, "w", "w", "ir", 2);
21095 return ret;
21096 case 16:
21097- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
21098+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
21099 ret, "q", "", "er", 16);
21100 if (unlikely(ret))
21101 return ret;
21102 asm("":::"memory");
21103- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
21104+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
21105 ret, "q", "", "er", 8);
21106 return ret;
21107 default:
21108- return copy_user_generic((__force void *)dst, src, size);
21109+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
21110 }
21111 }
21112
21113 static __always_inline __must_check
21114-int __copy_to_user(void __user *dst, const void *src, unsigned size)
21115+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
21116 {
21117 might_fault();
21118 return __copy_to_user_nocheck(dst, src, size);
21119 }
21120
21121 static __always_inline __must_check
21122-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21123+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21124 {
21125- int ret = 0;
21126+ unsigned ret = 0;
21127
21128 might_fault();
21129+
21130+ if (size > INT_MAX)
21131+ return size;
21132+
21133+#ifdef CONFIG_PAX_MEMORY_UDEREF
21134+ if (!access_ok_noprefault(VERIFY_READ, src, size))
21135+ return size;
21136+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
21137+ return size;
21138+#endif
21139+
21140 if (!__builtin_constant_p(size))
21141- return copy_user_generic((__force void *)dst,
21142- (__force void *)src, size);
21143+ return copy_user_generic((__force_kernel void *)____m(dst),
21144+ (__force_kernel const void *)____m(src), size);
21145 switch (size) {
21146 case 1: {
21147 u8 tmp;
21148- __get_user_asm(tmp, (u8 __user *)src,
21149+ __get_user_asm(tmp, (const u8 __user *)src,
21150 ret, "b", "b", "=q", 1);
21151 if (likely(!ret))
21152 __put_user_asm(tmp, (u8 __user *)dst,
21153@@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21154 }
21155 case 2: {
21156 u16 tmp;
21157- __get_user_asm(tmp, (u16 __user *)src,
21158+ __get_user_asm(tmp, (const u16 __user *)src,
21159 ret, "w", "w", "=r", 2);
21160 if (likely(!ret))
21161 __put_user_asm(tmp, (u16 __user *)dst,
21162@@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21163
21164 case 4: {
21165 u32 tmp;
21166- __get_user_asm(tmp, (u32 __user *)src,
21167+ __get_user_asm(tmp, (const u32 __user *)src,
21168 ret, "l", "k", "=r", 4);
21169 if (likely(!ret))
21170 __put_user_asm(tmp, (u32 __user *)dst,
21171@@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21172 }
21173 case 8: {
21174 u64 tmp;
21175- __get_user_asm(tmp, (u64 __user *)src,
21176+ __get_user_asm(tmp, (const u64 __user *)src,
21177 ret, "q", "", "=r", 8);
21178 if (likely(!ret))
21179 __put_user_asm(tmp, (u64 __user *)dst,
21180@@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21181 return ret;
21182 }
21183 default:
21184- return copy_user_generic((__force void *)dst,
21185- (__force void *)src, size);
21186+ return copy_user_generic((__force_kernel void *)____m(dst),
21187+ (__force_kernel const void *)____m(src), size);
21188 }
21189 }
21190
21191-static __must_check __always_inline int
21192-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
21193+static __must_check __always_inline unsigned long
21194+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
21195 {
21196 return __copy_from_user_nocheck(dst, src, size);
21197 }
21198
21199-static __must_check __always_inline int
21200-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
21201+static __must_check __always_inline unsigned long
21202+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
21203 {
21204 return __copy_to_user_nocheck(dst, src, size);
21205 }
21206
21207-extern long __copy_user_nocache(void *dst, const void __user *src,
21208- unsigned size, int zerorest);
21209+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
21210+ unsigned long size, int zerorest);
21211
21212-static inline int
21213-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
21214+static inline unsigned long
21215+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
21216 {
21217 might_fault();
21218+
21219+ if (size > INT_MAX)
21220+ return size;
21221+
21222+#ifdef CONFIG_PAX_MEMORY_UDEREF
21223+ if (!access_ok_noprefault(VERIFY_READ, src, size))
21224+ return size;
21225+#endif
21226+
21227 return __copy_user_nocache(dst, src, size, 1);
21228 }
21229
21230-static inline int
21231+static inline unsigned long
21232 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
21233- unsigned size)
21234+ unsigned long size)
21235 {
21236+ if (size > INT_MAX)
21237+ return size;
21238+
21239+#ifdef CONFIG_PAX_MEMORY_UDEREF
21240+ if (!access_ok_noprefault(VERIFY_READ, src, size))
21241+ return size;
21242+#endif
21243+
21244 return __copy_user_nocache(dst, src, size, 0);
21245 }
21246
21247 unsigned long
21248-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
21249+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
21250
21251 #endif /* _ASM_X86_UACCESS_64_H */
21252diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
21253index 5b238981..77fdd78 100644
21254--- a/arch/x86/include/asm/word-at-a-time.h
21255+++ b/arch/x86/include/asm/word-at-a-time.h
21256@@ -11,7 +11,7 @@
21257 * and shift, for example.
21258 */
21259 struct word_at_a_time {
21260- const unsigned long one_bits, high_bits;
21261+ unsigned long one_bits, high_bits;
21262 };
21263
21264 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
21265diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
21266index e45e4da..44e8572 100644
21267--- a/arch/x86/include/asm/x86_init.h
21268+++ b/arch/x86/include/asm/x86_init.h
21269@@ -129,7 +129,7 @@ struct x86_init_ops {
21270 struct x86_init_timers timers;
21271 struct x86_init_iommu iommu;
21272 struct x86_init_pci pci;
21273-};
21274+} __no_const;
21275
21276 /**
21277 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
21278@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
21279 void (*setup_percpu_clockev)(void);
21280 void (*early_percpu_clock_init)(void);
21281 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
21282-};
21283+} __no_const;
21284
21285 struct timespec;
21286
21287@@ -168,7 +168,7 @@ struct x86_platform_ops {
21288 void (*save_sched_clock_state)(void);
21289 void (*restore_sched_clock_state)(void);
21290 void (*apic_post_init)(void);
21291-};
21292+} __no_const;
21293
21294 struct pci_dev;
21295 struct msi_msg;
21296@@ -185,7 +185,7 @@ struct x86_msi_ops {
21297 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
21298 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
21299 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
21300-};
21301+} __no_const;
21302
21303 struct IO_APIC_route_entry;
21304 struct io_apic_irq_attr;
21305@@ -206,7 +206,7 @@ struct x86_io_apic_ops {
21306 unsigned int destination, int vector,
21307 struct io_apic_irq_attr *attr);
21308 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
21309-};
21310+} __no_const;
21311
21312 extern struct x86_init_ops x86_init;
21313 extern struct x86_cpuinit_ops x86_cpuinit;
21314diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
21315index c949923..c22bfa4 100644
21316--- a/arch/x86/include/asm/xen/page.h
21317+++ b/arch/x86/include/asm/xen/page.h
21318@@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
21319 extern struct page *m2p_find_override(unsigned long mfn);
21320 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
21321
21322-static inline unsigned long pfn_to_mfn(unsigned long pfn)
21323+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
21324 {
21325 unsigned long mfn;
21326
21327diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
21328index 7e7a79a..0824666 100644
21329--- a/arch/x86/include/asm/xsave.h
21330+++ b/arch/x86/include/asm/xsave.h
21331@@ -228,12 +228,16 @@ static inline int xsave_user(struct xsave_struct __user *buf)
21332 if (unlikely(err))
21333 return -EFAULT;
21334
21335+ pax_open_userland();
21336 __asm__ __volatile__(ASM_STAC "\n"
21337- "1:"XSAVE"\n"
21338+ "1:"
21339+ __copyuser_seg
21340+ XSAVE"\n"
21341 "2: " ASM_CLAC "\n"
21342 xstate_fault
21343 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
21344 : "memory");
21345+ pax_close_userland();
21346 return err;
21347 }
21348
21349@@ -243,16 +247,20 @@ static inline int xsave_user(struct xsave_struct __user *buf)
21350 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
21351 {
21352 int err = 0;
21353- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
21354+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
21355 u32 lmask = mask;
21356 u32 hmask = mask >> 32;
21357
21358+ pax_open_userland();
21359 __asm__ __volatile__(ASM_STAC "\n"
21360- "1:"XRSTOR"\n"
21361+ "1:"
21362+ __copyuser_seg
21363+ XRSTOR"\n"
21364 "2: " ASM_CLAC "\n"
21365 xstate_fault
21366 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
21367 : "memory"); /* memory required? */
21368+ pax_close_userland();
21369 return err;
21370 }
21371
21372diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
21373index bbae024..e1528f9 100644
21374--- a/arch/x86/include/uapi/asm/e820.h
21375+++ b/arch/x86/include/uapi/asm/e820.h
21376@@ -63,7 +63,7 @@ struct e820map {
21377 #define ISA_START_ADDRESS 0xa0000
21378 #define ISA_END_ADDRESS 0x100000
21379
21380-#define BIOS_BEGIN 0x000a0000
21381+#define BIOS_BEGIN 0x000c0000
21382 #define BIOS_END 0x00100000
21383
21384 #define BIOS_ROM_BASE 0xffe00000
21385diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
21386index 7b0a55a..ad115bf 100644
21387--- a/arch/x86/include/uapi/asm/ptrace-abi.h
21388+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
21389@@ -49,7 +49,6 @@
21390 #define EFLAGS 144
21391 #define RSP 152
21392 #define SS 160
21393-#define ARGOFFSET R11
21394 #endif /* __ASSEMBLY__ */
21395
21396 /* top of stack page */
21397diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
21398index ada2e2d..ca69e16 100644
21399--- a/arch/x86/kernel/Makefile
21400+++ b/arch/x86/kernel/Makefile
21401@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
21402 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
21403 obj-$(CONFIG_IRQ_WORK) += irq_work.o
21404 obj-y += probe_roms.o
21405-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
21406+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
21407 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
21408 obj-$(CONFIG_X86_64) += mcount_64.o
21409 obj-y += syscall_$(BITS).o vsyscall_gtod.o
21410diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
21411index a142e77..6222cdd 100644
21412--- a/arch/x86/kernel/acpi/boot.c
21413+++ b/arch/x86/kernel/acpi/boot.c
21414@@ -1276,7 +1276,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
21415 * If your system is blacklisted here, but you find that acpi=force
21416 * works for you, please contact linux-acpi@vger.kernel.org
21417 */
21418-static struct dmi_system_id __initdata acpi_dmi_table[] = {
21419+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
21420 /*
21421 * Boxes that need ACPI disabled
21422 */
21423@@ -1351,7 +1351,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
21424 };
21425
21426 /* second table for DMI checks that should run after early-quirks */
21427-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
21428+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
21429 /*
21430 * HP laptops which use a DSDT reporting as HP/SB400/10000,
21431 * which includes some code which overrides all temperature
21432diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
21433index 3136820..e2c6577 100644
21434--- a/arch/x86/kernel/acpi/sleep.c
21435+++ b/arch/x86/kernel/acpi/sleep.c
21436@@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
21437 #else /* CONFIG_64BIT */
21438 #ifdef CONFIG_SMP
21439 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
21440+
21441+ pax_open_kernel();
21442 early_gdt_descr.address =
21443 (unsigned long)get_cpu_gdt_table(smp_processor_id());
21444+ pax_close_kernel();
21445+
21446 initial_gs = per_cpu_offset(smp_processor_id());
21447 #endif
21448 initial_code = (unsigned long)wakeup_long64;
21449diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
21450index 665c6b7..eae4d56 100644
21451--- a/arch/x86/kernel/acpi/wakeup_32.S
21452+++ b/arch/x86/kernel/acpi/wakeup_32.S
21453@@ -29,13 +29,11 @@ wakeup_pmode_return:
21454 # and restore the stack ... but you need gdt for this to work
21455 movl saved_context_esp, %esp
21456
21457- movl %cs:saved_magic, %eax
21458- cmpl $0x12345678, %eax
21459+ cmpl $0x12345678, saved_magic
21460 jne bogus_magic
21461
21462 # jump to place where we left off
21463- movl saved_eip, %eax
21464- jmp *%eax
21465+ jmp *(saved_eip)
21466
21467 bogus_magic:
21468 jmp bogus_magic
21469diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
21470index 703130f..27a155d 100644
21471--- a/arch/x86/kernel/alternative.c
21472+++ b/arch/x86/kernel/alternative.c
21473@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
21474 */
21475 for (a = start; a < end; a++) {
21476 instr = (u8 *)&a->instr_offset + a->instr_offset;
21477+
21478+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21479+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21480+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
21481+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21482+#endif
21483+
21484 replacement = (u8 *)&a->repl_offset + a->repl_offset;
21485 BUG_ON(a->replacementlen > a->instrlen);
21486 BUG_ON(a->instrlen > sizeof(insnbuf));
21487@@ -284,6 +291,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
21488 add_nops(insnbuf + a->replacementlen,
21489 a->instrlen - a->replacementlen);
21490
21491+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21492+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
21493+ instr = ktva_ktla(instr);
21494+#endif
21495+
21496 text_poke_early(instr, insnbuf, a->instrlen);
21497 }
21498 }
21499@@ -299,10 +311,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
21500 for (poff = start; poff < end; poff++) {
21501 u8 *ptr = (u8 *)poff + *poff;
21502
21503+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21504+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21505+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
21506+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21507+#endif
21508+
21509 if (!*poff || ptr < text || ptr >= text_end)
21510 continue;
21511 /* turn DS segment override prefix into lock prefix */
21512- if (*ptr == 0x3e)
21513+ if (*ktla_ktva(ptr) == 0x3e)
21514 text_poke(ptr, ((unsigned char []){0xf0}), 1);
21515 }
21516 mutex_unlock(&text_mutex);
21517@@ -317,10 +335,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
21518 for (poff = start; poff < end; poff++) {
21519 u8 *ptr = (u8 *)poff + *poff;
21520
21521+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21522+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21523+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
21524+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21525+#endif
21526+
21527 if (!*poff || ptr < text || ptr >= text_end)
21528 continue;
21529 /* turn lock prefix into DS segment override prefix */
21530- if (*ptr == 0xf0)
21531+ if (*ktla_ktva(ptr) == 0xf0)
21532 text_poke(ptr, ((unsigned char []){0x3E}), 1);
21533 }
21534 mutex_unlock(&text_mutex);
21535@@ -457,7 +481,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
21536
21537 BUG_ON(p->len > MAX_PATCH_LEN);
21538 /* prep the buffer with the original instructions */
21539- memcpy(insnbuf, p->instr, p->len);
21540+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
21541 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
21542 (unsigned long)p->instr, p->len);
21543
21544@@ -504,7 +528,7 @@ void __init alternative_instructions(void)
21545 if (!uniproc_patched || num_possible_cpus() == 1)
21546 free_init_pages("SMP alternatives",
21547 (unsigned long)__smp_locks,
21548- (unsigned long)__smp_locks_end);
21549+ PAGE_ALIGN((unsigned long)__smp_locks_end));
21550 #endif
21551
21552 apply_paravirt(__parainstructions, __parainstructions_end);
21553@@ -524,13 +548,17 @@ void __init alternative_instructions(void)
21554 * instructions. And on the local CPU you need to be protected again NMI or MCE
21555 * handlers seeing an inconsistent instruction while you patch.
21556 */
21557-void *__init_or_module text_poke_early(void *addr, const void *opcode,
21558+void *__kprobes text_poke_early(void *addr, const void *opcode,
21559 size_t len)
21560 {
21561 unsigned long flags;
21562 local_irq_save(flags);
21563- memcpy(addr, opcode, len);
21564+
21565+ pax_open_kernel();
21566+ memcpy(ktla_ktva(addr), opcode, len);
21567 sync_core();
21568+ pax_close_kernel();
21569+
21570 local_irq_restore(flags);
21571 /* Could also do a CLFLUSH here to speed up CPU recovery; but
21572 that causes hangs on some VIA CPUs. */
21573@@ -552,36 +580,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
21574 */
21575 void *text_poke(void *addr, const void *opcode, size_t len)
21576 {
21577- unsigned long flags;
21578- char *vaddr;
21579+ unsigned char *vaddr = ktla_ktva(addr);
21580 struct page *pages[2];
21581- int i;
21582+ size_t i;
21583
21584 if (!core_kernel_text((unsigned long)addr)) {
21585- pages[0] = vmalloc_to_page(addr);
21586- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
21587+ pages[0] = vmalloc_to_page(vaddr);
21588+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
21589 } else {
21590- pages[0] = virt_to_page(addr);
21591+ pages[0] = virt_to_page(vaddr);
21592 WARN_ON(!PageReserved(pages[0]));
21593- pages[1] = virt_to_page(addr + PAGE_SIZE);
21594+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
21595 }
21596 BUG_ON(!pages[0]);
21597- local_irq_save(flags);
21598- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
21599- if (pages[1])
21600- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
21601- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
21602- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
21603- clear_fixmap(FIX_TEXT_POKE0);
21604- if (pages[1])
21605- clear_fixmap(FIX_TEXT_POKE1);
21606- local_flush_tlb();
21607- sync_core();
21608- /* Could also do a CLFLUSH here to speed up CPU recovery; but
21609- that causes hangs on some VIA CPUs. */
21610+ text_poke_early(addr, opcode, len);
21611 for (i = 0; i < len; i++)
21612- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
21613- local_irq_restore(flags);
21614+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
21615 return addr;
21616 }
21617
21618@@ -601,7 +615,7 @@ int poke_int3_handler(struct pt_regs *regs)
21619 if (likely(!bp_patching_in_progress))
21620 return 0;
21621
21622- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
21623+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
21624 return 0;
21625
21626 /* set up the specified breakpoint handler */
21627@@ -635,7 +649,7 @@ int poke_int3_handler(struct pt_regs *regs)
21628 */
21629 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
21630 {
21631- unsigned char int3 = 0xcc;
21632+ const unsigned char int3 = 0xcc;
21633
21634 bp_int3_handler = handler;
21635 bp_int3_addr = (u8 *)addr + sizeof(int3);
21636diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
21637index 24b5894..6d9701b 100644
21638--- a/arch/x86/kernel/apic/apic.c
21639+++ b/arch/x86/kernel/apic/apic.c
21640@@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
21641 /*
21642 * Debug level, exported for io_apic.c
21643 */
21644-unsigned int apic_verbosity;
21645+int apic_verbosity;
21646
21647 int pic_mode;
21648
21649@@ -1989,7 +1989,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
21650 apic_write(APIC_ESR, 0);
21651 v = apic_read(APIC_ESR);
21652 ack_APIC_irq();
21653- atomic_inc(&irq_err_count);
21654+ atomic_inc_unchecked(&irq_err_count);
21655
21656 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
21657 smp_processor_id(), v);
21658diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
21659index de918c4..32eed23 100644
21660--- a/arch/x86/kernel/apic/apic_flat_64.c
21661+++ b/arch/x86/kernel/apic/apic_flat_64.c
21662@@ -154,7 +154,7 @@ static int flat_probe(void)
21663 return 1;
21664 }
21665
21666-static struct apic apic_flat = {
21667+static struct apic apic_flat __read_only = {
21668 .name = "flat",
21669 .probe = flat_probe,
21670 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
21671@@ -260,7 +260,7 @@ static int physflat_probe(void)
21672 return 0;
21673 }
21674
21675-static struct apic apic_physflat = {
21676+static struct apic apic_physflat __read_only = {
21677
21678 .name = "physical flat",
21679 .probe = physflat_probe,
21680diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
21681index b205cdb..d8503ff 100644
21682--- a/arch/x86/kernel/apic/apic_noop.c
21683+++ b/arch/x86/kernel/apic/apic_noop.c
21684@@ -108,7 +108,7 @@ static void noop_apic_write(u32 reg, u32 v)
21685 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
21686 }
21687
21688-struct apic apic_noop = {
21689+struct apic apic_noop __read_only = {
21690 .name = "noop",
21691 .probe = noop_probe,
21692 .acpi_madt_oem_check = NULL,
21693diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
21694index c4a8d63..fe893ac 100644
21695--- a/arch/x86/kernel/apic/bigsmp_32.c
21696+++ b/arch/x86/kernel/apic/bigsmp_32.c
21697@@ -147,7 +147,7 @@ static int probe_bigsmp(void)
21698 return dmi_bigsmp;
21699 }
21700
21701-static struct apic apic_bigsmp = {
21702+static struct apic apic_bigsmp __read_only = {
21703
21704 .name = "bigsmp",
21705 .probe = probe_bigsmp,
21706diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
21707index 337ce5a..c8d98b4 100644
21708--- a/arch/x86/kernel/apic/io_apic.c
21709+++ b/arch/x86/kernel/apic/io_apic.c
21710@@ -1230,7 +1230,7 @@ out:
21711 }
21712 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
21713
21714-void lock_vector_lock(void)
21715+void lock_vector_lock(void) __acquires(vector_lock)
21716 {
21717 /* Used to the online set of cpus does not change
21718 * during assign_irq_vector.
21719@@ -1238,7 +1238,7 @@ void lock_vector_lock(void)
21720 raw_spin_lock(&vector_lock);
21721 }
21722
21723-void unlock_vector_lock(void)
21724+void unlock_vector_lock(void) __releases(vector_lock)
21725 {
21726 raw_spin_unlock(&vector_lock);
21727 }
21728@@ -2465,7 +2465,7 @@ static void ack_apic_edge(struct irq_data *data)
21729 ack_APIC_irq();
21730 }
21731
21732-atomic_t irq_mis_count;
21733+atomic_unchecked_t irq_mis_count;
21734
21735 #ifdef CONFIG_GENERIC_PENDING_IRQ
21736 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
21737@@ -2606,7 +2606,7 @@ static void ack_apic_level(struct irq_data *data)
21738 * at the cpu.
21739 */
21740 if (!(v & (1 << (i & 0x1f)))) {
21741- atomic_inc(&irq_mis_count);
21742+ atomic_inc_unchecked(&irq_mis_count);
21743
21744 eoi_ioapic_irq(irq, cfg);
21745 }
21746diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
21747index bda4886..f9c7195 100644
21748--- a/arch/x86/kernel/apic/probe_32.c
21749+++ b/arch/x86/kernel/apic/probe_32.c
21750@@ -72,7 +72,7 @@ static int probe_default(void)
21751 return 1;
21752 }
21753
21754-static struct apic apic_default = {
21755+static struct apic apic_default __read_only = {
21756
21757 .name = "default",
21758 .probe = probe_default,
21759diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
21760index 6ce600f..cb44af8 100644
21761--- a/arch/x86/kernel/apic/x2apic_cluster.c
21762+++ b/arch/x86/kernel/apic/x2apic_cluster.c
21763@@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
21764 return notifier_from_errno(err);
21765 }
21766
21767-static struct notifier_block __refdata x2apic_cpu_notifier = {
21768+static struct notifier_block x2apic_cpu_notifier = {
21769 .notifier_call = update_clusterinfo,
21770 };
21771
21772@@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
21773 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
21774 }
21775
21776-static struct apic apic_x2apic_cluster = {
21777+static struct apic apic_x2apic_cluster __read_only = {
21778
21779 .name = "cluster x2apic",
21780 .probe = x2apic_cluster_probe,
21781diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
21782index 6fae733..5ca17af 100644
21783--- a/arch/x86/kernel/apic/x2apic_phys.c
21784+++ b/arch/x86/kernel/apic/x2apic_phys.c
21785@@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
21786 return apic == &apic_x2apic_phys;
21787 }
21788
21789-static struct apic apic_x2apic_phys = {
21790+static struct apic apic_x2apic_phys __read_only = {
21791
21792 .name = "physical x2apic",
21793 .probe = x2apic_phys_probe,
21794diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
21795index 004f017..8fbc8b5 100644
21796--- a/arch/x86/kernel/apic/x2apic_uv_x.c
21797+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
21798@@ -350,7 +350,7 @@ static int uv_probe(void)
21799 return apic == &apic_x2apic_uv_x;
21800 }
21801
21802-static struct apic __refdata apic_x2apic_uv_x = {
21803+static struct apic apic_x2apic_uv_x __read_only = {
21804
21805 .name = "UV large system",
21806 .probe = uv_probe,
21807diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
21808index 5848744..56cb598 100644
21809--- a/arch/x86/kernel/apm_32.c
21810+++ b/arch/x86/kernel/apm_32.c
21811@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
21812 * This is for buggy BIOS's that refer to (real mode) segment 0x40
21813 * even though they are called in protected mode.
21814 */
21815-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
21816+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
21817 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
21818
21819 static const char driver_version[] = "1.16ac"; /* no spaces */
21820@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
21821 BUG_ON(cpu != 0);
21822 gdt = get_cpu_gdt_table(cpu);
21823 save_desc_40 = gdt[0x40 / 8];
21824+
21825+ pax_open_kernel();
21826 gdt[0x40 / 8] = bad_bios_desc;
21827+ pax_close_kernel();
21828
21829 apm_irq_save(flags);
21830 APM_DO_SAVE_SEGS;
21831@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
21832 &call->esi);
21833 APM_DO_RESTORE_SEGS;
21834 apm_irq_restore(flags);
21835+
21836+ pax_open_kernel();
21837 gdt[0x40 / 8] = save_desc_40;
21838+ pax_close_kernel();
21839+
21840 put_cpu();
21841
21842 return call->eax & 0xff;
21843@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21844 BUG_ON(cpu != 0);
21845 gdt = get_cpu_gdt_table(cpu);
21846 save_desc_40 = gdt[0x40 / 8];
21847+
21848+ pax_open_kernel();
21849 gdt[0x40 / 8] = bad_bios_desc;
21850+ pax_close_kernel();
21851
21852 apm_irq_save(flags);
21853 APM_DO_SAVE_SEGS;
21854@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21855 &call->eax);
21856 APM_DO_RESTORE_SEGS;
21857 apm_irq_restore(flags);
21858+
21859+ pax_open_kernel();
21860 gdt[0x40 / 8] = save_desc_40;
21861+ pax_close_kernel();
21862+
21863 put_cpu();
21864 return error;
21865 }
21866@@ -2350,12 +2364,15 @@ static int __init apm_init(void)
21867 * code to that CPU.
21868 */
21869 gdt = get_cpu_gdt_table(0);
21870+
21871+ pax_open_kernel();
21872 set_desc_base(&gdt[APM_CS >> 3],
21873 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21874 set_desc_base(&gdt[APM_CS_16 >> 3],
21875 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21876 set_desc_base(&gdt[APM_DS >> 3],
21877 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21878+ pax_close_kernel();
21879
21880 proc_create("apm", 0, NULL, &apm_file_ops);
21881
21882diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21883index 9f6b934..cf5ffb3 100644
21884--- a/arch/x86/kernel/asm-offsets.c
21885+++ b/arch/x86/kernel/asm-offsets.c
21886@@ -32,6 +32,8 @@ void common(void) {
21887 OFFSET(TI_flags, thread_info, flags);
21888 OFFSET(TI_status, thread_info, status);
21889 OFFSET(TI_addr_limit, thread_info, addr_limit);
21890+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21891+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21892
21893 BLANK();
21894 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21895@@ -52,8 +54,26 @@ void common(void) {
21896 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21897 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21898 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21899+
21900+#ifdef CONFIG_PAX_KERNEXEC
21901+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21902 #endif
21903
21904+#ifdef CONFIG_PAX_MEMORY_UDEREF
21905+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21906+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21907+#ifdef CONFIG_X86_64
21908+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21909+#endif
21910+#endif
21911+
21912+#endif
21913+
21914+ BLANK();
21915+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21916+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21917+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21918+
21919 #ifdef CONFIG_XEN
21920 BLANK();
21921 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21922diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21923index e7c798b..2b2019b 100644
21924--- a/arch/x86/kernel/asm-offsets_64.c
21925+++ b/arch/x86/kernel/asm-offsets_64.c
21926@@ -77,6 +77,7 @@ int main(void)
21927 BLANK();
21928 #undef ENTRY
21929
21930+ DEFINE(TSS_size, sizeof(struct tss_struct));
21931 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21932 BLANK();
21933
21934diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21935index 7fd54f0..0691410 100644
21936--- a/arch/x86/kernel/cpu/Makefile
21937+++ b/arch/x86/kernel/cpu/Makefile
21938@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21939 CFLAGS_REMOVE_perf_event.o = -pg
21940 endif
21941
21942-# Make sure load_percpu_segment has no stackprotector
21943-nostackp := $(call cc-option, -fno-stack-protector)
21944-CFLAGS_common.o := $(nostackp)
21945-
21946 obj-y := intel_cacheinfo.o scattered.o topology.o
21947 obj-y += proc.o capflags.o powerflags.o common.o
21948 obj-y += rdrand.o
21949diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21950index 813d29d..6e542d4 100644
21951--- a/arch/x86/kernel/cpu/amd.c
21952+++ b/arch/x86/kernel/cpu/amd.c
21953@@ -718,7 +718,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21954 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21955 {
21956 /* AMD errata T13 (order #21922) */
21957- if ((c->x86 == 6)) {
21958+ if (c->x86 == 6) {
21959 /* Duron Rev A0 */
21960 if (c->x86_model == 3 && c->x86_mask == 0)
21961 size = 64;
21962diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21963index 35db56b..256e87c 100644
21964--- a/arch/x86/kernel/cpu/common.c
21965+++ b/arch/x86/kernel/cpu/common.c
21966@@ -90,60 +90,6 @@ static const struct cpu_dev default_cpu = {
21967
21968 static const struct cpu_dev *this_cpu = &default_cpu;
21969
21970-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21971-#ifdef CONFIG_X86_64
21972- /*
21973- * We need valid kernel segments for data and code in long mode too
21974- * IRET will check the segment types kkeil 2000/10/28
21975- * Also sysret mandates a special GDT layout
21976- *
21977- * TLS descriptors are currently at a different place compared to i386.
21978- * Hopefully nobody expects them at a fixed place (Wine?)
21979- */
21980- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21981- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21982- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21983- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21984- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21985- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21986-#else
21987- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21988- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21989- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21990- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21991- /*
21992- * Segments used for calling PnP BIOS have byte granularity.
21993- * They code segments and data segments have fixed 64k limits,
21994- * the transfer segment sizes are set at run time.
21995- */
21996- /* 32-bit code */
21997- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21998- /* 16-bit code */
21999- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
22000- /* 16-bit data */
22001- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
22002- /* 16-bit data */
22003- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
22004- /* 16-bit data */
22005- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
22006- /*
22007- * The APM segments have byte granularity and their bases
22008- * are set at run time. All have 64k limits.
22009- */
22010- /* 32-bit code */
22011- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
22012- /* 16-bit code */
22013- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
22014- /* data */
22015- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
22016-
22017- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
22018- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
22019- GDT_STACK_CANARY_INIT
22020-#endif
22021-} };
22022-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
22023-
22024 static int __init x86_xsave_setup(char *s)
22025 {
22026 if (strlen(s))
22027@@ -305,6 +251,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
22028 }
22029 }
22030
22031+#ifdef CONFIG_X86_64
22032+static __init int setup_disable_pcid(char *arg)
22033+{
22034+ setup_clear_cpu_cap(X86_FEATURE_PCID);
22035+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
22036+
22037+#ifdef CONFIG_PAX_MEMORY_UDEREF
22038+ if (clone_pgd_mask != ~(pgdval_t)0UL)
22039+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
22040+#endif
22041+
22042+ return 1;
22043+}
22044+__setup("nopcid", setup_disable_pcid);
22045+
22046+static void setup_pcid(struct cpuinfo_x86 *c)
22047+{
22048+ if (!cpu_has(c, X86_FEATURE_PCID)) {
22049+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
22050+
22051+#ifdef CONFIG_PAX_MEMORY_UDEREF
22052+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
22053+ pax_open_kernel();
22054+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
22055+ pax_close_kernel();
22056+ printk("PAX: slow and weak UDEREF enabled\n");
22057+ } else
22058+ printk("PAX: UDEREF disabled\n");
22059+#endif
22060+
22061+ return;
22062+ }
22063+
22064+ printk("PAX: PCID detected\n");
22065+ set_in_cr4(X86_CR4_PCIDE);
22066+
22067+#ifdef CONFIG_PAX_MEMORY_UDEREF
22068+ pax_open_kernel();
22069+ clone_pgd_mask = ~(pgdval_t)0UL;
22070+ pax_close_kernel();
22071+ if (pax_user_shadow_base)
22072+ printk("PAX: weak UDEREF enabled\n");
22073+ else {
22074+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
22075+ printk("PAX: strong UDEREF enabled\n");
22076+ }
22077+#endif
22078+
22079+ if (cpu_has(c, X86_FEATURE_INVPCID))
22080+ printk("PAX: INVPCID detected\n");
22081+}
22082+#endif
22083+
22084 /*
22085 * Some CPU features depend on higher CPUID levels, which may not always
22086 * be available due to CPUID level capping or broken virtualization
22087@@ -405,7 +404,7 @@ void switch_to_new_gdt(int cpu)
22088 {
22089 struct desc_ptr gdt_descr;
22090
22091- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
22092+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
22093 gdt_descr.size = GDT_SIZE - 1;
22094 load_gdt(&gdt_descr);
22095 /* Reload the per-cpu base */
22096@@ -895,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
22097 setup_smep(c);
22098 setup_smap(c);
22099
22100+#ifdef CONFIG_X86_64
22101+ setup_pcid(c);
22102+#endif
22103+
22104 /*
22105 * The vendor-specific functions might have changed features.
22106 * Now we do "generic changes."
22107@@ -903,6 +906,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
22108 /* Filter out anything that depends on CPUID levels we don't have */
22109 filter_cpuid_features(c, true);
22110
22111+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
22112+ setup_clear_cpu_cap(X86_FEATURE_SEP);
22113+#endif
22114+
22115 /* If the model name is still unset, do table lookup. */
22116 if (!c->x86_model_id[0]) {
22117 const char *p;
22118@@ -983,7 +990,7 @@ static void syscall32_cpu_init(void)
22119 void enable_sep_cpu(void)
22120 {
22121 int cpu = get_cpu();
22122- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22123+ struct tss_struct *tss = init_tss + cpu;
22124
22125 if (!boot_cpu_has(X86_FEATURE_SEP)) {
22126 put_cpu();
22127@@ -1123,14 +1130,16 @@ static __init int setup_disablecpuid(char *arg)
22128 }
22129 __setup("clearcpuid=", setup_disablecpuid);
22130
22131+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
22132+EXPORT_PER_CPU_SYMBOL(current_tinfo);
22133+
22134 DEFINE_PER_CPU(unsigned long, kernel_stack) =
22135- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
22136+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
22137 EXPORT_PER_CPU_SYMBOL(kernel_stack);
22138
22139 #ifdef CONFIG_X86_64
22140-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
22141-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
22142- (unsigned long) debug_idt_table };
22143+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
22144+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
22145
22146 DEFINE_PER_CPU_FIRST(union irq_stack_union,
22147 irq_stack_union) __aligned(PAGE_SIZE) __visible;
22148@@ -1293,7 +1302,7 @@ void cpu_init(void)
22149 load_ucode_ap();
22150
22151 cpu = stack_smp_processor_id();
22152- t = &per_cpu(init_tss, cpu);
22153+ t = init_tss + cpu;
22154 oist = &per_cpu(orig_ist, cpu);
22155
22156 #ifdef CONFIG_NUMA
22157@@ -1328,7 +1337,6 @@ void cpu_init(void)
22158 wrmsrl(MSR_KERNEL_GS_BASE, 0);
22159 barrier();
22160
22161- x86_configure_nx();
22162 enable_x2apic();
22163
22164 /*
22165@@ -1380,7 +1388,7 @@ void cpu_init(void)
22166 {
22167 int cpu = smp_processor_id();
22168 struct task_struct *curr = current;
22169- struct tss_struct *t = &per_cpu(init_tss, cpu);
22170+ struct tss_struct *t = init_tss + cpu;
22171 struct thread_struct *thread = &curr->thread;
22172
22173 show_ucode_info_early();
22174diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
22175index c703507..28535e3 100644
22176--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
22177+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
22178@@ -1026,6 +1026,22 @@ static struct attribute *default_attrs[] = {
22179 };
22180
22181 #ifdef CONFIG_AMD_NB
22182+static struct attribute *default_attrs_amd_nb[] = {
22183+ &type.attr,
22184+ &level.attr,
22185+ &coherency_line_size.attr,
22186+ &physical_line_partition.attr,
22187+ &ways_of_associativity.attr,
22188+ &number_of_sets.attr,
22189+ &size.attr,
22190+ &shared_cpu_map.attr,
22191+ &shared_cpu_list.attr,
22192+ NULL,
22193+ NULL,
22194+ NULL,
22195+ NULL
22196+};
22197+
22198 static struct attribute **amd_l3_attrs(void)
22199 {
22200 static struct attribute **attrs;
22201@@ -1036,18 +1052,7 @@ static struct attribute **amd_l3_attrs(void)
22202
22203 n = ARRAY_SIZE(default_attrs);
22204
22205- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
22206- n += 2;
22207-
22208- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
22209- n += 1;
22210-
22211- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
22212- if (attrs == NULL)
22213- return attrs = default_attrs;
22214-
22215- for (n = 0; default_attrs[n]; n++)
22216- attrs[n] = default_attrs[n];
22217+ attrs = default_attrs_amd_nb;
22218
22219 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
22220 attrs[n++] = &cache_disable_0.attr;
22221@@ -1098,6 +1103,13 @@ static struct kobj_type ktype_cache = {
22222 .default_attrs = default_attrs,
22223 };
22224
22225+#ifdef CONFIG_AMD_NB
22226+static struct kobj_type ktype_cache_amd_nb = {
22227+ .sysfs_ops = &sysfs_ops,
22228+ .default_attrs = default_attrs_amd_nb,
22229+};
22230+#endif
22231+
22232 static struct kobj_type ktype_percpu_entry = {
22233 .sysfs_ops = &sysfs_ops,
22234 };
22235@@ -1163,20 +1175,26 @@ static int cache_add_dev(struct device *dev)
22236 return retval;
22237 }
22238
22239+#ifdef CONFIG_AMD_NB
22240+ amd_l3_attrs();
22241+#endif
22242+
22243 for (i = 0; i < num_cache_leaves; i++) {
22244+ struct kobj_type *ktype;
22245+
22246 this_object = INDEX_KOBJECT_PTR(cpu, i);
22247 this_object->cpu = cpu;
22248 this_object->index = i;
22249
22250 this_leaf = CPUID4_INFO_IDX(cpu, i);
22251
22252- ktype_cache.default_attrs = default_attrs;
22253+ ktype = &ktype_cache;
22254 #ifdef CONFIG_AMD_NB
22255 if (this_leaf->base.nb)
22256- ktype_cache.default_attrs = amd_l3_attrs();
22257+ ktype = &ktype_cache_amd_nb;
22258 #endif
22259 retval = kobject_init_and_add(&(this_object->kobj),
22260- &ktype_cache,
22261+ ktype,
22262 per_cpu(ici_cache_kobject, cpu),
22263 "index%1lu", i);
22264 if (unlikely(retval)) {
22265diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
22266index bd9ccda..38314e7 100644
22267--- a/arch/x86/kernel/cpu/mcheck/mce.c
22268+++ b/arch/x86/kernel/cpu/mcheck/mce.c
22269@@ -45,6 +45,7 @@
22270 #include <asm/processor.h>
22271 #include <asm/mce.h>
22272 #include <asm/msr.h>
22273+#include <asm/local.h>
22274
22275 #include "mce-internal.h"
22276
22277@@ -259,7 +260,7 @@ static void print_mce(struct mce *m)
22278 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
22279 m->cs, m->ip);
22280
22281- if (m->cs == __KERNEL_CS)
22282+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
22283 print_symbol("{%s}", m->ip);
22284 pr_cont("\n");
22285 }
22286@@ -292,10 +293,10 @@ static void print_mce(struct mce *m)
22287
22288 #define PANIC_TIMEOUT 5 /* 5 seconds */
22289
22290-static atomic_t mce_paniced;
22291+static atomic_unchecked_t mce_paniced;
22292
22293 static int fake_panic;
22294-static atomic_t mce_fake_paniced;
22295+static atomic_unchecked_t mce_fake_paniced;
22296
22297 /* Panic in progress. Enable interrupts and wait for final IPI */
22298 static void wait_for_panic(void)
22299@@ -319,7 +320,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
22300 /*
22301 * Make sure only one CPU runs in machine check panic
22302 */
22303- if (atomic_inc_return(&mce_paniced) > 1)
22304+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
22305 wait_for_panic();
22306 barrier();
22307
22308@@ -327,7 +328,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
22309 console_verbose();
22310 } else {
22311 /* Don't log too much for fake panic */
22312- if (atomic_inc_return(&mce_fake_paniced) > 1)
22313+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
22314 return;
22315 }
22316 /* First print corrected ones that are still unlogged */
22317@@ -366,7 +367,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
22318 if (!fake_panic) {
22319 if (panic_timeout == 0)
22320 panic_timeout = mca_cfg.panic_timeout;
22321- panic(msg);
22322+ panic("%s", msg);
22323 } else
22324 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
22325 }
22326@@ -697,7 +698,7 @@ static int mce_timed_out(u64 *t)
22327 * might have been modified by someone else.
22328 */
22329 rmb();
22330- if (atomic_read(&mce_paniced))
22331+ if (atomic_read_unchecked(&mce_paniced))
22332 wait_for_panic();
22333 if (!mca_cfg.monarch_timeout)
22334 goto out;
22335@@ -1674,7 +1675,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
22336 }
22337
22338 /* Call the installed machine check handler for this CPU setup. */
22339-void (*machine_check_vector)(struct pt_regs *, long error_code) =
22340+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
22341 unexpected_machine_check;
22342
22343 /*
22344@@ -1697,7 +1698,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
22345 return;
22346 }
22347
22348+ pax_open_kernel();
22349 machine_check_vector = do_machine_check;
22350+ pax_close_kernel();
22351
22352 __mcheck_cpu_init_generic();
22353 __mcheck_cpu_init_vendor(c);
22354@@ -1711,7 +1714,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
22355 */
22356
22357 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
22358-static int mce_chrdev_open_count; /* #times opened */
22359+static local_t mce_chrdev_open_count; /* #times opened */
22360 static int mce_chrdev_open_exclu; /* already open exclusive? */
22361
22362 static int mce_chrdev_open(struct inode *inode, struct file *file)
22363@@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
22364 spin_lock(&mce_chrdev_state_lock);
22365
22366 if (mce_chrdev_open_exclu ||
22367- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
22368+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
22369 spin_unlock(&mce_chrdev_state_lock);
22370
22371 return -EBUSY;
22372@@ -1727,7 +1730,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
22373
22374 if (file->f_flags & O_EXCL)
22375 mce_chrdev_open_exclu = 1;
22376- mce_chrdev_open_count++;
22377+ local_inc(&mce_chrdev_open_count);
22378
22379 spin_unlock(&mce_chrdev_state_lock);
22380
22381@@ -1738,7 +1741,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
22382 {
22383 spin_lock(&mce_chrdev_state_lock);
22384
22385- mce_chrdev_open_count--;
22386+ local_dec(&mce_chrdev_open_count);
22387 mce_chrdev_open_exclu = 0;
22388
22389 spin_unlock(&mce_chrdev_state_lock);
22390@@ -2413,7 +2416,7 @@ static __init void mce_init_banks(void)
22391
22392 for (i = 0; i < mca_cfg.banks; i++) {
22393 struct mce_bank *b = &mce_banks[i];
22394- struct device_attribute *a = &b->attr;
22395+ device_attribute_no_const *a = &b->attr;
22396
22397 sysfs_attr_init(&a->attr);
22398 a->attr.name = b->attrname;
22399@@ -2520,7 +2523,7 @@ struct dentry *mce_get_debugfs_dir(void)
22400 static void mce_reset(void)
22401 {
22402 cpu_missing = 0;
22403- atomic_set(&mce_fake_paniced, 0);
22404+ atomic_set_unchecked(&mce_fake_paniced, 0);
22405 atomic_set(&mce_executing, 0);
22406 atomic_set(&mce_callin, 0);
22407 atomic_set(&global_nwo, 0);
22408diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
22409index a304298..49b6d06 100644
22410--- a/arch/x86/kernel/cpu/mcheck/p5.c
22411+++ b/arch/x86/kernel/cpu/mcheck/p5.c
22412@@ -10,6 +10,7 @@
22413 #include <asm/processor.h>
22414 #include <asm/mce.h>
22415 #include <asm/msr.h>
22416+#include <asm/pgtable.h>
22417
22418 /* By default disabled */
22419 int mce_p5_enabled __read_mostly;
22420@@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
22421 if (!cpu_has(c, X86_FEATURE_MCE))
22422 return;
22423
22424+ pax_open_kernel();
22425 machine_check_vector = pentium_machine_check;
22426+ pax_close_kernel();
22427 /* Make sure the vector pointer is visible before we enable MCEs: */
22428 wmb();
22429
22430diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
22431index 7dc5564..1273569 100644
22432--- a/arch/x86/kernel/cpu/mcheck/winchip.c
22433+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
22434@@ -9,6 +9,7 @@
22435 #include <asm/processor.h>
22436 #include <asm/mce.h>
22437 #include <asm/msr.h>
22438+#include <asm/pgtable.h>
22439
22440 /* Machine check handler for WinChip C6: */
22441 static void winchip_machine_check(struct pt_regs *regs, long error_code)
22442@@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
22443 {
22444 u32 lo, hi;
22445
22446+ pax_open_kernel();
22447 machine_check_vector = winchip_machine_check;
22448+ pax_close_kernel();
22449 /* Make sure the vector pointer is visible before we enable MCEs: */
22450 wmb();
22451
22452diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
22453index dd9d619..86e1d81 100644
22454--- a/arch/x86/kernel/cpu/microcode/core.c
22455+++ b/arch/x86/kernel/cpu/microcode/core.c
22456@@ -516,7 +516,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
22457 return NOTIFY_OK;
22458 }
22459
22460-static struct notifier_block __refdata mc_cpu_notifier = {
22461+static struct notifier_block mc_cpu_notifier = {
22462 .notifier_call = mc_cpu_callback,
22463 };
22464
22465diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
22466index a276fa7..e66810f 100644
22467--- a/arch/x86/kernel/cpu/microcode/intel.c
22468+++ b/arch/x86/kernel/cpu/microcode/intel.c
22469@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
22470
22471 static int get_ucode_user(void *to, const void *from, size_t n)
22472 {
22473- return copy_from_user(to, from, n);
22474+ return copy_from_user(to, (const void __force_user *)from, n);
22475 }
22476
22477 static enum ucode_state
22478 request_microcode_user(int cpu, const void __user *buf, size_t size)
22479 {
22480- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
22481+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
22482 }
22483
22484 static void microcode_fini_cpu(int cpu)
22485diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
22486index f961de9..8a9d332 100644
22487--- a/arch/x86/kernel/cpu/mtrr/main.c
22488+++ b/arch/x86/kernel/cpu/mtrr/main.c
22489@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
22490 u64 size_or_mask, size_and_mask;
22491 static bool mtrr_aps_delayed_init;
22492
22493-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
22494+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
22495
22496 const struct mtrr_ops *mtrr_if;
22497
22498diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
22499index df5e41f..816c719 100644
22500--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
22501+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
22502@@ -25,7 +25,7 @@ struct mtrr_ops {
22503 int (*validate_add_page)(unsigned long base, unsigned long size,
22504 unsigned int type);
22505 int (*have_wrcomb)(void);
22506-};
22507+} __do_const;
22508
22509 extern int generic_get_free_region(unsigned long base, unsigned long size,
22510 int replace_reg);
22511diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
22512index 2879ecd..bb8c80b 100644
22513--- a/arch/x86/kernel/cpu/perf_event.c
22514+++ b/arch/x86/kernel/cpu/perf_event.c
22515@@ -1372,7 +1372,7 @@ static void __init pmu_check_apic(void)
22516
22517 }
22518
22519-static struct attribute_group x86_pmu_format_group = {
22520+static attribute_group_no_const x86_pmu_format_group = {
22521 .name = "format",
22522 .attrs = NULL,
22523 };
22524@@ -1471,7 +1471,7 @@ static struct attribute *events_attr[] = {
22525 NULL,
22526 };
22527
22528-static struct attribute_group x86_pmu_events_group = {
22529+static attribute_group_no_const x86_pmu_events_group = {
22530 .name = "events",
22531 .attrs = events_attr,
22532 };
22533@@ -1995,7 +1995,7 @@ static unsigned long get_segment_base(unsigned int segment)
22534 if (idx > GDT_ENTRIES)
22535 return 0;
22536
22537- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
22538+ desc = get_cpu_gdt_table(smp_processor_id());
22539 }
22540
22541 return get_desc_base(desc + idx);
22542@@ -2085,7 +2085,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
22543 break;
22544
22545 perf_callchain_store(entry, frame.return_address);
22546- fp = frame.next_frame;
22547+ fp = (const void __force_user *)frame.next_frame;
22548 }
22549 }
22550
22551diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
22552index 639d128..e92d7e5 100644
22553--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
22554+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
22555@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
22556 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
22557 {
22558 struct attribute **attrs;
22559- struct attribute_group *attr_group;
22560+ attribute_group_no_const *attr_group;
22561 int i = 0, j;
22562
22563 while (amd_iommu_v2_event_descs[i].attr.attr.name)
22564diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
22565index 2502d0d..e5cc05c 100644
22566--- a/arch/x86/kernel/cpu/perf_event_intel.c
22567+++ b/arch/x86/kernel/cpu/perf_event_intel.c
22568@@ -2353,10 +2353,10 @@ __init int intel_pmu_init(void)
22569 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
22570
22571 if (boot_cpu_has(X86_FEATURE_PDCM)) {
22572- u64 capabilities;
22573+ u64 capabilities = x86_pmu.intel_cap.capabilities;
22574
22575- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
22576- x86_pmu.intel_cap.capabilities = capabilities;
22577+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
22578+ x86_pmu.intel_cap.capabilities = capabilities;
22579 }
22580
22581 intel_ds_init();
22582diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22583index 619f769..d510008 100644
22584--- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22585+++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22586@@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
22587 NULL,
22588 };
22589
22590-static struct attribute_group rapl_pmu_events_group = {
22591+static attribute_group_no_const rapl_pmu_events_group __read_only = {
22592 .name = "events",
22593 .attrs = NULL, /* patched at runtime */
22594 };
22595diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22596index 0939f86..69730af 100644
22597--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22598+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22599@@ -3691,7 +3691,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
22600 static int __init uncore_type_init(struct intel_uncore_type *type)
22601 {
22602 struct intel_uncore_pmu *pmus;
22603- struct attribute_group *attr_group;
22604+ attribute_group_no_const *attr_group;
22605 struct attribute **attrs;
22606 int i, j;
22607
22608diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22609index 90236f0..54cb20d 100644
22610--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22611+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22612@@ -503,7 +503,7 @@ struct intel_uncore_box {
22613 struct uncore_event_desc {
22614 struct kobj_attribute attr;
22615 const char *config;
22616-};
22617+} __do_const;
22618
22619 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
22620 { \
22621diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
22622index 3225ae6c..ee3c6db 100644
22623--- a/arch/x86/kernel/cpuid.c
22624+++ b/arch/x86/kernel/cpuid.c
22625@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
22626 return notifier_from_errno(err);
22627 }
22628
22629-static struct notifier_block __refdata cpuid_class_cpu_notifier =
22630+static struct notifier_block cpuid_class_cpu_notifier =
22631 {
22632 .notifier_call = cpuid_class_cpu_callback,
22633 };
22634diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
22635index a618fcd..200e95b 100644
22636--- a/arch/x86/kernel/crash.c
22637+++ b/arch/x86/kernel/crash.c
22638@@ -104,7 +104,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
22639 #ifdef CONFIG_X86_32
22640 struct pt_regs fixed_regs;
22641
22642- if (!user_mode_vm(regs)) {
22643+ if (!user_mode(regs)) {
22644 crash_fixup_ss_esp(&fixed_regs, regs);
22645 regs = &fixed_regs;
22646 }
22647diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
22648index afa64ad..dce67dd 100644
22649--- a/arch/x86/kernel/crash_dump_64.c
22650+++ b/arch/x86/kernel/crash_dump_64.c
22651@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
22652 return -ENOMEM;
22653
22654 if (userbuf) {
22655- if (copy_to_user(buf, vaddr + offset, csize)) {
22656+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
22657 iounmap(vaddr);
22658 return -EFAULT;
22659 }
22660diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
22661index f6dfd93..892ade4 100644
22662--- a/arch/x86/kernel/doublefault.c
22663+++ b/arch/x86/kernel/doublefault.c
22664@@ -12,7 +12,7 @@
22665
22666 #define DOUBLEFAULT_STACKSIZE (1024)
22667 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
22668-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
22669+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
22670
22671 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
22672
22673@@ -22,7 +22,7 @@ static void doublefault_fn(void)
22674 unsigned long gdt, tss;
22675
22676 native_store_gdt(&gdt_desc);
22677- gdt = gdt_desc.address;
22678+ gdt = (unsigned long)gdt_desc.address;
22679
22680 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
22681
22682@@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
22683 /* 0x2 bit is always set */
22684 .flags = X86_EFLAGS_SF | 0x2,
22685 .sp = STACK_START,
22686- .es = __USER_DS,
22687+ .es = __KERNEL_DS,
22688 .cs = __KERNEL_CS,
22689 .ss = __KERNEL_DS,
22690- .ds = __USER_DS,
22691+ .ds = __KERNEL_DS,
22692 .fs = __KERNEL_PERCPU,
22693
22694 .__cr3 = __pa_nodebug(swapper_pg_dir),
22695diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
22696index b74ebc7..2c95874 100644
22697--- a/arch/x86/kernel/dumpstack.c
22698+++ b/arch/x86/kernel/dumpstack.c
22699@@ -2,6 +2,9 @@
22700 * Copyright (C) 1991, 1992 Linus Torvalds
22701 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
22702 */
22703+#ifdef CONFIG_GRKERNSEC_HIDESYM
22704+#define __INCLUDED_BY_HIDESYM 1
22705+#endif
22706 #include <linux/kallsyms.h>
22707 #include <linux/kprobes.h>
22708 #include <linux/uaccess.h>
22709@@ -33,23 +36,21 @@ static void printk_stack_address(unsigned long address, int reliable)
22710
22711 void printk_address(unsigned long address)
22712 {
22713- pr_cont(" [<%p>] %pS\n", (void *)address, (void *)address);
22714+ pr_cont(" [<%p>] %pA\n", (void *)address, (void *)address);
22715 }
22716
22717 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
22718 static void
22719 print_ftrace_graph_addr(unsigned long addr, void *data,
22720 const struct stacktrace_ops *ops,
22721- struct thread_info *tinfo, int *graph)
22722+ struct task_struct *task, int *graph)
22723 {
22724- struct task_struct *task;
22725 unsigned long ret_addr;
22726 int index;
22727
22728 if (addr != (unsigned long)return_to_handler)
22729 return;
22730
22731- task = tinfo->task;
22732 index = task->curr_ret_stack;
22733
22734 if (!task->ret_stack || index < *graph)
22735@@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
22736 static inline void
22737 print_ftrace_graph_addr(unsigned long addr, void *data,
22738 const struct stacktrace_ops *ops,
22739- struct thread_info *tinfo, int *graph)
22740+ struct task_struct *task, int *graph)
22741 { }
22742 #endif
22743
22744@@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
22745 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
22746 */
22747
22748-static inline int valid_stack_ptr(struct thread_info *tinfo,
22749- void *p, unsigned int size, void *end)
22750+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
22751 {
22752- void *t = tinfo;
22753 if (end) {
22754 if (p < end && p >= (end-THREAD_SIZE))
22755 return 1;
22756@@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
22757 }
22758
22759 unsigned long
22760-print_context_stack(struct thread_info *tinfo,
22761+print_context_stack(struct task_struct *task, void *stack_start,
22762 unsigned long *stack, unsigned long bp,
22763 const struct stacktrace_ops *ops, void *data,
22764 unsigned long *end, int *graph)
22765 {
22766 struct stack_frame *frame = (struct stack_frame *)bp;
22767
22768- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
22769+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
22770 unsigned long addr;
22771
22772 addr = *stack;
22773@@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
22774 } else {
22775 ops->address(data, addr, 0);
22776 }
22777- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22778+ print_ftrace_graph_addr(addr, data, ops, task, graph);
22779 }
22780 stack++;
22781 }
22782@@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
22783 EXPORT_SYMBOL_GPL(print_context_stack);
22784
22785 unsigned long
22786-print_context_stack_bp(struct thread_info *tinfo,
22787+print_context_stack_bp(struct task_struct *task, void *stack_start,
22788 unsigned long *stack, unsigned long bp,
22789 const struct stacktrace_ops *ops, void *data,
22790 unsigned long *end, int *graph)
22791@@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22792 struct stack_frame *frame = (struct stack_frame *)bp;
22793 unsigned long *ret_addr = &frame->return_address;
22794
22795- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
22796+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
22797 unsigned long addr = *ret_addr;
22798
22799 if (!__kernel_text_address(addr))
22800@@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22801 ops->address(data, addr, 1);
22802 frame = frame->next_frame;
22803 ret_addr = &frame->return_address;
22804- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22805+ print_ftrace_graph_addr(addr, data, ops, task, graph);
22806 }
22807
22808 return (unsigned long)frame;
22809@@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
22810 static void print_trace_address(void *data, unsigned long addr, int reliable)
22811 {
22812 touch_nmi_watchdog();
22813- printk(data);
22814+ printk("%s", (char *)data);
22815 printk_stack_address(addr, reliable);
22816 }
22817
22818@@ -225,6 +224,8 @@ unsigned long oops_begin(void)
22819 EXPORT_SYMBOL_GPL(oops_begin);
22820 NOKPROBE_SYMBOL(oops_begin);
22821
22822+extern void gr_handle_kernel_exploit(void);
22823+
22824 void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22825 {
22826 if (regs && kexec_should_crash(current))
22827@@ -246,7 +247,10 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22828 panic("Fatal exception in interrupt");
22829 if (panic_on_oops)
22830 panic("Fatal exception");
22831- do_exit(signr);
22832+
22833+ gr_handle_kernel_exploit();
22834+
22835+ do_group_exit(signr);
22836 }
22837 NOKPROBE_SYMBOL(oops_end);
22838
22839@@ -275,7 +279,7 @@ int __die(const char *str, struct pt_regs *regs, long err)
22840 print_modules();
22841 show_regs(regs);
22842 #ifdef CONFIG_X86_32
22843- if (user_mode_vm(regs)) {
22844+ if (user_mode(regs)) {
22845 sp = regs->sp;
22846 ss = regs->ss & 0xffff;
22847 } else {
22848@@ -304,7 +308,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22849 unsigned long flags = oops_begin();
22850 int sig = SIGSEGV;
22851
22852- if (!user_mode_vm(regs))
22853+ if (!user_mode(regs))
22854 report_bug(regs->ip, regs);
22855
22856 if (__die(str, regs, err))
22857diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22858index 5abd4cd..c65733b 100644
22859--- a/arch/x86/kernel/dumpstack_32.c
22860+++ b/arch/x86/kernel/dumpstack_32.c
22861@@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22862 bp = stack_frame(task, regs);
22863
22864 for (;;) {
22865- struct thread_info *context;
22866+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22867 void *end_stack;
22868
22869 end_stack = is_hardirq_stack(stack, cpu);
22870 if (!end_stack)
22871 end_stack = is_softirq_stack(stack, cpu);
22872
22873- context = task_thread_info(task);
22874- bp = ops->walk_stack(context, stack, bp, ops, data,
22875+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
22876 end_stack, &graph);
22877
22878 /* Stop if not on irq stack */
22879@@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
22880 int i;
22881
22882 show_regs_print_info(KERN_EMERG);
22883- __show_regs(regs, !user_mode_vm(regs));
22884+ __show_regs(regs, !user_mode(regs));
22885
22886 /*
22887 * When in-kernel, we also print out the stack and code at the
22888 * time of the fault..
22889 */
22890- if (!user_mode_vm(regs)) {
22891+ if (!user_mode(regs)) {
22892 unsigned int code_prologue = code_bytes * 43 / 64;
22893 unsigned int code_len = code_bytes;
22894 unsigned char c;
22895 u8 *ip;
22896+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22897
22898 pr_emerg("Stack:\n");
22899 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22900
22901 pr_emerg("Code:");
22902
22903- ip = (u8 *)regs->ip - code_prologue;
22904+ ip = (u8 *)regs->ip - code_prologue + cs_base;
22905 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22906 /* try starting at IP */
22907- ip = (u8 *)regs->ip;
22908+ ip = (u8 *)regs->ip + cs_base;
22909 code_len = code_len - code_prologue + 1;
22910 }
22911 for (i = 0; i < code_len; i++, ip++) {
22912@@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
22913 pr_cont(" Bad EIP value.");
22914 break;
22915 }
22916- if (ip == (u8 *)regs->ip)
22917+ if (ip == (u8 *)regs->ip + cs_base)
22918 pr_cont(" <%02x>", c);
22919 else
22920 pr_cont(" %02x", c);
22921@@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
22922 {
22923 unsigned short ud2;
22924
22925+ ip = ktla_ktva(ip);
22926 if (ip < PAGE_OFFSET)
22927 return 0;
22928 if (probe_kernel_address((unsigned short *)ip, ud2))
22929@@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
22930
22931 return ud2 == 0x0b0f;
22932 }
22933+
22934+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22935+void pax_check_alloca(unsigned long size)
22936+{
22937+ unsigned long sp = (unsigned long)&sp, stack_left;
22938+
22939+ /* all kernel stacks are of the same size */
22940+ stack_left = sp & (THREAD_SIZE - 1);
22941+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22942+}
22943+EXPORT_SYMBOL(pax_check_alloca);
22944+#endif
22945diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22946index ff86f19..a20c62c 100644
22947--- a/arch/x86/kernel/dumpstack_64.c
22948+++ b/arch/x86/kernel/dumpstack_64.c
22949@@ -153,12 +153,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22950 const struct stacktrace_ops *ops, void *data)
22951 {
22952 const unsigned cpu = get_cpu();
22953- struct thread_info *tinfo;
22954 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22955 unsigned long dummy;
22956 unsigned used = 0;
22957 int graph = 0;
22958 int done = 0;
22959+ void *stack_start;
22960
22961 if (!task)
22962 task = current;
22963@@ -179,7 +179,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22964 * current stack address. If the stacks consist of nested
22965 * exceptions
22966 */
22967- tinfo = task_thread_info(task);
22968 while (!done) {
22969 unsigned long *stack_end;
22970 enum stack_type stype;
22971@@ -202,7 +201,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22972 if (ops->stack(data, id) < 0)
22973 break;
22974
22975- bp = ops->walk_stack(tinfo, stack, bp, ops,
22976+ bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
22977 data, stack_end, &graph);
22978 ops->stack(data, "<EOE>");
22979 /*
22980@@ -210,6 +209,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22981 * second-to-last pointer (index -2 to end) in the
22982 * exception stack:
22983 */
22984+ if ((u16)stack_end[-1] != __KERNEL_DS)
22985+ goto out;
22986 stack = (unsigned long *) stack_end[-2];
22987 done = 0;
22988 break;
22989@@ -218,7 +219,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22990
22991 if (ops->stack(data, "IRQ") < 0)
22992 break;
22993- bp = ops->walk_stack(tinfo, stack, bp,
22994+ bp = ops->walk_stack(task, irq_stack, stack, bp,
22995 ops, data, stack_end, &graph);
22996 /*
22997 * We link to the next stack (which would be
22998@@ -240,7 +241,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22999 /*
23000 * This handles the process stack:
23001 */
23002- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
23003+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
23004+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
23005+out:
23006 put_cpu();
23007 }
23008 EXPORT_SYMBOL(dump_trace);
23009@@ -349,3 +352,50 @@ int is_valid_bugaddr(unsigned long ip)
23010
23011 return ud2 == 0x0b0f;
23012 }
23013+
23014+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
23015+void pax_check_alloca(unsigned long size)
23016+{
23017+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
23018+ unsigned cpu, used;
23019+ char *id;
23020+
23021+ /* check the process stack first */
23022+ stack_start = (unsigned long)task_stack_page(current);
23023+ stack_end = stack_start + THREAD_SIZE;
23024+ if (likely(stack_start <= sp && sp < stack_end)) {
23025+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
23026+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
23027+ return;
23028+ }
23029+
23030+ cpu = get_cpu();
23031+
23032+ /* check the irq stacks */
23033+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
23034+ stack_start = stack_end - IRQ_STACK_SIZE;
23035+ if (stack_start <= sp && sp < stack_end) {
23036+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
23037+ put_cpu();
23038+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
23039+ return;
23040+ }
23041+
23042+ /* check the exception stacks */
23043+ used = 0;
23044+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
23045+ stack_start = stack_end - EXCEPTION_STKSZ;
23046+ if (stack_end && stack_start <= sp && sp < stack_end) {
23047+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
23048+ put_cpu();
23049+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
23050+ return;
23051+ }
23052+
23053+ put_cpu();
23054+
23055+ /* unknown stack */
23056+ BUG();
23057+}
23058+EXPORT_SYMBOL(pax_check_alloca);
23059+#endif
23060diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
23061index 988c00a..4f673b6 100644
23062--- a/arch/x86/kernel/e820.c
23063+++ b/arch/x86/kernel/e820.c
23064@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
23065
23066 static void early_panic(char *msg)
23067 {
23068- early_printk(msg);
23069- panic(msg);
23070+ early_printk("%s", msg);
23071+ panic("%s", msg);
23072 }
23073
23074 static int userdef __initdata;
23075diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
23076index 01d1c18..8073693 100644
23077--- a/arch/x86/kernel/early_printk.c
23078+++ b/arch/x86/kernel/early_printk.c
23079@@ -7,6 +7,7 @@
23080 #include <linux/pci_regs.h>
23081 #include <linux/pci_ids.h>
23082 #include <linux/errno.h>
23083+#include <linux/sched.h>
23084 #include <asm/io.h>
23085 #include <asm/processor.h>
23086 #include <asm/fcntl.h>
23087diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
23088index 4b0e1df..884b67e 100644
23089--- a/arch/x86/kernel/entry_32.S
23090+++ b/arch/x86/kernel/entry_32.S
23091@@ -177,13 +177,153 @@
23092 /*CFI_REL_OFFSET gs, PT_GS*/
23093 .endm
23094 .macro SET_KERNEL_GS reg
23095+
23096+#ifdef CONFIG_CC_STACKPROTECTOR
23097 movl $(__KERNEL_STACK_CANARY), \reg
23098+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
23099+ movl $(__USER_DS), \reg
23100+#else
23101+ xorl \reg, \reg
23102+#endif
23103+
23104 movl \reg, %gs
23105 .endm
23106
23107 #endif /* CONFIG_X86_32_LAZY_GS */
23108
23109-.macro SAVE_ALL
23110+.macro pax_enter_kernel
23111+#ifdef CONFIG_PAX_KERNEXEC
23112+ call pax_enter_kernel
23113+#endif
23114+.endm
23115+
23116+.macro pax_exit_kernel
23117+#ifdef CONFIG_PAX_KERNEXEC
23118+ call pax_exit_kernel
23119+#endif
23120+.endm
23121+
23122+#ifdef CONFIG_PAX_KERNEXEC
23123+ENTRY(pax_enter_kernel)
23124+#ifdef CONFIG_PARAVIRT
23125+ pushl %eax
23126+ pushl %ecx
23127+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
23128+ mov %eax, %esi
23129+#else
23130+ mov %cr0, %esi
23131+#endif
23132+ bts $16, %esi
23133+ jnc 1f
23134+ mov %cs, %esi
23135+ cmp $__KERNEL_CS, %esi
23136+ jz 3f
23137+ ljmp $__KERNEL_CS, $3f
23138+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
23139+2:
23140+#ifdef CONFIG_PARAVIRT
23141+ mov %esi, %eax
23142+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
23143+#else
23144+ mov %esi, %cr0
23145+#endif
23146+3:
23147+#ifdef CONFIG_PARAVIRT
23148+ popl %ecx
23149+ popl %eax
23150+#endif
23151+ ret
23152+ENDPROC(pax_enter_kernel)
23153+
23154+ENTRY(pax_exit_kernel)
23155+#ifdef CONFIG_PARAVIRT
23156+ pushl %eax
23157+ pushl %ecx
23158+#endif
23159+ mov %cs, %esi
23160+ cmp $__KERNEXEC_KERNEL_CS, %esi
23161+ jnz 2f
23162+#ifdef CONFIG_PARAVIRT
23163+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
23164+ mov %eax, %esi
23165+#else
23166+ mov %cr0, %esi
23167+#endif
23168+ btr $16, %esi
23169+ ljmp $__KERNEL_CS, $1f
23170+1:
23171+#ifdef CONFIG_PARAVIRT
23172+ mov %esi, %eax
23173+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
23174+#else
23175+ mov %esi, %cr0
23176+#endif
23177+2:
23178+#ifdef CONFIG_PARAVIRT
23179+ popl %ecx
23180+ popl %eax
23181+#endif
23182+ ret
23183+ENDPROC(pax_exit_kernel)
23184+#endif
23185+
23186+ .macro pax_erase_kstack
23187+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23188+ call pax_erase_kstack
23189+#endif
23190+ .endm
23191+
23192+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23193+/*
23194+ * ebp: thread_info
23195+ */
23196+ENTRY(pax_erase_kstack)
23197+ pushl %edi
23198+ pushl %ecx
23199+ pushl %eax
23200+
23201+ mov TI_lowest_stack(%ebp), %edi
23202+ mov $-0xBEEF, %eax
23203+ std
23204+
23205+1: mov %edi, %ecx
23206+ and $THREAD_SIZE_asm - 1, %ecx
23207+ shr $2, %ecx
23208+ repne scasl
23209+ jecxz 2f
23210+
23211+ cmp $2*16, %ecx
23212+ jc 2f
23213+
23214+ mov $2*16, %ecx
23215+ repe scasl
23216+ jecxz 2f
23217+ jne 1b
23218+
23219+2: cld
23220+ mov %esp, %ecx
23221+ sub %edi, %ecx
23222+
23223+ cmp $THREAD_SIZE_asm, %ecx
23224+ jb 3f
23225+ ud2
23226+3:
23227+
23228+ shr $2, %ecx
23229+ rep stosl
23230+
23231+ mov TI_task_thread_sp0(%ebp), %edi
23232+ sub $128, %edi
23233+ mov %edi, TI_lowest_stack(%ebp)
23234+
23235+ popl %eax
23236+ popl %ecx
23237+ popl %edi
23238+ ret
23239+ENDPROC(pax_erase_kstack)
23240+#endif
23241+
23242+.macro __SAVE_ALL _DS
23243 cld
23244 PUSH_GS
23245 pushl_cfi %fs
23246@@ -206,7 +346,7 @@
23247 CFI_REL_OFFSET ecx, 0
23248 pushl_cfi %ebx
23249 CFI_REL_OFFSET ebx, 0
23250- movl $(__USER_DS), %edx
23251+ movl $\_DS, %edx
23252 movl %edx, %ds
23253 movl %edx, %es
23254 movl $(__KERNEL_PERCPU), %edx
23255@@ -214,6 +354,15 @@
23256 SET_KERNEL_GS %edx
23257 .endm
23258
23259+.macro SAVE_ALL
23260+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23261+ __SAVE_ALL __KERNEL_DS
23262+ pax_enter_kernel
23263+#else
23264+ __SAVE_ALL __USER_DS
23265+#endif
23266+.endm
23267+
23268 .macro RESTORE_INT_REGS
23269 popl_cfi %ebx
23270 CFI_RESTORE ebx
23271@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
23272 popfl_cfi
23273 jmp syscall_exit
23274 CFI_ENDPROC
23275-END(ret_from_fork)
23276+ENDPROC(ret_from_fork)
23277
23278 ENTRY(ret_from_kernel_thread)
23279 CFI_STARTPROC
23280@@ -340,7 +489,15 @@ ret_from_intr:
23281 andl $SEGMENT_RPL_MASK, %eax
23282 #endif
23283 cmpl $USER_RPL, %eax
23284+
23285+#ifdef CONFIG_PAX_KERNEXEC
23286+ jae resume_userspace
23287+
23288+ pax_exit_kernel
23289+ jmp resume_kernel
23290+#else
23291 jb resume_kernel # not returning to v8086 or userspace
23292+#endif
23293
23294 ENTRY(resume_userspace)
23295 LOCKDEP_SYS_EXIT
23296@@ -352,8 +509,8 @@ ENTRY(resume_userspace)
23297 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
23298 # int/exception return?
23299 jne work_pending
23300- jmp restore_all
23301-END(ret_from_exception)
23302+ jmp restore_all_pax
23303+ENDPROC(ret_from_exception)
23304
23305 #ifdef CONFIG_PREEMPT
23306 ENTRY(resume_kernel)
23307@@ -365,7 +522,7 @@ need_resched:
23308 jz restore_all
23309 call preempt_schedule_irq
23310 jmp need_resched
23311-END(resume_kernel)
23312+ENDPROC(resume_kernel)
23313 #endif
23314 CFI_ENDPROC
23315
23316@@ -395,30 +552,45 @@ sysenter_past_esp:
23317 /*CFI_REL_OFFSET cs, 0*/
23318 /*
23319 * Push current_thread_info()->sysenter_return to the stack.
23320- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
23321- * pushed above; +8 corresponds to copy_thread's esp0 setting.
23322 */
23323- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
23324+ pushl_cfi $0
23325 CFI_REL_OFFSET eip, 0
23326
23327 pushl_cfi %eax
23328 SAVE_ALL
23329+ GET_THREAD_INFO(%ebp)
23330+ movl TI_sysenter_return(%ebp),%ebp
23331+ movl %ebp,PT_EIP(%esp)
23332 ENABLE_INTERRUPTS(CLBR_NONE)
23333
23334 /*
23335 * Load the potential sixth argument from user stack.
23336 * Careful about security.
23337 */
23338+ movl PT_OLDESP(%esp),%ebp
23339+
23340+#ifdef CONFIG_PAX_MEMORY_UDEREF
23341+ mov PT_OLDSS(%esp),%ds
23342+1: movl %ds:(%ebp),%ebp
23343+ push %ss
23344+ pop %ds
23345+#else
23346 cmpl $__PAGE_OFFSET-3,%ebp
23347 jae syscall_fault
23348 ASM_STAC
23349 1: movl (%ebp),%ebp
23350 ASM_CLAC
23351+#endif
23352+
23353 movl %ebp,PT_EBP(%esp)
23354 _ASM_EXTABLE(1b,syscall_fault)
23355
23356 GET_THREAD_INFO(%ebp)
23357
23358+#ifdef CONFIG_PAX_RANDKSTACK
23359+ pax_erase_kstack
23360+#endif
23361+
23362 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
23363 jnz sysenter_audit
23364 sysenter_do_call:
23365@@ -434,12 +606,24 @@ sysenter_after_call:
23366 testl $_TIF_ALLWORK_MASK, %ecx
23367 jne sysexit_audit
23368 sysenter_exit:
23369+
23370+#ifdef CONFIG_PAX_RANDKSTACK
23371+ pushl_cfi %eax
23372+ movl %esp, %eax
23373+ call pax_randomize_kstack
23374+ popl_cfi %eax
23375+#endif
23376+
23377+ pax_erase_kstack
23378+
23379 /* if something modifies registers it must also disable sysexit */
23380 movl PT_EIP(%esp), %edx
23381 movl PT_OLDESP(%esp), %ecx
23382 xorl %ebp,%ebp
23383 TRACE_IRQS_ON
23384 1: mov PT_FS(%esp), %fs
23385+2: mov PT_DS(%esp), %ds
23386+3: mov PT_ES(%esp), %es
23387 PTGS_TO_GS
23388 ENABLE_INTERRUPTS_SYSEXIT
23389
23390@@ -456,6 +640,9 @@ sysenter_audit:
23391 movl %eax,%edx /* 2nd arg: syscall number */
23392 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
23393 call __audit_syscall_entry
23394+
23395+ pax_erase_kstack
23396+
23397 pushl_cfi %ebx
23398 movl PT_EAX(%esp),%eax /* reload syscall number */
23399 jmp sysenter_do_call
23400@@ -481,10 +668,16 @@ sysexit_audit:
23401
23402 CFI_ENDPROC
23403 .pushsection .fixup,"ax"
23404-2: movl $0,PT_FS(%esp)
23405+4: movl $0,PT_FS(%esp)
23406+ jmp 1b
23407+5: movl $0,PT_DS(%esp)
23408+ jmp 1b
23409+6: movl $0,PT_ES(%esp)
23410 jmp 1b
23411 .popsection
23412- _ASM_EXTABLE(1b,2b)
23413+ _ASM_EXTABLE(1b,4b)
23414+ _ASM_EXTABLE(2b,5b)
23415+ _ASM_EXTABLE(3b,6b)
23416 PTGS_TO_GS_EX
23417 ENDPROC(ia32_sysenter_target)
23418
23419@@ -495,6 +688,11 @@ ENTRY(system_call)
23420 pushl_cfi %eax # save orig_eax
23421 SAVE_ALL
23422 GET_THREAD_INFO(%ebp)
23423+
23424+#ifdef CONFIG_PAX_RANDKSTACK
23425+ pax_erase_kstack
23426+#endif
23427+
23428 # system call tracing in operation / emulation
23429 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
23430 jnz syscall_trace_entry
23431@@ -514,6 +712,15 @@ syscall_exit:
23432 testl $_TIF_ALLWORK_MASK, %ecx # current->work
23433 jne syscall_exit_work
23434
23435+restore_all_pax:
23436+
23437+#ifdef CONFIG_PAX_RANDKSTACK
23438+ movl %esp, %eax
23439+ call pax_randomize_kstack
23440+#endif
23441+
23442+ pax_erase_kstack
23443+
23444 restore_all:
23445 TRACE_IRQS_IRET
23446 restore_all_notrace:
23447@@ -568,14 +775,34 @@ ldt_ss:
23448 * compensating for the offset by changing to the ESPFIX segment with
23449 * a base address that matches for the difference.
23450 */
23451-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
23452+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
23453 mov %esp, %edx /* load kernel esp */
23454 mov PT_OLDESP(%esp), %eax /* load userspace esp */
23455 mov %dx, %ax /* eax: new kernel esp */
23456 sub %eax, %edx /* offset (low word is 0) */
23457+#ifdef CONFIG_SMP
23458+ movl PER_CPU_VAR(cpu_number), %ebx
23459+ shll $PAGE_SHIFT_asm, %ebx
23460+ addl $cpu_gdt_table, %ebx
23461+#else
23462+ movl $cpu_gdt_table, %ebx
23463+#endif
23464 shr $16, %edx
23465- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
23466- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
23467+
23468+#ifdef CONFIG_PAX_KERNEXEC
23469+ mov %cr0, %esi
23470+ btr $16, %esi
23471+ mov %esi, %cr0
23472+#endif
23473+
23474+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
23475+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
23476+
23477+#ifdef CONFIG_PAX_KERNEXEC
23478+ bts $16, %esi
23479+ mov %esi, %cr0
23480+#endif
23481+
23482 pushl_cfi $__ESPFIX_SS
23483 pushl_cfi %eax /* new kernel esp */
23484 /* Disable interrupts, but do not irqtrace this section: we
23485@@ -605,20 +832,18 @@ work_resched:
23486 movl TI_flags(%ebp), %ecx
23487 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
23488 # than syscall tracing?
23489- jz restore_all
23490+ jz restore_all_pax
23491 testb $_TIF_NEED_RESCHED, %cl
23492 jnz work_resched
23493
23494 work_notifysig: # deal with pending signals and
23495 # notify-resume requests
23496+ movl %esp, %eax
23497 #ifdef CONFIG_VM86
23498 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
23499- movl %esp, %eax
23500 jne work_notifysig_v86 # returning to kernel-space or
23501 # vm86-space
23502 1:
23503-#else
23504- movl %esp, %eax
23505 #endif
23506 TRACE_IRQS_ON
23507 ENABLE_INTERRUPTS(CLBR_NONE)
23508@@ -639,7 +864,7 @@ work_notifysig_v86:
23509 movl %eax, %esp
23510 jmp 1b
23511 #endif
23512-END(work_pending)
23513+ENDPROC(work_pending)
23514
23515 # perform syscall exit tracing
23516 ALIGN
23517@@ -647,11 +872,14 @@ syscall_trace_entry:
23518 movl $-ENOSYS,PT_EAX(%esp)
23519 movl %esp, %eax
23520 call syscall_trace_enter
23521+
23522+ pax_erase_kstack
23523+
23524 /* What it returned is what we'll actually use. */
23525 cmpl $(NR_syscalls), %eax
23526 jnae syscall_call
23527 jmp syscall_exit
23528-END(syscall_trace_entry)
23529+ENDPROC(syscall_trace_entry)
23530
23531 # perform syscall exit tracing
23532 ALIGN
23533@@ -664,26 +892,30 @@ syscall_exit_work:
23534 movl %esp, %eax
23535 call syscall_trace_leave
23536 jmp resume_userspace
23537-END(syscall_exit_work)
23538+ENDPROC(syscall_exit_work)
23539 CFI_ENDPROC
23540
23541 RING0_INT_FRAME # can't unwind into user space anyway
23542 syscall_fault:
23543+#ifdef CONFIG_PAX_MEMORY_UDEREF
23544+ push %ss
23545+ pop %ds
23546+#endif
23547 ASM_CLAC
23548 GET_THREAD_INFO(%ebp)
23549 movl $-EFAULT,PT_EAX(%esp)
23550 jmp resume_userspace
23551-END(syscall_fault)
23552+ENDPROC(syscall_fault)
23553
23554 syscall_badsys:
23555 movl $-ENOSYS,%eax
23556 jmp syscall_after_call
23557-END(syscall_badsys)
23558+ENDPROC(syscall_badsys)
23559
23560 sysenter_badsys:
23561 movl $-ENOSYS,%eax
23562 jmp sysenter_after_call
23563-END(sysenter_badsys)
23564+ENDPROC(sysenter_badsys)
23565 CFI_ENDPROC
23566
23567 .macro FIXUP_ESPFIX_STACK
23568@@ -696,8 +928,15 @@ END(sysenter_badsys)
23569 */
23570 #ifdef CONFIG_X86_ESPFIX32
23571 /* fixup the stack */
23572- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
23573- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
23574+#ifdef CONFIG_SMP
23575+ movl PER_CPU_VAR(cpu_number), %ebx
23576+ shll $PAGE_SHIFT_asm, %ebx
23577+ addl $cpu_gdt_table, %ebx
23578+#else
23579+ movl $cpu_gdt_table, %ebx
23580+#endif
23581+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
23582+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
23583 shl $16, %eax
23584 addl %esp, %eax /* the adjusted stack pointer */
23585 pushl_cfi $__KERNEL_DS
23586@@ -753,7 +992,7 @@ vector=vector+1
23587 .endr
23588 2: jmp common_interrupt
23589 .endr
23590-END(irq_entries_start)
23591+ENDPROC(irq_entries_start)
23592
23593 .previous
23594 END(interrupt)
23595@@ -810,7 +1049,7 @@ ENTRY(coprocessor_error)
23596 pushl_cfi $do_coprocessor_error
23597 jmp error_code
23598 CFI_ENDPROC
23599-END(coprocessor_error)
23600+ENDPROC(coprocessor_error)
23601
23602 ENTRY(simd_coprocessor_error)
23603 RING0_INT_FRAME
23604@@ -823,7 +1062,7 @@ ENTRY(simd_coprocessor_error)
23605 .section .altinstructions,"a"
23606 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
23607 .previous
23608-.section .altinstr_replacement,"ax"
23609+.section .altinstr_replacement,"a"
23610 663: pushl $do_simd_coprocessor_error
23611 664:
23612 .previous
23613@@ -832,7 +1071,7 @@ ENTRY(simd_coprocessor_error)
23614 #endif
23615 jmp error_code
23616 CFI_ENDPROC
23617-END(simd_coprocessor_error)
23618+ENDPROC(simd_coprocessor_error)
23619
23620 ENTRY(device_not_available)
23621 RING0_INT_FRAME
23622@@ -841,18 +1080,18 @@ ENTRY(device_not_available)
23623 pushl_cfi $do_device_not_available
23624 jmp error_code
23625 CFI_ENDPROC
23626-END(device_not_available)
23627+ENDPROC(device_not_available)
23628
23629 #ifdef CONFIG_PARAVIRT
23630 ENTRY(native_iret)
23631 iret
23632 _ASM_EXTABLE(native_iret, iret_exc)
23633-END(native_iret)
23634+ENDPROC(native_iret)
23635
23636 ENTRY(native_irq_enable_sysexit)
23637 sti
23638 sysexit
23639-END(native_irq_enable_sysexit)
23640+ENDPROC(native_irq_enable_sysexit)
23641 #endif
23642
23643 ENTRY(overflow)
23644@@ -862,7 +1101,7 @@ ENTRY(overflow)
23645 pushl_cfi $do_overflow
23646 jmp error_code
23647 CFI_ENDPROC
23648-END(overflow)
23649+ENDPROC(overflow)
23650
23651 ENTRY(bounds)
23652 RING0_INT_FRAME
23653@@ -871,7 +1110,7 @@ ENTRY(bounds)
23654 pushl_cfi $do_bounds
23655 jmp error_code
23656 CFI_ENDPROC
23657-END(bounds)
23658+ENDPROC(bounds)
23659
23660 ENTRY(invalid_op)
23661 RING0_INT_FRAME
23662@@ -880,7 +1119,7 @@ ENTRY(invalid_op)
23663 pushl_cfi $do_invalid_op
23664 jmp error_code
23665 CFI_ENDPROC
23666-END(invalid_op)
23667+ENDPROC(invalid_op)
23668
23669 ENTRY(coprocessor_segment_overrun)
23670 RING0_INT_FRAME
23671@@ -889,7 +1128,7 @@ ENTRY(coprocessor_segment_overrun)
23672 pushl_cfi $do_coprocessor_segment_overrun
23673 jmp error_code
23674 CFI_ENDPROC
23675-END(coprocessor_segment_overrun)
23676+ENDPROC(coprocessor_segment_overrun)
23677
23678 ENTRY(invalid_TSS)
23679 RING0_EC_FRAME
23680@@ -897,7 +1136,7 @@ ENTRY(invalid_TSS)
23681 pushl_cfi $do_invalid_TSS
23682 jmp error_code
23683 CFI_ENDPROC
23684-END(invalid_TSS)
23685+ENDPROC(invalid_TSS)
23686
23687 ENTRY(segment_not_present)
23688 RING0_EC_FRAME
23689@@ -905,7 +1144,7 @@ ENTRY(segment_not_present)
23690 pushl_cfi $do_segment_not_present
23691 jmp error_code
23692 CFI_ENDPROC
23693-END(segment_not_present)
23694+ENDPROC(segment_not_present)
23695
23696 ENTRY(stack_segment)
23697 RING0_EC_FRAME
23698@@ -913,7 +1152,7 @@ ENTRY(stack_segment)
23699 pushl_cfi $do_stack_segment
23700 jmp error_code
23701 CFI_ENDPROC
23702-END(stack_segment)
23703+ENDPROC(stack_segment)
23704
23705 ENTRY(alignment_check)
23706 RING0_EC_FRAME
23707@@ -921,7 +1160,7 @@ ENTRY(alignment_check)
23708 pushl_cfi $do_alignment_check
23709 jmp error_code
23710 CFI_ENDPROC
23711-END(alignment_check)
23712+ENDPROC(alignment_check)
23713
23714 ENTRY(divide_error)
23715 RING0_INT_FRAME
23716@@ -930,7 +1169,7 @@ ENTRY(divide_error)
23717 pushl_cfi $do_divide_error
23718 jmp error_code
23719 CFI_ENDPROC
23720-END(divide_error)
23721+ENDPROC(divide_error)
23722
23723 #ifdef CONFIG_X86_MCE
23724 ENTRY(machine_check)
23725@@ -940,7 +1179,7 @@ ENTRY(machine_check)
23726 pushl_cfi machine_check_vector
23727 jmp error_code
23728 CFI_ENDPROC
23729-END(machine_check)
23730+ENDPROC(machine_check)
23731 #endif
23732
23733 ENTRY(spurious_interrupt_bug)
23734@@ -950,7 +1189,7 @@ ENTRY(spurious_interrupt_bug)
23735 pushl_cfi $do_spurious_interrupt_bug
23736 jmp error_code
23737 CFI_ENDPROC
23738-END(spurious_interrupt_bug)
23739+ENDPROC(spurious_interrupt_bug)
23740
23741 #ifdef CONFIG_XEN
23742 /* Xen doesn't set %esp to be precisely what the normal sysenter
23743@@ -1056,7 +1295,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
23744
23745 ENTRY(mcount)
23746 ret
23747-END(mcount)
23748+ENDPROC(mcount)
23749
23750 ENTRY(ftrace_caller)
23751 pushl %eax
23752@@ -1086,7 +1325,7 @@ ftrace_graph_call:
23753 .globl ftrace_stub
23754 ftrace_stub:
23755 ret
23756-END(ftrace_caller)
23757+ENDPROC(ftrace_caller)
23758
23759 ENTRY(ftrace_regs_caller)
23760 pushf /* push flags before compare (in cs location) */
23761@@ -1184,7 +1423,7 @@ trace:
23762 popl %ecx
23763 popl %eax
23764 jmp ftrace_stub
23765-END(mcount)
23766+ENDPROC(mcount)
23767 #endif /* CONFIG_DYNAMIC_FTRACE */
23768 #endif /* CONFIG_FUNCTION_TRACER */
23769
23770@@ -1202,7 +1441,7 @@ ENTRY(ftrace_graph_caller)
23771 popl %ecx
23772 popl %eax
23773 ret
23774-END(ftrace_graph_caller)
23775+ENDPROC(ftrace_graph_caller)
23776
23777 .globl return_to_handler
23778 return_to_handler:
23779@@ -1263,15 +1502,18 @@ error_code:
23780 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
23781 REG_TO_PTGS %ecx
23782 SET_KERNEL_GS %ecx
23783- movl $(__USER_DS), %ecx
23784+ movl $(__KERNEL_DS), %ecx
23785 movl %ecx, %ds
23786 movl %ecx, %es
23787+
23788+ pax_enter_kernel
23789+
23790 TRACE_IRQS_OFF
23791 movl %esp,%eax # pt_regs pointer
23792 call *%edi
23793 jmp ret_from_exception
23794 CFI_ENDPROC
23795-END(page_fault)
23796+ENDPROC(page_fault)
23797
23798 /*
23799 * Debug traps and NMI can happen at the one SYSENTER instruction
23800@@ -1314,7 +1556,7 @@ debug_stack_correct:
23801 call do_debug
23802 jmp ret_from_exception
23803 CFI_ENDPROC
23804-END(debug)
23805+ENDPROC(debug)
23806
23807 /*
23808 * NMI is doubly nasty. It can happen _while_ we're handling
23809@@ -1354,6 +1596,9 @@ nmi_stack_correct:
23810 xorl %edx,%edx # zero error code
23811 movl %esp,%eax # pt_regs pointer
23812 call do_nmi
23813+
23814+ pax_exit_kernel
23815+
23816 jmp restore_all_notrace
23817 CFI_ENDPROC
23818
23819@@ -1391,13 +1636,16 @@ nmi_espfix_stack:
23820 FIXUP_ESPFIX_STACK # %eax == %esp
23821 xorl %edx,%edx # zero error code
23822 call do_nmi
23823+
23824+ pax_exit_kernel
23825+
23826 RESTORE_REGS
23827 lss 12+4(%esp), %esp # back to espfix stack
23828 CFI_ADJUST_CFA_OFFSET -24
23829 jmp irq_return
23830 #endif
23831 CFI_ENDPROC
23832-END(nmi)
23833+ENDPROC(nmi)
23834
23835 ENTRY(int3)
23836 RING0_INT_FRAME
23837@@ -1410,14 +1658,14 @@ ENTRY(int3)
23838 call do_int3
23839 jmp ret_from_exception
23840 CFI_ENDPROC
23841-END(int3)
23842+ENDPROC(int3)
23843
23844 ENTRY(general_protection)
23845 RING0_EC_FRAME
23846 pushl_cfi $do_general_protection
23847 jmp error_code
23848 CFI_ENDPROC
23849-END(general_protection)
23850+ENDPROC(general_protection)
23851
23852 #ifdef CONFIG_KVM_GUEST
23853 ENTRY(async_page_fault)
23854@@ -1426,6 +1674,6 @@ ENTRY(async_page_fault)
23855 pushl_cfi $do_async_page_fault
23856 jmp error_code
23857 CFI_ENDPROC
23858-END(async_page_fault)
23859+ENDPROC(async_page_fault)
23860 #endif
23861
23862diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23863index b9dde27..6e9dc4e 100644
23864--- a/arch/x86/kernel/entry_64.S
23865+++ b/arch/x86/kernel/entry_64.S
23866@@ -59,6 +59,8 @@
23867 #include <asm/smap.h>
23868 #include <asm/pgtable_types.h>
23869 #include <linux/err.h>
23870+#include <asm/pgtable.h>
23871+#include <asm/alternative-asm.h>
23872
23873 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23874 #include <linux/elf-em.h>
23875@@ -81,6 +83,430 @@ ENTRY(native_usergs_sysret64)
23876 ENDPROC(native_usergs_sysret64)
23877 #endif /* CONFIG_PARAVIRT */
23878
23879+ .macro ljmpq sel, off
23880+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23881+ .byte 0x48; ljmp *1234f(%rip)
23882+ .pushsection .rodata
23883+ .align 16
23884+ 1234: .quad \off; .word \sel
23885+ .popsection
23886+#else
23887+ pushq $\sel
23888+ pushq $\off
23889+ lretq
23890+#endif
23891+ .endm
23892+
23893+ .macro pax_enter_kernel
23894+ pax_set_fptr_mask
23895+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23896+ call pax_enter_kernel
23897+#endif
23898+ .endm
23899+
23900+ .macro pax_exit_kernel
23901+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23902+ call pax_exit_kernel
23903+#endif
23904+
23905+ .endm
23906+
23907+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23908+ENTRY(pax_enter_kernel)
23909+ pushq %rdi
23910+
23911+#ifdef CONFIG_PARAVIRT
23912+ PV_SAVE_REGS(CLBR_RDI)
23913+#endif
23914+
23915+#ifdef CONFIG_PAX_KERNEXEC
23916+ GET_CR0_INTO_RDI
23917+ bts $16,%rdi
23918+ jnc 3f
23919+ mov %cs,%edi
23920+ cmp $__KERNEL_CS,%edi
23921+ jnz 2f
23922+1:
23923+#endif
23924+
23925+#ifdef CONFIG_PAX_MEMORY_UDEREF
23926+ 661: jmp 111f
23927+ .pushsection .altinstr_replacement, "a"
23928+ 662: ASM_NOP2
23929+ .popsection
23930+ .pushsection .altinstructions, "a"
23931+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23932+ .popsection
23933+ GET_CR3_INTO_RDI
23934+ cmp $0,%dil
23935+ jnz 112f
23936+ mov $__KERNEL_DS,%edi
23937+ mov %edi,%ss
23938+ jmp 111f
23939+112: cmp $1,%dil
23940+ jz 113f
23941+ ud2
23942+113: sub $4097,%rdi
23943+ bts $63,%rdi
23944+ SET_RDI_INTO_CR3
23945+ mov $__UDEREF_KERNEL_DS,%edi
23946+ mov %edi,%ss
23947+111:
23948+#endif
23949+
23950+#ifdef CONFIG_PARAVIRT
23951+ PV_RESTORE_REGS(CLBR_RDI)
23952+#endif
23953+
23954+ popq %rdi
23955+ pax_force_retaddr
23956+ retq
23957+
23958+#ifdef CONFIG_PAX_KERNEXEC
23959+2: ljmpq __KERNEL_CS,1b
23960+3: ljmpq __KERNEXEC_KERNEL_CS,4f
23961+4: SET_RDI_INTO_CR0
23962+ jmp 1b
23963+#endif
23964+ENDPROC(pax_enter_kernel)
23965+
23966+ENTRY(pax_exit_kernel)
23967+ pushq %rdi
23968+
23969+#ifdef CONFIG_PARAVIRT
23970+ PV_SAVE_REGS(CLBR_RDI)
23971+#endif
23972+
23973+#ifdef CONFIG_PAX_KERNEXEC
23974+ mov %cs,%rdi
23975+ cmp $__KERNEXEC_KERNEL_CS,%edi
23976+ jz 2f
23977+ GET_CR0_INTO_RDI
23978+ bts $16,%rdi
23979+ jnc 4f
23980+1:
23981+#endif
23982+
23983+#ifdef CONFIG_PAX_MEMORY_UDEREF
23984+ 661: jmp 111f
23985+ .pushsection .altinstr_replacement, "a"
23986+ 662: ASM_NOP2
23987+ .popsection
23988+ .pushsection .altinstructions, "a"
23989+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23990+ .popsection
23991+ mov %ss,%edi
23992+ cmp $__UDEREF_KERNEL_DS,%edi
23993+ jnz 111f
23994+ GET_CR3_INTO_RDI
23995+ cmp $0,%dil
23996+ jz 112f
23997+ ud2
23998+112: add $4097,%rdi
23999+ bts $63,%rdi
24000+ SET_RDI_INTO_CR3
24001+ mov $__KERNEL_DS,%edi
24002+ mov %edi,%ss
24003+111:
24004+#endif
24005+
24006+#ifdef CONFIG_PARAVIRT
24007+ PV_RESTORE_REGS(CLBR_RDI);
24008+#endif
24009+
24010+ popq %rdi
24011+ pax_force_retaddr
24012+ retq
24013+
24014+#ifdef CONFIG_PAX_KERNEXEC
24015+2: GET_CR0_INTO_RDI
24016+ btr $16,%rdi
24017+ jnc 4f
24018+ ljmpq __KERNEL_CS,3f
24019+3: SET_RDI_INTO_CR0
24020+ jmp 1b
24021+4: ud2
24022+ jmp 4b
24023+#endif
24024+ENDPROC(pax_exit_kernel)
24025+#endif
24026+
24027+ .macro pax_enter_kernel_user
24028+ pax_set_fptr_mask
24029+#ifdef CONFIG_PAX_MEMORY_UDEREF
24030+ call pax_enter_kernel_user
24031+#endif
24032+ .endm
24033+
24034+ .macro pax_exit_kernel_user
24035+#ifdef CONFIG_PAX_MEMORY_UDEREF
24036+ call pax_exit_kernel_user
24037+#endif
24038+#ifdef CONFIG_PAX_RANDKSTACK
24039+ pushq %rax
24040+ pushq %r11
24041+ call pax_randomize_kstack
24042+ popq %r11
24043+ popq %rax
24044+#endif
24045+ .endm
24046+
24047+#ifdef CONFIG_PAX_MEMORY_UDEREF
24048+ENTRY(pax_enter_kernel_user)
24049+ pushq %rdi
24050+ pushq %rbx
24051+
24052+#ifdef CONFIG_PARAVIRT
24053+ PV_SAVE_REGS(CLBR_RDI)
24054+#endif
24055+
24056+ 661: jmp 111f
24057+ .pushsection .altinstr_replacement, "a"
24058+ 662: ASM_NOP2
24059+ .popsection
24060+ .pushsection .altinstructions, "a"
24061+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
24062+ .popsection
24063+ GET_CR3_INTO_RDI
24064+ cmp $1,%dil
24065+ jnz 4f
24066+ sub $4097,%rdi
24067+ bts $63,%rdi
24068+ SET_RDI_INTO_CR3
24069+ jmp 3f
24070+111:
24071+
24072+ GET_CR3_INTO_RDI
24073+ mov %rdi,%rbx
24074+ add $__START_KERNEL_map,%rbx
24075+ sub phys_base(%rip),%rbx
24076+
24077+#ifdef CONFIG_PARAVIRT
24078+ cmpl $0, pv_info+PARAVIRT_enabled
24079+ jz 1f
24080+ pushq %rdi
24081+ i = 0
24082+ .rept USER_PGD_PTRS
24083+ mov i*8(%rbx),%rsi
24084+ mov $0,%sil
24085+ lea i*8(%rbx),%rdi
24086+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
24087+ i = i + 1
24088+ .endr
24089+ popq %rdi
24090+ jmp 2f
24091+1:
24092+#endif
24093+
24094+ i = 0
24095+ .rept USER_PGD_PTRS
24096+ movb $0,i*8(%rbx)
24097+ i = i + 1
24098+ .endr
24099+
24100+2: SET_RDI_INTO_CR3
24101+
24102+#ifdef CONFIG_PAX_KERNEXEC
24103+ GET_CR0_INTO_RDI
24104+ bts $16,%rdi
24105+ SET_RDI_INTO_CR0
24106+#endif
24107+
24108+3:
24109+
24110+#ifdef CONFIG_PARAVIRT
24111+ PV_RESTORE_REGS(CLBR_RDI)
24112+#endif
24113+
24114+ popq %rbx
24115+ popq %rdi
24116+ pax_force_retaddr
24117+ retq
24118+4: ud2
24119+ENDPROC(pax_enter_kernel_user)
24120+
24121+ENTRY(pax_exit_kernel_user)
24122+ pushq %rdi
24123+ pushq %rbx
24124+
24125+#ifdef CONFIG_PARAVIRT
24126+ PV_SAVE_REGS(CLBR_RDI)
24127+#endif
24128+
24129+ GET_CR3_INTO_RDI
24130+ 661: jmp 1f
24131+ .pushsection .altinstr_replacement, "a"
24132+ 662: ASM_NOP2
24133+ .popsection
24134+ .pushsection .altinstructions, "a"
24135+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
24136+ .popsection
24137+ cmp $0,%dil
24138+ jnz 3f
24139+ add $4097,%rdi
24140+ bts $63,%rdi
24141+ SET_RDI_INTO_CR3
24142+ jmp 2f
24143+1:
24144+
24145+ mov %rdi,%rbx
24146+
24147+#ifdef CONFIG_PAX_KERNEXEC
24148+ GET_CR0_INTO_RDI
24149+ btr $16,%rdi
24150+ jnc 3f
24151+ SET_RDI_INTO_CR0
24152+#endif
24153+
24154+ add $__START_KERNEL_map,%rbx
24155+ sub phys_base(%rip),%rbx
24156+
24157+#ifdef CONFIG_PARAVIRT
24158+ cmpl $0, pv_info+PARAVIRT_enabled
24159+ jz 1f
24160+ i = 0
24161+ .rept USER_PGD_PTRS
24162+ mov i*8(%rbx),%rsi
24163+ mov $0x67,%sil
24164+ lea i*8(%rbx),%rdi
24165+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
24166+ i = i + 1
24167+ .endr
24168+ jmp 2f
24169+1:
24170+#endif
24171+
24172+ i = 0
24173+ .rept USER_PGD_PTRS
24174+ movb $0x67,i*8(%rbx)
24175+ i = i + 1
24176+ .endr
24177+2:
24178+
24179+#ifdef CONFIG_PARAVIRT
24180+ PV_RESTORE_REGS(CLBR_RDI)
24181+#endif
24182+
24183+ popq %rbx
24184+ popq %rdi
24185+ pax_force_retaddr
24186+ retq
24187+3: ud2
24188+ENDPROC(pax_exit_kernel_user)
24189+#endif
24190+
24191+ .macro pax_enter_kernel_nmi
24192+ pax_set_fptr_mask
24193+
24194+#ifdef CONFIG_PAX_KERNEXEC
24195+ GET_CR0_INTO_RDI
24196+ bts $16,%rdi
24197+ jc 110f
24198+ SET_RDI_INTO_CR0
24199+ or $2,%ebx
24200+110:
24201+#endif
24202+
24203+#ifdef CONFIG_PAX_MEMORY_UDEREF
24204+ 661: jmp 111f
24205+ .pushsection .altinstr_replacement, "a"
24206+ 662: ASM_NOP2
24207+ .popsection
24208+ .pushsection .altinstructions, "a"
24209+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
24210+ .popsection
24211+ GET_CR3_INTO_RDI
24212+ cmp $0,%dil
24213+ jz 111f
24214+ sub $4097,%rdi
24215+ or $4,%ebx
24216+ bts $63,%rdi
24217+ SET_RDI_INTO_CR3
24218+ mov $__UDEREF_KERNEL_DS,%edi
24219+ mov %edi,%ss
24220+111:
24221+#endif
24222+ .endm
24223+
24224+ .macro pax_exit_kernel_nmi
24225+#ifdef CONFIG_PAX_KERNEXEC
24226+ btr $1,%ebx
24227+ jnc 110f
24228+ GET_CR0_INTO_RDI
24229+ btr $16,%rdi
24230+ SET_RDI_INTO_CR0
24231+110:
24232+#endif
24233+
24234+#ifdef CONFIG_PAX_MEMORY_UDEREF
24235+ btr $2,%ebx
24236+ jnc 111f
24237+ GET_CR3_INTO_RDI
24238+ add $4097,%rdi
24239+ bts $63,%rdi
24240+ SET_RDI_INTO_CR3
24241+ mov $__KERNEL_DS,%edi
24242+ mov %edi,%ss
24243+111:
24244+#endif
24245+ .endm
24246+
24247+ .macro pax_erase_kstack
24248+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
24249+ call pax_erase_kstack
24250+#endif
24251+ .endm
24252+
24253+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
24254+ENTRY(pax_erase_kstack)
24255+ pushq %rdi
24256+ pushq %rcx
24257+ pushq %rax
24258+ pushq %r11
24259+
24260+ GET_THREAD_INFO(%r11)
24261+ mov TI_lowest_stack(%r11), %rdi
24262+ mov $-0xBEEF, %rax
24263+ std
24264+
24265+1: mov %edi, %ecx
24266+ and $THREAD_SIZE_asm - 1, %ecx
24267+ shr $3, %ecx
24268+ repne scasq
24269+ jecxz 2f
24270+
24271+ cmp $2*8, %ecx
24272+ jc 2f
24273+
24274+ mov $2*8, %ecx
24275+ repe scasq
24276+ jecxz 2f
24277+ jne 1b
24278+
24279+2: cld
24280+ mov %esp, %ecx
24281+ sub %edi, %ecx
24282+
24283+ cmp $THREAD_SIZE_asm, %rcx
24284+ jb 3f
24285+ ud2
24286+3:
24287+
24288+ shr $3, %ecx
24289+ rep stosq
24290+
24291+ mov TI_task_thread_sp0(%r11), %rdi
24292+ sub $256, %rdi
24293+ mov %rdi, TI_lowest_stack(%r11)
24294+
24295+ popq %r11
24296+ popq %rax
24297+ popq %rcx
24298+ popq %rdi
24299+ pax_force_retaddr
24300+ ret
24301+ENDPROC(pax_erase_kstack)
24302+#endif
24303
24304 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
24305 #ifdef CONFIG_TRACE_IRQFLAGS
24306@@ -117,7 +543,7 @@ ENDPROC(native_usergs_sysret64)
24307 .endm
24308
24309 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
24310- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
24311+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
24312 jnc 1f
24313 TRACE_IRQS_ON_DEBUG
24314 1:
24315@@ -155,27 +581,6 @@ ENDPROC(native_usergs_sysret64)
24316 movq \tmp,R11+\offset(%rsp)
24317 .endm
24318
24319- .macro FAKE_STACK_FRAME child_rip
24320- /* push in order ss, rsp, eflags, cs, rip */
24321- xorl %eax, %eax
24322- pushq_cfi $__KERNEL_DS /* ss */
24323- /*CFI_REL_OFFSET ss,0*/
24324- pushq_cfi %rax /* rsp */
24325- CFI_REL_OFFSET rsp,0
24326- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
24327- /*CFI_REL_OFFSET rflags,0*/
24328- pushq_cfi $__KERNEL_CS /* cs */
24329- /*CFI_REL_OFFSET cs,0*/
24330- pushq_cfi \child_rip /* rip */
24331- CFI_REL_OFFSET rip,0
24332- pushq_cfi %rax /* orig rax */
24333- .endm
24334-
24335- .macro UNFAKE_STACK_FRAME
24336- addq $8*6, %rsp
24337- CFI_ADJUST_CFA_OFFSET -(6*8)
24338- .endm
24339-
24340 /*
24341 * initial frame state for interrupts (and exceptions without error code)
24342 */
24343@@ -241,25 +646,26 @@ ENDPROC(native_usergs_sysret64)
24344 /* save partial stack frame */
24345 .macro SAVE_ARGS_IRQ
24346 cld
24347- /* start from rbp in pt_regs and jump over */
24348- movq_cfi rdi, (RDI-RBP)
24349- movq_cfi rsi, (RSI-RBP)
24350- movq_cfi rdx, (RDX-RBP)
24351- movq_cfi rcx, (RCX-RBP)
24352- movq_cfi rax, (RAX-RBP)
24353- movq_cfi r8, (R8-RBP)
24354- movq_cfi r9, (R9-RBP)
24355- movq_cfi r10, (R10-RBP)
24356- movq_cfi r11, (R11-RBP)
24357+ /* start from r15 in pt_regs and jump over */
24358+ movq_cfi rdi, RDI
24359+ movq_cfi rsi, RSI
24360+ movq_cfi rdx, RDX
24361+ movq_cfi rcx, RCX
24362+ movq_cfi rax, RAX
24363+ movq_cfi r8, R8
24364+ movq_cfi r9, R9
24365+ movq_cfi r10, R10
24366+ movq_cfi r11, R11
24367+ movq_cfi r12, R12
24368
24369 /* Save rbp so that we can unwind from get_irq_regs() */
24370- movq_cfi rbp, 0
24371+ movq_cfi rbp, RBP
24372
24373 /* Save previous stack value */
24374 movq %rsp, %rsi
24375
24376- leaq -RBP(%rsp),%rdi /* arg1 for handler */
24377- testl $3, CS-RBP(%rsi)
24378+ movq %rsp,%rdi /* arg1 for handler */
24379+ testb $3, CS(%rsi)
24380 je 1f
24381 SWAPGS
24382 /*
24383@@ -279,6 +685,18 @@ ENDPROC(native_usergs_sysret64)
24384 0x06 /* DW_OP_deref */, \
24385 0x08 /* DW_OP_const1u */, SS+8-RBP, \
24386 0x22 /* DW_OP_plus */
24387+
24388+#ifdef CONFIG_PAX_MEMORY_UDEREF
24389+ testb $3, CS(%rdi)
24390+ jnz 1f
24391+ pax_enter_kernel
24392+ jmp 2f
24393+1: pax_enter_kernel_user
24394+2:
24395+#else
24396+ pax_enter_kernel
24397+#endif
24398+
24399 /* We entered an interrupt context - irqs are off: */
24400 TRACE_IRQS_OFF
24401 .endm
24402@@ -308,9 +726,52 @@ ENTRY(save_paranoid)
24403 js 1f /* negative -> in kernel */
24404 SWAPGS
24405 xorl %ebx,%ebx
24406-1: ret
24407+1:
24408+#ifdef CONFIG_PAX_MEMORY_UDEREF
24409+ testb $3, CS+8(%rsp)
24410+ jnz 1f
24411+ pax_enter_kernel
24412+ jmp 2f
24413+1: pax_enter_kernel_user
24414+2:
24415+#else
24416+ pax_enter_kernel
24417+#endif
24418+ pax_force_retaddr
24419+ ret
24420 CFI_ENDPROC
24421-END(save_paranoid)
24422+ENDPROC(save_paranoid)
24423+
24424+ENTRY(save_paranoid_nmi)
24425+ XCPT_FRAME 1 RDI+8
24426+ cld
24427+ movq_cfi rdi, RDI+8
24428+ movq_cfi rsi, RSI+8
24429+ movq_cfi rdx, RDX+8
24430+ movq_cfi rcx, RCX+8
24431+ movq_cfi rax, RAX+8
24432+ movq_cfi r8, R8+8
24433+ movq_cfi r9, R9+8
24434+ movq_cfi r10, R10+8
24435+ movq_cfi r11, R11+8
24436+ movq_cfi rbx, RBX+8
24437+ movq_cfi rbp, RBP+8
24438+ movq_cfi r12, R12+8
24439+ movq_cfi r13, R13+8
24440+ movq_cfi r14, R14+8
24441+ movq_cfi r15, R15+8
24442+ movl $1,%ebx
24443+ movl $MSR_GS_BASE,%ecx
24444+ rdmsr
24445+ testl %edx,%edx
24446+ js 1f /* negative -> in kernel */
24447+ SWAPGS
24448+ xorl %ebx,%ebx
24449+1: pax_enter_kernel_nmi
24450+ pax_force_retaddr
24451+ ret
24452+ CFI_ENDPROC
24453+ENDPROC(save_paranoid_nmi)
24454
24455 /*
24456 * A newly forked process directly context switches into this address.
24457@@ -331,7 +792,7 @@ ENTRY(ret_from_fork)
24458
24459 RESTORE_REST
24460
24461- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
24462+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
24463 jz 1f
24464
24465 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
24466@@ -341,15 +802,13 @@ ENTRY(ret_from_fork)
24467 jmp ret_from_sys_call # go to the SYSRET fastpath
24468
24469 1:
24470- subq $REST_SKIP, %rsp # leave space for volatiles
24471- CFI_ADJUST_CFA_OFFSET REST_SKIP
24472 movq %rbp, %rdi
24473 call *%rbx
24474 movl $0, RAX(%rsp)
24475 RESTORE_REST
24476 jmp int_ret_from_sys_call
24477 CFI_ENDPROC
24478-END(ret_from_fork)
24479+ENDPROC(ret_from_fork)
24480
24481 /*
24482 * System call entry. Up to 6 arguments in registers are supported.
24483@@ -386,7 +845,7 @@ END(ret_from_fork)
24484 ENTRY(system_call)
24485 CFI_STARTPROC simple
24486 CFI_SIGNAL_FRAME
24487- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
24488+ CFI_DEF_CFA rsp,0
24489 CFI_REGISTER rip,rcx
24490 /*CFI_REGISTER rflags,r11*/
24491 SWAPGS_UNSAFE_STACK
24492@@ -399,16 +858,23 @@ GLOBAL(system_call_after_swapgs)
24493
24494 movq %rsp,PER_CPU_VAR(old_rsp)
24495 movq PER_CPU_VAR(kernel_stack),%rsp
24496+ SAVE_ARGS 8*6,0
24497+ pax_enter_kernel_user
24498+
24499+#ifdef CONFIG_PAX_RANDKSTACK
24500+ pax_erase_kstack
24501+#endif
24502+
24503 /*
24504 * No need to follow this irqs off/on section - it's straight
24505 * and short:
24506 */
24507 ENABLE_INTERRUPTS(CLBR_NONE)
24508- SAVE_ARGS 8,0
24509 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
24510 movq %rcx,RIP-ARGOFFSET(%rsp)
24511 CFI_REL_OFFSET rip,RIP-ARGOFFSET
24512- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
24513+ GET_THREAD_INFO(%rcx)
24514+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
24515 jnz tracesys
24516 system_call_fastpath:
24517 #if __SYSCALL_MASK == ~0
24518@@ -432,10 +898,13 @@ sysret_check:
24519 LOCKDEP_SYS_EXIT
24520 DISABLE_INTERRUPTS(CLBR_NONE)
24521 TRACE_IRQS_OFF
24522- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
24523+ GET_THREAD_INFO(%rcx)
24524+ movl TI_flags(%rcx),%edx
24525 andl %edi,%edx
24526 jnz sysret_careful
24527 CFI_REMEMBER_STATE
24528+ pax_exit_kernel_user
24529+ pax_erase_kstack
24530 /*
24531 * sysretq will re-enable interrupts:
24532 */
24533@@ -494,6 +963,9 @@ auditsys:
24534 movq %rax,%rsi /* 2nd arg: syscall number */
24535 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
24536 call __audit_syscall_entry
24537+
24538+ pax_erase_kstack
24539+
24540 LOAD_ARGS 0 /* reload call-clobbered registers */
24541 jmp system_call_fastpath
24542
24543@@ -515,7 +987,7 @@ sysret_audit:
24544 /* Do syscall tracing */
24545 tracesys:
24546 #ifdef CONFIG_AUDITSYSCALL
24547- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
24548+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
24549 jz auditsys
24550 #endif
24551 SAVE_REST
24552@@ -523,12 +995,15 @@ tracesys:
24553 FIXUP_TOP_OF_STACK %rdi
24554 movq %rsp,%rdi
24555 call syscall_trace_enter
24556+
24557+ pax_erase_kstack
24558+
24559 /*
24560 * Reload arg registers from stack in case ptrace changed them.
24561 * We don't reload %rax because syscall_trace_enter() returned
24562 * the value it wants us to use in the table lookup.
24563 */
24564- LOAD_ARGS ARGOFFSET, 1
24565+ LOAD_ARGS 1
24566 RESTORE_REST
24567 #if __SYSCALL_MASK == ~0
24568 cmpq $__NR_syscall_max,%rax
24569@@ -558,7 +1033,9 @@ GLOBAL(int_with_check)
24570 andl %edi,%edx
24571 jnz int_careful
24572 andl $~TS_COMPAT,TI_status(%rcx)
24573- jmp retint_swapgs
24574+ pax_exit_kernel_user
24575+ pax_erase_kstack
24576+ jmp retint_swapgs_pax
24577
24578 /* Either reschedule or signal or syscall exit tracking needed. */
24579 /* First do a reschedule test. */
24580@@ -604,7 +1081,7 @@ int_restore_rest:
24581 TRACE_IRQS_OFF
24582 jmp int_with_check
24583 CFI_ENDPROC
24584-END(system_call)
24585+ENDPROC(system_call)
24586
24587 .macro FORK_LIKE func
24588 ENTRY(stub_\func)
24589@@ -617,9 +1094,10 @@ ENTRY(stub_\func)
24590 DEFAULT_FRAME 0 8 /* offset 8: return address */
24591 call sys_\func
24592 RESTORE_TOP_OF_STACK %r11, 8
24593- ret $REST_SKIP /* pop extended registers */
24594+ pax_force_retaddr
24595+ ret
24596 CFI_ENDPROC
24597-END(stub_\func)
24598+ENDPROC(stub_\func)
24599 .endm
24600
24601 .macro FIXED_FRAME label,func
24602@@ -629,9 +1107,10 @@ ENTRY(\label)
24603 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
24604 call \func
24605 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
24606+ pax_force_retaddr
24607 ret
24608 CFI_ENDPROC
24609-END(\label)
24610+ENDPROC(\label)
24611 .endm
24612
24613 FORK_LIKE clone
24614@@ -639,19 +1118,6 @@ END(\label)
24615 FORK_LIKE vfork
24616 FIXED_FRAME stub_iopl, sys_iopl
24617
24618-ENTRY(ptregscall_common)
24619- DEFAULT_FRAME 1 8 /* offset 8: return address */
24620- RESTORE_TOP_OF_STACK %r11, 8
24621- movq_cfi_restore R15+8, r15
24622- movq_cfi_restore R14+8, r14
24623- movq_cfi_restore R13+8, r13
24624- movq_cfi_restore R12+8, r12
24625- movq_cfi_restore RBP+8, rbp
24626- movq_cfi_restore RBX+8, rbx
24627- ret $REST_SKIP /* pop extended registers */
24628- CFI_ENDPROC
24629-END(ptregscall_common)
24630-
24631 ENTRY(stub_execve)
24632 CFI_STARTPROC
24633 addq $8, %rsp
24634@@ -663,7 +1129,7 @@ ENTRY(stub_execve)
24635 RESTORE_REST
24636 jmp int_ret_from_sys_call
24637 CFI_ENDPROC
24638-END(stub_execve)
24639+ENDPROC(stub_execve)
24640
24641 /*
24642 * sigreturn is special because it needs to restore all registers on return.
24643@@ -680,7 +1146,7 @@ ENTRY(stub_rt_sigreturn)
24644 RESTORE_REST
24645 jmp int_ret_from_sys_call
24646 CFI_ENDPROC
24647-END(stub_rt_sigreturn)
24648+ENDPROC(stub_rt_sigreturn)
24649
24650 #ifdef CONFIG_X86_X32_ABI
24651 ENTRY(stub_x32_rt_sigreturn)
24652@@ -694,7 +1160,7 @@ ENTRY(stub_x32_rt_sigreturn)
24653 RESTORE_REST
24654 jmp int_ret_from_sys_call
24655 CFI_ENDPROC
24656-END(stub_x32_rt_sigreturn)
24657+ENDPROC(stub_x32_rt_sigreturn)
24658
24659 ENTRY(stub_x32_execve)
24660 CFI_STARTPROC
24661@@ -708,7 +1174,7 @@ ENTRY(stub_x32_execve)
24662 RESTORE_REST
24663 jmp int_ret_from_sys_call
24664 CFI_ENDPROC
24665-END(stub_x32_execve)
24666+ENDPROC(stub_x32_execve)
24667
24668 #endif
24669
24670@@ -745,7 +1211,7 @@ vector=vector+1
24671 2: jmp common_interrupt
24672 .endr
24673 CFI_ENDPROC
24674-END(irq_entries_start)
24675+ENDPROC(irq_entries_start)
24676
24677 .previous
24678 END(interrupt)
24679@@ -762,8 +1228,8 @@ END(interrupt)
24680 /* 0(%rsp): ~(interrupt number) */
24681 .macro interrupt func
24682 /* reserve pt_regs for scratch regs and rbp */
24683- subq $ORIG_RAX-RBP, %rsp
24684- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
24685+ subq $ORIG_RAX, %rsp
24686+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
24687 SAVE_ARGS_IRQ
24688 call \func
24689 .endm
24690@@ -786,14 +1252,14 @@ ret_from_intr:
24691
24692 /* Restore saved previous stack */
24693 popq %rsi
24694- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
24695- leaq ARGOFFSET-RBP(%rsi), %rsp
24696+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
24697+ movq %rsi, %rsp
24698 CFI_DEF_CFA_REGISTER rsp
24699- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
24700+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
24701
24702 exit_intr:
24703 GET_THREAD_INFO(%rcx)
24704- testl $3,CS-ARGOFFSET(%rsp)
24705+ testb $3,CS-ARGOFFSET(%rsp)
24706 je retint_kernel
24707
24708 /* Interrupt came from user space */
24709@@ -815,12 +1281,35 @@ retint_swapgs: /* return to user-space */
24710 * The iretq could re-enable interrupts:
24711 */
24712 DISABLE_INTERRUPTS(CLBR_ANY)
24713+ pax_exit_kernel_user
24714+retint_swapgs_pax:
24715 TRACE_IRQS_IRETQ
24716 SWAPGS
24717 jmp restore_args
24718
24719 retint_restore_args: /* return to kernel space */
24720 DISABLE_INTERRUPTS(CLBR_ANY)
24721+ pax_exit_kernel
24722+
24723+#if defined(CONFIG_EFI) && defined(CONFIG_PAX_KERNEXEC)
24724+ /* This is a quirk to allow IRQs/NMIs/MCEs during early EFI setup,
24725+ * namely calling EFI runtime services with a phys mapping. We're
24726+ * starting off with NOPs and patch in the real instrumentation
24727+ * (BTS/OR) before starting any userland process; even before starting
24728+ * up the APs.
24729+ */
24730+ .pushsection .altinstr_replacement, "a"
24731+ 601: pax_force_retaddr (RIP-ARGOFFSET)
24732+ 602:
24733+ .popsection
24734+ 603: .fill 602b-601b, 1, 0x90
24735+ .pushsection .altinstructions, "a"
24736+ altinstruction_entry 603b, 601b, X86_FEATURE_ALWAYS, 602b-601b, 602b-601b
24737+ .popsection
24738+#else
24739+ pax_force_retaddr (RIP-ARGOFFSET)
24740+#endif
24741+
24742 /*
24743 * The iretq could re-enable interrupts:
24744 */
24745@@ -920,7 +1409,7 @@ ENTRY(retint_kernel)
24746 jmp exit_intr
24747 #endif
24748 CFI_ENDPROC
24749-END(common_interrupt)
24750+ENDPROC(common_interrupt)
24751
24752 /*
24753 * APIC interrupts.
24754@@ -934,7 +1423,7 @@ ENTRY(\sym)
24755 interrupt \do_sym
24756 jmp ret_from_intr
24757 CFI_ENDPROC
24758-END(\sym)
24759+ENDPROC(\sym)
24760 .endm
24761
24762 #ifdef CONFIG_TRACING
24763@@ -1007,7 +1496,7 @@ apicinterrupt IRQ_WORK_VECTOR \
24764 /*
24765 * Exception entry points.
24766 */
24767-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
24768+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
24769
24770 .macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1
24771 ENTRY(\sym)
24772@@ -1058,6 +1547,12 @@ ENTRY(\sym)
24773 .endif
24774
24775 .if \shift_ist != -1
24776+#ifdef CONFIG_SMP
24777+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
24778+ lea init_tss(%r13), %r13
24779+#else
24780+ lea init_tss(%rip), %r13
24781+#endif
24782 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\shift_ist)
24783 .endif
24784
24785@@ -1074,7 +1569,7 @@ ENTRY(\sym)
24786 .endif
24787
24788 CFI_ENDPROC
24789-END(\sym)
24790+ENDPROC(\sym)
24791 .endm
24792
24793 #ifdef CONFIG_TRACING
24794@@ -1115,9 +1610,10 @@ gs_change:
24795 2: mfence /* workaround */
24796 SWAPGS
24797 popfq_cfi
24798+ pax_force_retaddr
24799 ret
24800 CFI_ENDPROC
24801-END(native_load_gs_index)
24802+ENDPROC(native_load_gs_index)
24803
24804 _ASM_EXTABLE(gs_change,bad_gs)
24805 .section .fixup,"ax"
24806@@ -1145,9 +1641,10 @@ ENTRY(do_softirq_own_stack)
24807 CFI_DEF_CFA_REGISTER rsp
24808 CFI_ADJUST_CFA_OFFSET -8
24809 decl PER_CPU_VAR(irq_count)
24810+ pax_force_retaddr
24811 ret
24812 CFI_ENDPROC
24813-END(do_softirq_own_stack)
24814+ENDPROC(do_softirq_own_stack)
24815
24816 #ifdef CONFIG_XEN
24817 idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
24818@@ -1185,7 +1682,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24819 decl PER_CPU_VAR(irq_count)
24820 jmp error_exit
24821 CFI_ENDPROC
24822-END(xen_do_hypervisor_callback)
24823+ENDPROC(xen_do_hypervisor_callback)
24824
24825 /*
24826 * Hypervisor uses this for application faults while it executes.
24827@@ -1244,7 +1741,7 @@ ENTRY(xen_failsafe_callback)
24828 SAVE_ALL
24829 jmp error_exit
24830 CFI_ENDPROC
24831-END(xen_failsafe_callback)
24832+ENDPROC(xen_failsafe_callback)
24833
24834 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24835 xen_hvm_callback_vector xen_evtchn_do_upcall
24836@@ -1291,18 +1788,33 @@ ENTRY(paranoid_exit)
24837 DEFAULT_FRAME
24838 DISABLE_INTERRUPTS(CLBR_NONE)
24839 TRACE_IRQS_OFF_DEBUG
24840- testl %ebx,%ebx /* swapgs needed? */
24841+ testl $1,%ebx /* swapgs needed? */
24842 jnz paranoid_restore
24843- testl $3,CS(%rsp)
24844+ testb $3,CS(%rsp)
24845 jnz paranoid_userspace
24846+#ifdef CONFIG_PAX_MEMORY_UDEREF
24847+ pax_exit_kernel
24848+ TRACE_IRQS_IRETQ 0
24849+ SWAPGS_UNSAFE_STACK
24850+ RESTORE_ALL 8
24851+ pax_force_retaddr_bts
24852+ jmp irq_return
24853+#endif
24854 paranoid_swapgs:
24855+#ifdef CONFIG_PAX_MEMORY_UDEREF
24856+ pax_exit_kernel_user
24857+#else
24858+ pax_exit_kernel
24859+#endif
24860 TRACE_IRQS_IRETQ 0
24861 SWAPGS_UNSAFE_STACK
24862 RESTORE_ALL 8
24863 jmp irq_return
24864 paranoid_restore:
24865+ pax_exit_kernel
24866 TRACE_IRQS_IRETQ_DEBUG 0
24867 RESTORE_ALL 8
24868+ pax_force_retaddr_bts
24869 jmp irq_return
24870 paranoid_userspace:
24871 GET_THREAD_INFO(%rcx)
24872@@ -1331,7 +1843,7 @@ paranoid_schedule:
24873 TRACE_IRQS_OFF
24874 jmp paranoid_userspace
24875 CFI_ENDPROC
24876-END(paranoid_exit)
24877+ENDPROC(paranoid_exit)
24878
24879 /*
24880 * Exception entry point. This expects an error code/orig_rax on the stack.
24881@@ -1358,12 +1870,23 @@ ENTRY(error_entry)
24882 movq %r14, R14+8(%rsp)
24883 movq %r15, R15+8(%rsp)
24884 xorl %ebx,%ebx
24885- testl $3,CS+8(%rsp)
24886+ testb $3,CS+8(%rsp)
24887 je error_kernelspace
24888 error_swapgs:
24889 SWAPGS
24890 error_sti:
24891+#ifdef CONFIG_PAX_MEMORY_UDEREF
24892+ testb $3, CS+8(%rsp)
24893+ jnz 1f
24894+ pax_enter_kernel
24895+ jmp 2f
24896+1: pax_enter_kernel_user
24897+2:
24898+#else
24899+ pax_enter_kernel
24900+#endif
24901 TRACE_IRQS_OFF
24902+ pax_force_retaddr
24903 ret
24904
24905 /*
24906@@ -1398,7 +1921,7 @@ error_bad_iret:
24907 decl %ebx /* Return to usergs */
24908 jmp error_sti
24909 CFI_ENDPROC
24910-END(error_entry)
24911+ENDPROC(error_entry)
24912
24913
24914 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24915@@ -1409,7 +1932,7 @@ ENTRY(error_exit)
24916 DISABLE_INTERRUPTS(CLBR_NONE)
24917 TRACE_IRQS_OFF
24918 GET_THREAD_INFO(%rcx)
24919- testl %eax,%eax
24920+ testl $1,%eax
24921 jne retint_kernel
24922 LOCKDEP_SYS_EXIT_IRQ
24923 movl TI_flags(%rcx),%edx
24924@@ -1418,7 +1941,7 @@ ENTRY(error_exit)
24925 jnz retint_careful
24926 jmp retint_swapgs
24927 CFI_ENDPROC
24928-END(error_exit)
24929+ENDPROC(error_exit)
24930
24931 /*
24932 * Test if a given stack is an NMI stack or not.
24933@@ -1476,9 +1999,11 @@ ENTRY(nmi)
24934 * If %cs was not the kernel segment, then the NMI triggered in user
24935 * space, which means it is definitely not nested.
24936 */
24937+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24938+ je 1f
24939 cmpl $__KERNEL_CS, 16(%rsp)
24940 jne first_nmi
24941-
24942+1:
24943 /*
24944 * Check the special variable on the stack to see if NMIs are
24945 * executing.
24946@@ -1512,8 +2037,7 @@ nested_nmi:
24947
24948 1:
24949 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24950- leaq -1*8(%rsp), %rdx
24951- movq %rdx, %rsp
24952+ subq $8, %rsp
24953 CFI_ADJUST_CFA_OFFSET 1*8
24954 leaq -10*8(%rsp), %rdx
24955 pushq_cfi $__KERNEL_DS
24956@@ -1531,6 +2055,7 @@ nested_nmi_out:
24957 CFI_RESTORE rdx
24958
24959 /* No need to check faults here */
24960+# pax_force_retaddr_bts
24961 INTERRUPT_RETURN
24962
24963 CFI_RESTORE_STATE
24964@@ -1627,13 +2152,13 @@ end_repeat_nmi:
24965 subq $ORIG_RAX-R15, %rsp
24966 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24967 /*
24968- * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24969+ * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24970 * as we should not be calling schedule in NMI context.
24971 * Even with normal interrupts enabled. An NMI should not be
24972 * setting NEED_RESCHED or anything that normal interrupts and
24973 * exceptions might do.
24974 */
24975- call save_paranoid
24976+ call save_paranoid_nmi
24977 DEFAULT_FRAME 0
24978
24979 /*
24980@@ -1643,9 +2168,9 @@ end_repeat_nmi:
24981 * NMI itself takes a page fault, the page fault that was preempted
24982 * will read the information from the NMI page fault and not the
24983 * origin fault. Save it off and restore it if it changes.
24984- * Use the r12 callee-saved register.
24985+ * Use the r13 callee-saved register.
24986 */
24987- movq %cr2, %r12
24988+ movq %cr2, %r13
24989
24990 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24991 movq %rsp,%rdi
24992@@ -1654,29 +2179,34 @@ end_repeat_nmi:
24993
24994 /* Did the NMI take a page fault? Restore cr2 if it did */
24995 movq %cr2, %rcx
24996- cmpq %rcx, %r12
24997+ cmpq %rcx, %r13
24998 je 1f
24999- movq %r12, %cr2
25000+ movq %r13, %cr2
25001 1:
25002
25003- testl %ebx,%ebx /* swapgs needed? */
25004+ testl $1,%ebx /* swapgs needed? */
25005 jnz nmi_restore
25006 nmi_swapgs:
25007 SWAPGS_UNSAFE_STACK
25008 nmi_restore:
25009+ pax_exit_kernel_nmi
25010 /* Pop the extra iret frame at once */
25011 RESTORE_ALL 6*8
25012+ testb $3, 8(%rsp)
25013+ jnz 1f
25014+ pax_force_retaddr_bts
25015+1:
25016
25017 /* Clear the NMI executing stack variable */
25018 movq $0, 5*8(%rsp)
25019 jmp irq_return
25020 CFI_ENDPROC
25021-END(nmi)
25022+ENDPROC(nmi)
25023
25024 ENTRY(ignore_sysret)
25025 CFI_STARTPROC
25026 mov $-ENOSYS,%eax
25027 sysret
25028 CFI_ENDPROC
25029-END(ignore_sysret)
25030+ENDPROC(ignore_sysret)
25031
25032diff --git a/arch/x86/kernel/espfix_64.c b/arch/x86/kernel/espfix_64.c
25033index 94d857f..bf1f0bf 100644
25034--- a/arch/x86/kernel/espfix_64.c
25035+++ b/arch/x86/kernel/espfix_64.c
25036@@ -197,7 +197,7 @@ void init_espfix_ap(void)
25037 set_pte(&pte_p[n*PTE_STRIDE], pte);
25038
25039 /* Job is done for this CPU and any CPU which shares this page */
25040- ACCESS_ONCE(espfix_pages[page]) = stack_page;
25041+ ACCESS_ONCE_RW(espfix_pages[page]) = stack_page;
25042
25043 unlock_done:
25044 mutex_unlock(&espfix_init_mutex);
25045diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
25046index 3386dc9..28bdf81 100644
25047--- a/arch/x86/kernel/ftrace.c
25048+++ b/arch/x86/kernel/ftrace.c
25049@@ -88,7 +88,7 @@ static unsigned long text_ip_addr(unsigned long ip)
25050 * kernel identity mapping to modify code.
25051 */
25052 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
25053- ip = (unsigned long)__va(__pa_symbol(ip));
25054+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
25055
25056 return ip;
25057 }
25058@@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
25059 {
25060 unsigned char replaced[MCOUNT_INSN_SIZE];
25061
25062+ ip = ktla_ktva(ip);
25063+
25064 /*
25065 * Note: Due to modules and __init, code can
25066 * disappear and change, we need to protect against faulting
25067@@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
25068 unsigned char old[MCOUNT_INSN_SIZE];
25069 int ret;
25070
25071- memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
25072+ memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
25073
25074 ftrace_update_func = ip;
25075 /* Make sure the breakpoints see the ftrace_update_func update */
25076@@ -310,7 +312,7 @@ static int add_break(unsigned long ip, const char *old)
25077 unsigned char replaced[MCOUNT_INSN_SIZE];
25078 unsigned char brk = BREAKPOINT_INSTRUCTION;
25079
25080- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
25081+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
25082 return -EFAULT;
25083
25084 /* Make sure it is what we expect it to be */
25085diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
25086index eda1a86..8f6df48 100644
25087--- a/arch/x86/kernel/head64.c
25088+++ b/arch/x86/kernel/head64.c
25089@@ -67,12 +67,12 @@ again:
25090 pgd = *pgd_p;
25091
25092 /*
25093- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
25094- * critical -- __PAGE_OFFSET would point us back into the dynamic
25095+ * The use of __early_va rather than __va here is critical:
25096+ * __va would point us back into the dynamic
25097 * range and we might end up looping forever...
25098 */
25099 if (pgd)
25100- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
25101+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
25102 else {
25103 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
25104 reset_early_page_tables();
25105@@ -82,13 +82,13 @@ again:
25106 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
25107 for (i = 0; i < PTRS_PER_PUD; i++)
25108 pud_p[i] = 0;
25109- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
25110+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
25111 }
25112 pud_p += pud_index(address);
25113 pud = *pud_p;
25114
25115 if (pud)
25116- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
25117+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
25118 else {
25119 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
25120 reset_early_page_tables();
25121@@ -98,7 +98,7 @@ again:
25122 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
25123 for (i = 0; i < PTRS_PER_PMD; i++)
25124 pmd_p[i] = 0;
25125- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
25126+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
25127 }
25128 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
25129 pmd_p[pmd_index(address)] = pmd;
25130@@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
25131 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
25132 early_printk("Kernel alive\n");
25133
25134- clear_page(init_level4_pgt);
25135 /* set init_level4_pgt kernel high mapping*/
25136 init_level4_pgt[511] = early_level4_pgt[511];
25137
25138diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
25139index f36bd42..0ab4474 100644
25140--- a/arch/x86/kernel/head_32.S
25141+++ b/arch/x86/kernel/head_32.S
25142@@ -26,6 +26,12 @@
25143 /* Physical address */
25144 #define pa(X) ((X) - __PAGE_OFFSET)
25145
25146+#ifdef CONFIG_PAX_KERNEXEC
25147+#define ta(X) (X)
25148+#else
25149+#define ta(X) ((X) - __PAGE_OFFSET)
25150+#endif
25151+
25152 /*
25153 * References to members of the new_cpu_data structure.
25154 */
25155@@ -55,11 +61,7 @@
25156 * and small than max_low_pfn, otherwise will waste some page table entries
25157 */
25158
25159-#if PTRS_PER_PMD > 1
25160-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
25161-#else
25162-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
25163-#endif
25164+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
25165
25166 /* Number of possible pages in the lowmem region */
25167 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
25168@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
25169 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
25170
25171 /*
25172+ * Real beginning of normal "text" segment
25173+ */
25174+ENTRY(stext)
25175+ENTRY(_stext)
25176+
25177+/*
25178 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
25179 * %esi points to the real-mode code as a 32-bit pointer.
25180 * CS and DS must be 4 GB flat segments, but we don't depend on
25181@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
25182 * can.
25183 */
25184 __HEAD
25185+
25186+#ifdef CONFIG_PAX_KERNEXEC
25187+ jmp startup_32
25188+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
25189+.fill PAGE_SIZE-5,1,0xcc
25190+#endif
25191+
25192 ENTRY(startup_32)
25193 movl pa(stack_start),%ecx
25194
25195@@ -106,6 +121,59 @@ ENTRY(startup_32)
25196 2:
25197 leal -__PAGE_OFFSET(%ecx),%esp
25198
25199+#ifdef CONFIG_SMP
25200+ movl $pa(cpu_gdt_table),%edi
25201+ movl $__per_cpu_load,%eax
25202+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
25203+ rorl $16,%eax
25204+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
25205+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
25206+ movl $__per_cpu_end - 1,%eax
25207+ subl $__per_cpu_start,%eax
25208+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
25209+#endif
25210+
25211+#ifdef CONFIG_PAX_MEMORY_UDEREF
25212+ movl $NR_CPUS,%ecx
25213+ movl $pa(cpu_gdt_table),%edi
25214+1:
25215+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
25216+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
25217+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
25218+ addl $PAGE_SIZE_asm,%edi
25219+ loop 1b
25220+#endif
25221+
25222+#ifdef CONFIG_PAX_KERNEXEC
25223+ movl $pa(boot_gdt),%edi
25224+ movl $__LOAD_PHYSICAL_ADDR,%eax
25225+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
25226+ rorl $16,%eax
25227+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
25228+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
25229+ rorl $16,%eax
25230+
25231+ ljmp $(__BOOT_CS),$1f
25232+1:
25233+
25234+ movl $NR_CPUS,%ecx
25235+ movl $pa(cpu_gdt_table),%edi
25236+ addl $__PAGE_OFFSET,%eax
25237+1:
25238+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
25239+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
25240+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
25241+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
25242+ rorl $16,%eax
25243+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
25244+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
25245+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
25246+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
25247+ rorl $16,%eax
25248+ addl $PAGE_SIZE_asm,%edi
25249+ loop 1b
25250+#endif
25251+
25252 /*
25253 * Clear BSS first so that there are no surprises...
25254 */
25255@@ -201,8 +269,11 @@ ENTRY(startup_32)
25256 movl %eax, pa(max_pfn_mapped)
25257
25258 /* Do early initialization of the fixmap area */
25259- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
25260- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
25261+#ifdef CONFIG_COMPAT_VDSO
25262+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
25263+#else
25264+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
25265+#endif
25266 #else /* Not PAE */
25267
25268 page_pde_offset = (__PAGE_OFFSET >> 20);
25269@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
25270 movl %eax, pa(max_pfn_mapped)
25271
25272 /* Do early initialization of the fixmap area */
25273- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
25274- movl %eax,pa(initial_page_table+0xffc)
25275+#ifdef CONFIG_COMPAT_VDSO
25276+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
25277+#else
25278+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
25279+#endif
25280 #endif
25281
25282 #ifdef CONFIG_PARAVIRT
25283@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
25284 cmpl $num_subarch_entries, %eax
25285 jae bad_subarch
25286
25287- movl pa(subarch_entries)(,%eax,4), %eax
25288- subl $__PAGE_OFFSET, %eax
25289- jmp *%eax
25290+ jmp *pa(subarch_entries)(,%eax,4)
25291
25292 bad_subarch:
25293 WEAK(lguest_entry)
25294@@ -261,10 +333,10 @@ WEAK(xen_entry)
25295 __INITDATA
25296
25297 subarch_entries:
25298- .long default_entry /* normal x86/PC */
25299- .long lguest_entry /* lguest hypervisor */
25300- .long xen_entry /* Xen hypervisor */
25301- .long default_entry /* Moorestown MID */
25302+ .long ta(default_entry) /* normal x86/PC */
25303+ .long ta(lguest_entry) /* lguest hypervisor */
25304+ .long ta(xen_entry) /* Xen hypervisor */
25305+ .long ta(default_entry) /* Moorestown MID */
25306 num_subarch_entries = (. - subarch_entries) / 4
25307 .previous
25308 #else
25309@@ -354,6 +426,7 @@ default_entry:
25310 movl pa(mmu_cr4_features),%eax
25311 movl %eax,%cr4
25312
25313+#ifdef CONFIG_X86_PAE
25314 testb $X86_CR4_PAE, %al # check if PAE is enabled
25315 jz enable_paging
25316
25317@@ -382,6 +455,9 @@ default_entry:
25318 /* Make changes effective */
25319 wrmsr
25320
25321+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
25322+#endif
25323+
25324 enable_paging:
25325
25326 /*
25327@@ -449,14 +525,20 @@ is486:
25328 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
25329 movl %eax,%ss # after changing gdt.
25330
25331- movl $(__USER_DS),%eax # DS/ES contains default USER segment
25332+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
25333 movl %eax,%ds
25334 movl %eax,%es
25335
25336 movl $(__KERNEL_PERCPU), %eax
25337 movl %eax,%fs # set this cpu's percpu
25338
25339+#ifdef CONFIG_CC_STACKPROTECTOR
25340 movl $(__KERNEL_STACK_CANARY),%eax
25341+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
25342+ movl $(__USER_DS),%eax
25343+#else
25344+ xorl %eax,%eax
25345+#endif
25346 movl %eax,%gs
25347
25348 xorl %eax,%eax # Clear LDT
25349@@ -512,8 +594,11 @@ setup_once:
25350 * relocation. Manually set base address in stack canary
25351 * segment descriptor.
25352 */
25353- movl $gdt_page,%eax
25354+ movl $cpu_gdt_table,%eax
25355 movl $stack_canary,%ecx
25356+#ifdef CONFIG_SMP
25357+ addl $__per_cpu_load,%ecx
25358+#endif
25359 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
25360 shrl $16, %ecx
25361 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
25362@@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
25363 cmpl $2,(%esp) # X86_TRAP_NMI
25364 je is_nmi # Ignore NMI
25365
25366- cmpl $2,%ss:early_recursion_flag
25367+ cmpl $1,%ss:early_recursion_flag
25368 je hlt_loop
25369 incl %ss:early_recursion_flag
25370
25371@@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
25372 pushl (20+6*4)(%esp) /* trapno */
25373 pushl $fault_msg
25374 call printk
25375-#endif
25376 call dump_stack
25377+#endif
25378 hlt_loop:
25379 hlt
25380 jmp hlt_loop
25381@@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
25382 /* This is the default interrupt "handler" :-) */
25383 ALIGN
25384 ignore_int:
25385- cld
25386 #ifdef CONFIG_PRINTK
25387+ cmpl $2,%ss:early_recursion_flag
25388+ je hlt_loop
25389+ incl %ss:early_recursion_flag
25390+ cld
25391 pushl %eax
25392 pushl %ecx
25393 pushl %edx
25394@@ -617,9 +705,6 @@ ignore_int:
25395 movl $(__KERNEL_DS),%eax
25396 movl %eax,%ds
25397 movl %eax,%es
25398- cmpl $2,early_recursion_flag
25399- je hlt_loop
25400- incl early_recursion_flag
25401 pushl 16(%esp)
25402 pushl 24(%esp)
25403 pushl 32(%esp)
25404@@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
25405 /*
25406 * BSS section
25407 */
25408-__PAGE_ALIGNED_BSS
25409- .align PAGE_SIZE
25410 #ifdef CONFIG_X86_PAE
25411+.section .initial_pg_pmd,"a",@progbits
25412 initial_pg_pmd:
25413 .fill 1024*KPMDS,4,0
25414 #else
25415+.section .initial_page_table,"a",@progbits
25416 ENTRY(initial_page_table)
25417 .fill 1024,4,0
25418 #endif
25419+.section .initial_pg_fixmap,"a",@progbits
25420 initial_pg_fixmap:
25421 .fill 1024,4,0
25422+.section .empty_zero_page,"a",@progbits
25423 ENTRY(empty_zero_page)
25424 .fill 4096,1,0
25425+.section .swapper_pg_dir,"a",@progbits
25426 ENTRY(swapper_pg_dir)
25427+#ifdef CONFIG_X86_PAE
25428+ .fill 4,8,0
25429+#else
25430 .fill 1024,4,0
25431+#endif
25432
25433 /*
25434 * This starts the data section.
25435 */
25436 #ifdef CONFIG_X86_PAE
25437-__PAGE_ALIGNED_DATA
25438- /* Page-aligned for the benefit of paravirt? */
25439- .align PAGE_SIZE
25440+.section .initial_page_table,"a",@progbits
25441 ENTRY(initial_page_table)
25442 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
25443 # if KPMDS == 3
25444@@ -694,12 +784,20 @@ ENTRY(initial_page_table)
25445 # error "Kernel PMDs should be 1, 2 or 3"
25446 # endif
25447 .align PAGE_SIZE /* needs to be page-sized too */
25448+
25449+#ifdef CONFIG_PAX_PER_CPU_PGD
25450+ENTRY(cpu_pgd)
25451+ .rept 2*NR_CPUS
25452+ .fill 4,8,0
25453+ .endr
25454+#endif
25455+
25456 #endif
25457
25458 .data
25459 .balign 4
25460 ENTRY(stack_start)
25461- .long init_thread_union+THREAD_SIZE
25462+ .long init_thread_union+THREAD_SIZE-8
25463
25464 __INITRODATA
25465 int_msg:
25466@@ -727,7 +825,7 @@ fault_msg:
25467 * segment size, and 32-bit linear address value:
25468 */
25469
25470- .data
25471+.section .rodata,"a",@progbits
25472 .globl boot_gdt_descr
25473 .globl idt_descr
25474
25475@@ -736,7 +834,7 @@ fault_msg:
25476 .word 0 # 32 bit align gdt_desc.address
25477 boot_gdt_descr:
25478 .word __BOOT_DS+7
25479- .long boot_gdt - __PAGE_OFFSET
25480+ .long pa(boot_gdt)
25481
25482 .word 0 # 32-bit align idt_desc.address
25483 idt_descr:
25484@@ -747,7 +845,7 @@ idt_descr:
25485 .word 0 # 32 bit align gdt_desc.address
25486 ENTRY(early_gdt_descr)
25487 .word GDT_ENTRIES*8-1
25488- .long gdt_page /* Overwritten for secondary CPUs */
25489+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
25490
25491 /*
25492 * The boot_gdt must mirror the equivalent in setup.S and is
25493@@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
25494 .align L1_CACHE_BYTES
25495 ENTRY(boot_gdt)
25496 .fill GDT_ENTRY_BOOT_CS,8,0
25497- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
25498- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
25499+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
25500+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
25501+
25502+ .align PAGE_SIZE_asm
25503+ENTRY(cpu_gdt_table)
25504+ .rept NR_CPUS
25505+ .quad 0x0000000000000000 /* NULL descriptor */
25506+ .quad 0x0000000000000000 /* 0x0b reserved */
25507+ .quad 0x0000000000000000 /* 0x13 reserved */
25508+ .quad 0x0000000000000000 /* 0x1b reserved */
25509+
25510+#ifdef CONFIG_PAX_KERNEXEC
25511+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
25512+#else
25513+ .quad 0x0000000000000000 /* 0x20 unused */
25514+#endif
25515+
25516+ .quad 0x0000000000000000 /* 0x28 unused */
25517+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
25518+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
25519+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
25520+ .quad 0x0000000000000000 /* 0x4b reserved */
25521+ .quad 0x0000000000000000 /* 0x53 reserved */
25522+ .quad 0x0000000000000000 /* 0x5b reserved */
25523+
25524+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
25525+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
25526+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
25527+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
25528+
25529+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
25530+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
25531+
25532+ /*
25533+ * Segments used for calling PnP BIOS have byte granularity.
25534+ * The code segments and data segments have fixed 64k limits,
25535+ * the transfer segment sizes are set at run time.
25536+ */
25537+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
25538+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
25539+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
25540+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
25541+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
25542+
25543+ /*
25544+ * The APM segments have byte granularity and their bases
25545+ * are set at run time. All have 64k limits.
25546+ */
25547+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
25548+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
25549+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
25550+
25551+ .quad 0x00c093000000ffff /* 0xd0 - ESPFIX SS */
25552+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
25553+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
25554+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
25555+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
25556+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
25557+
25558+ /* Be sure this is zeroed to avoid false validations in Xen */
25559+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
25560+ .endr
25561diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
25562index a468c0a..8b5a879 100644
25563--- a/arch/x86/kernel/head_64.S
25564+++ b/arch/x86/kernel/head_64.S
25565@@ -20,6 +20,8 @@
25566 #include <asm/processor-flags.h>
25567 #include <asm/percpu.h>
25568 #include <asm/nops.h>
25569+#include <asm/cpufeature.h>
25570+#include <asm/alternative-asm.h>
25571
25572 #ifdef CONFIG_PARAVIRT
25573 #include <asm/asm-offsets.h>
25574@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
25575 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
25576 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
25577 L3_START_KERNEL = pud_index(__START_KERNEL_map)
25578+L4_VMALLOC_START = pgd_index(VMALLOC_START)
25579+L3_VMALLOC_START = pud_index(VMALLOC_START)
25580+L4_VMALLOC_END = pgd_index(VMALLOC_END)
25581+L3_VMALLOC_END = pud_index(VMALLOC_END)
25582+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
25583+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
25584
25585 .text
25586 __HEAD
25587@@ -89,11 +97,24 @@ startup_64:
25588 * Fixup the physical addresses in the page table
25589 */
25590 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
25591+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
25592+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
25593+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
25594+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
25595+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
25596
25597- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
25598- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
25599+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
25600+#ifndef CONFIG_XEN
25601+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
25602+#endif
25603+
25604+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
25605+
25606+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
25607+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
25608
25609 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
25610+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
25611
25612 /*
25613 * Set up the identity mapping for the switchover. These
25614@@ -174,11 +195,12 @@ ENTRY(secondary_startup_64)
25615 * after the boot processor executes this code.
25616 */
25617
25618+ orq $-1, %rbp
25619 movq $(init_level4_pgt - __START_KERNEL_map), %rax
25620 1:
25621
25622- /* Enable PAE mode and PGE */
25623- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
25624+ /* Enable PAE mode and PSE/PGE */
25625+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
25626 movq %rcx, %cr4
25627
25628 /* Setup early boot stage 4 level pagetables. */
25629@@ -199,10 +221,19 @@ ENTRY(secondary_startup_64)
25630 movl $MSR_EFER, %ecx
25631 rdmsr
25632 btsl $_EFER_SCE, %eax /* Enable System Call */
25633- btl $20,%edi /* No Execute supported? */
25634+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
25635 jnc 1f
25636 btsl $_EFER_NX, %eax
25637+ cmpq $-1, %rbp
25638+ je 1f
25639 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
25640+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
25641+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
25642+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
25643+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
25644+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
25645+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
25646+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
25647 1: wrmsr /* Make changes effective */
25648
25649 /* Setup cr0 */
25650@@ -282,6 +313,7 @@ ENTRY(secondary_startup_64)
25651 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
25652 * address given in m16:64.
25653 */
25654+ pax_set_fptr_mask
25655 movq initial_code(%rip),%rax
25656 pushq $0 # fake return address to stop unwinder
25657 pushq $__KERNEL_CS # set correct cs
25658@@ -313,7 +345,7 @@ ENDPROC(start_cpu0)
25659 .quad INIT_PER_CPU_VAR(irq_stack_union)
25660
25661 GLOBAL(stack_start)
25662- .quad init_thread_union+THREAD_SIZE-8
25663+ .quad init_thread_union+THREAD_SIZE-16
25664 .word 0
25665 __FINITDATA
25666
25667@@ -391,7 +423,7 @@ ENTRY(early_idt_handler)
25668 call dump_stack
25669 #ifdef CONFIG_KALLSYMS
25670 leaq early_idt_ripmsg(%rip),%rdi
25671- movq 40(%rsp),%rsi # %rip again
25672+ movq 88(%rsp),%rsi # %rip again
25673 call __print_symbol
25674 #endif
25675 #endif /* EARLY_PRINTK */
25676@@ -420,6 +452,7 @@ ENDPROC(early_idt_handler)
25677 early_recursion_flag:
25678 .long 0
25679
25680+ .section .rodata,"a",@progbits
25681 #ifdef CONFIG_EARLY_PRINTK
25682 early_idt_msg:
25683 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
25684@@ -447,29 +480,52 @@ NEXT_PAGE(early_level4_pgt)
25685 NEXT_PAGE(early_dynamic_pgts)
25686 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
25687
25688- .data
25689+ .section .rodata,"a",@progbits
25690
25691-#ifndef CONFIG_XEN
25692 NEXT_PAGE(init_level4_pgt)
25693- .fill 512,8,0
25694-#else
25695-NEXT_PAGE(init_level4_pgt)
25696- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25697 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
25698 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25699+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
25700+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
25701+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
25702+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
25703+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
25704+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25705 .org init_level4_pgt + L4_START_KERNEL*8, 0
25706 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
25707 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
25708
25709+#ifdef CONFIG_PAX_PER_CPU_PGD
25710+NEXT_PAGE(cpu_pgd)
25711+ .rept 2*NR_CPUS
25712+ .fill 512,8,0
25713+ .endr
25714+#endif
25715+
25716 NEXT_PAGE(level3_ident_pgt)
25717 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25718+#ifdef CONFIG_XEN
25719 .fill 511, 8, 0
25720+#else
25721+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
25722+ .fill 510,8,0
25723+#endif
25724+
25725+NEXT_PAGE(level3_vmalloc_start_pgt)
25726+ .fill 512,8,0
25727+
25728+NEXT_PAGE(level3_vmalloc_end_pgt)
25729+ .fill 512,8,0
25730+
25731+NEXT_PAGE(level3_vmemmap_pgt)
25732+ .fill L3_VMEMMAP_START,8,0
25733+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25734+
25735 NEXT_PAGE(level2_ident_pgt)
25736- /* Since I easily can, map the first 1G.
25737+ /* Since I easily can, map the first 2G.
25738 * Don't set NX because code runs from these pages.
25739 */
25740- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
25741-#endif
25742+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
25743
25744 NEXT_PAGE(level3_kernel_pgt)
25745 .fill L3_START_KERNEL,8,0
25746@@ -477,6 +533,9 @@ NEXT_PAGE(level3_kernel_pgt)
25747 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
25748 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25749
25750+NEXT_PAGE(level2_vmemmap_pgt)
25751+ .fill 512,8,0
25752+
25753 NEXT_PAGE(level2_kernel_pgt)
25754 /*
25755 * 512 MB kernel mapping. We spend a full page on this pagetable
25756@@ -494,28 +553,64 @@ NEXT_PAGE(level2_kernel_pgt)
25757 NEXT_PAGE(level2_fixmap_pgt)
25758 .fill 506,8,0
25759 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25760- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
25761- .fill 5,8,0
25762+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
25763+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
25764+ .fill 4,8,0
25765
25766 NEXT_PAGE(level1_fixmap_pgt)
25767 .fill 512,8,0
25768
25769+NEXT_PAGE(level1_vsyscall_pgt)
25770+ .fill 512,8,0
25771+
25772 #undef PMDS
25773
25774- .data
25775+ .align PAGE_SIZE
25776+ENTRY(cpu_gdt_table)
25777+ .rept NR_CPUS
25778+ .quad 0x0000000000000000 /* NULL descriptor */
25779+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
25780+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
25781+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
25782+ .quad 0x00cffb000000ffff /* __USER32_CS */
25783+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25784+ .quad 0x00affb000000ffff /* __USER_CS */
25785+
25786+#ifdef CONFIG_PAX_KERNEXEC
25787+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25788+#else
25789+ .quad 0x0 /* unused */
25790+#endif
25791+
25792+ .quad 0,0 /* TSS */
25793+ .quad 0,0 /* LDT */
25794+ .quad 0,0,0 /* three TLS descriptors */
25795+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
25796+ /* asm/segment.h:GDT_ENTRIES must match this */
25797+
25798+#ifdef CONFIG_PAX_MEMORY_UDEREF
25799+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25800+#else
25801+ .quad 0x0 /* unused */
25802+#endif
25803+
25804+ /* zero the remaining page */
25805+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25806+ .endr
25807+
25808 .align 16
25809 .globl early_gdt_descr
25810 early_gdt_descr:
25811 .word GDT_ENTRIES*8-1
25812 early_gdt_descr_base:
25813- .quad INIT_PER_CPU_VAR(gdt_page)
25814+ .quad cpu_gdt_table
25815
25816 ENTRY(phys_base)
25817 /* This must match the first entry in level2_kernel_pgt */
25818 .quad 0x0000000000000000
25819
25820 #include "../../x86/xen/xen-head.S"
25821-
25822- __PAGE_ALIGNED_BSS
25823+
25824+ .section .rodata,"a",@progbits
25825 NEXT_PAGE(empty_zero_page)
25826 .skip PAGE_SIZE
25827diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25828index 05fd74f..c3548b1 100644
25829--- a/arch/x86/kernel/i386_ksyms_32.c
25830+++ b/arch/x86/kernel/i386_ksyms_32.c
25831@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25832 EXPORT_SYMBOL(cmpxchg8b_emu);
25833 #endif
25834
25835+EXPORT_SYMBOL_GPL(cpu_gdt_table);
25836+
25837 /* Networking helper routines. */
25838 EXPORT_SYMBOL(csum_partial_copy_generic);
25839+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25840+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25841
25842 EXPORT_SYMBOL(__get_user_1);
25843 EXPORT_SYMBOL(__get_user_2);
25844@@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25845 EXPORT_SYMBOL(___preempt_schedule_context);
25846 #endif
25847 #endif
25848+
25849+#ifdef CONFIG_PAX_KERNEXEC
25850+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25851+#endif
25852+
25853+#ifdef CONFIG_PAX_PER_CPU_PGD
25854+EXPORT_SYMBOL(cpu_pgd);
25855+#endif
25856diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25857index a9a4229..6f4d476 100644
25858--- a/arch/x86/kernel/i387.c
25859+++ b/arch/x86/kernel/i387.c
25860@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25861 static inline bool interrupted_user_mode(void)
25862 {
25863 struct pt_regs *regs = get_irq_regs();
25864- return regs && user_mode_vm(regs);
25865+ return regs && user_mode(regs);
25866 }
25867
25868 /*
25869diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25870index 8af8171..f8c1169 100644
25871--- a/arch/x86/kernel/i8259.c
25872+++ b/arch/x86/kernel/i8259.c
25873@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25874 static void make_8259A_irq(unsigned int irq)
25875 {
25876 disable_irq_nosync(irq);
25877- io_apic_irqs &= ~(1<<irq);
25878+ io_apic_irqs &= ~(1UL<<irq);
25879 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
25880 i8259A_chip.name);
25881 enable_irq(irq);
25882@@ -209,7 +209,7 @@ spurious_8259A_irq:
25883 "spurious 8259A interrupt: IRQ%d.\n", irq);
25884 spurious_irq_mask |= irqmask;
25885 }
25886- atomic_inc(&irq_err_count);
25887+ atomic_inc_unchecked(&irq_err_count);
25888 /*
25889 * Theoretically we do not have to handle this IRQ,
25890 * but in Linux this does not cause problems and is
25891@@ -350,14 +350,16 @@ static void init_8259A(int auto_eoi)
25892 /* (slave's support for AEOI in flat mode is to be investigated) */
25893 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25894
25895+ pax_open_kernel();
25896 if (auto_eoi)
25897 /*
25898 * In AEOI mode we just have to mask the interrupt
25899 * when acking.
25900 */
25901- i8259A_chip.irq_mask_ack = disable_8259A_irq;
25902+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25903 else
25904- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25905+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25906+ pax_close_kernel();
25907
25908 udelay(100); /* wait for 8259A to initialize */
25909
25910diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25911index a979b5b..1d6db75 100644
25912--- a/arch/x86/kernel/io_delay.c
25913+++ b/arch/x86/kernel/io_delay.c
25914@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25915 * Quirk table for systems that misbehave (lock up, etc.) if port
25916 * 0x80 is used:
25917 */
25918-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25919+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25920 {
25921 .callback = dmi_io_delay_0xed_port,
25922 .ident = "Compaq Presario V6000",
25923diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25924index 4ddaf66..49d5c18 100644
25925--- a/arch/x86/kernel/ioport.c
25926+++ b/arch/x86/kernel/ioport.c
25927@@ -6,6 +6,7 @@
25928 #include <linux/sched.h>
25929 #include <linux/kernel.h>
25930 #include <linux/capability.h>
25931+#include <linux/security.h>
25932 #include <linux/errno.h>
25933 #include <linux/types.h>
25934 #include <linux/ioport.h>
25935@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25936 return -EINVAL;
25937 if (turn_on && !capable(CAP_SYS_RAWIO))
25938 return -EPERM;
25939+#ifdef CONFIG_GRKERNSEC_IO
25940+ if (turn_on && grsec_disable_privio) {
25941+ gr_handle_ioperm();
25942+ return -ENODEV;
25943+ }
25944+#endif
25945
25946 /*
25947 * If it's the first ioperm() call in this thread's lifetime, set the
25948@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25949 * because the ->io_bitmap_max value must match the bitmap
25950 * contents:
25951 */
25952- tss = &per_cpu(init_tss, get_cpu());
25953+ tss = init_tss + get_cpu();
25954
25955 if (turn_on)
25956 bitmap_clear(t->io_bitmap_ptr, from, num);
25957@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25958 if (level > old) {
25959 if (!capable(CAP_SYS_RAWIO))
25960 return -EPERM;
25961+#ifdef CONFIG_GRKERNSEC_IO
25962+ if (grsec_disable_privio) {
25963+ gr_handle_iopl();
25964+ return -ENODEV;
25965+ }
25966+#endif
25967 }
25968 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25969 t->iopl = level << 12;
25970diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25971index 922d285..6d20692 100644
25972--- a/arch/x86/kernel/irq.c
25973+++ b/arch/x86/kernel/irq.c
25974@@ -22,7 +22,7 @@
25975 #define CREATE_TRACE_POINTS
25976 #include <asm/trace/irq_vectors.h>
25977
25978-atomic_t irq_err_count;
25979+atomic_unchecked_t irq_err_count;
25980
25981 /* Function pointer for generic interrupt vector handling */
25982 void (*x86_platform_ipi_callback)(void) = NULL;
25983@@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25984 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
25985 seq_printf(p, " Hypervisor callback interrupts\n");
25986 #endif
25987- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25988+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25989 #if defined(CONFIG_X86_IO_APIC)
25990- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25991+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25992 #endif
25993 return 0;
25994 }
25995@@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25996
25997 u64 arch_irq_stat(void)
25998 {
25999- u64 sum = atomic_read(&irq_err_count);
26000+ u64 sum = atomic_read_unchecked(&irq_err_count);
26001 return sum;
26002 }
26003
26004diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
26005index 63ce838..2ea3e06 100644
26006--- a/arch/x86/kernel/irq_32.c
26007+++ b/arch/x86/kernel/irq_32.c
26008@@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
26009
26010 #ifdef CONFIG_DEBUG_STACKOVERFLOW
26011
26012+extern void gr_handle_kernel_exploit(void);
26013+
26014 int sysctl_panic_on_stackoverflow __read_mostly;
26015
26016 /* Debugging check for stack overflow: is there less than 1KB free? */
26017@@ -39,13 +41,14 @@ static int check_stack_overflow(void)
26018 __asm__ __volatile__("andl %%esp,%0" :
26019 "=r" (sp) : "0" (THREAD_SIZE - 1));
26020
26021- return sp < (sizeof(struct thread_info) + STACK_WARN);
26022+ return sp < STACK_WARN;
26023 }
26024
26025 static void print_stack_overflow(void)
26026 {
26027 printk(KERN_WARNING "low stack detected by irq handler\n");
26028 dump_stack();
26029+ gr_handle_kernel_exploit();
26030 if (sysctl_panic_on_stackoverflow)
26031 panic("low stack detected by irq handler - check messages\n");
26032 }
26033@@ -84,10 +87,9 @@ static inline void *current_stack(void)
26034 static inline int
26035 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
26036 {
26037- struct irq_stack *curstk, *irqstk;
26038+ struct irq_stack *irqstk;
26039 u32 *isp, *prev_esp, arg1, arg2;
26040
26041- curstk = (struct irq_stack *) current_stack();
26042 irqstk = __this_cpu_read(hardirq_stack);
26043
26044 /*
26045@@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
26046 * handler) we can't do that and just have to keep using the
26047 * current stack (which is the irq stack already after all)
26048 */
26049- if (unlikely(curstk == irqstk))
26050+ if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
26051 return 0;
26052
26053- isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
26054+ isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
26055
26056 /* Save the next esp at the bottom of the stack */
26057 prev_esp = (u32 *)irqstk;
26058 *prev_esp = current_stack_pointer;
26059
26060+#ifdef CONFIG_PAX_MEMORY_UDEREF
26061+ __set_fs(MAKE_MM_SEG(0));
26062+#endif
26063+
26064 if (unlikely(overflow))
26065 call_on_stack(print_stack_overflow, isp);
26066
26067@@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
26068 : "0" (irq), "1" (desc), "2" (isp),
26069 "D" (desc->handle_irq)
26070 : "memory", "cc", "ecx");
26071+
26072+#ifdef CONFIG_PAX_MEMORY_UDEREF
26073+ __set_fs(current_thread_info()->addr_limit);
26074+#endif
26075+
26076 return 1;
26077 }
26078
26079@@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
26080 */
26081 void irq_ctx_init(int cpu)
26082 {
26083- struct irq_stack *irqstk;
26084-
26085 if (per_cpu(hardirq_stack, cpu))
26086 return;
26087
26088- irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
26089- THREADINFO_GFP,
26090- THREAD_SIZE_ORDER));
26091- per_cpu(hardirq_stack, cpu) = irqstk;
26092-
26093- irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
26094- THREADINFO_GFP,
26095- THREAD_SIZE_ORDER));
26096- per_cpu(softirq_stack, cpu) = irqstk;
26097-
26098- printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
26099- cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
26100+ per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
26101+ per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
26102 }
26103
26104 void do_softirq_own_stack(void)
26105 {
26106- struct thread_info *curstk;
26107 struct irq_stack *irqstk;
26108 u32 *isp, *prev_esp;
26109
26110- curstk = current_stack();
26111 irqstk = __this_cpu_read(softirq_stack);
26112
26113 /* build the stack frame on the softirq stack */
26114@@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
26115 prev_esp = (u32 *)irqstk;
26116 *prev_esp = current_stack_pointer;
26117
26118+#ifdef CONFIG_PAX_MEMORY_UDEREF
26119+ __set_fs(MAKE_MM_SEG(0));
26120+#endif
26121+
26122 call_on_stack(__do_softirq, isp);
26123+
26124+#ifdef CONFIG_PAX_MEMORY_UDEREF
26125+ __set_fs(current_thread_info()->addr_limit);
26126+#endif
26127+
26128 }
26129
26130 bool handle_irq(unsigned irq, struct pt_regs *regs)
26131@@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
26132 if (unlikely(!desc))
26133 return false;
26134
26135- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
26136+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
26137 if (unlikely(overflow))
26138 print_stack_overflow();
26139 desc->handle_irq(irq, desc);
26140diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
26141index 4d1c746..55a22d6 100644
26142--- a/arch/x86/kernel/irq_64.c
26143+++ b/arch/x86/kernel/irq_64.c
26144@@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
26145 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
26146 EXPORT_PER_CPU_SYMBOL(irq_regs);
26147
26148+extern void gr_handle_kernel_exploit(void);
26149+
26150 int sysctl_panic_on_stackoverflow;
26151
26152 /*
26153@@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
26154 u64 estack_top, estack_bottom;
26155 u64 curbase = (u64)task_stack_page(current);
26156
26157- if (user_mode_vm(regs))
26158+ if (user_mode(regs))
26159 return;
26160
26161 if (regs->sp >= curbase + sizeof(struct thread_info) +
26162@@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
26163 irq_stack_top, irq_stack_bottom,
26164 estack_top, estack_bottom);
26165
26166+ gr_handle_kernel_exploit();
26167+
26168 if (sysctl_panic_on_stackoverflow)
26169 panic("low stack detected by irq handler - check messages\n");
26170 #endif
26171diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
26172index 26d5a55..a01160a 100644
26173--- a/arch/x86/kernel/jump_label.c
26174+++ b/arch/x86/kernel/jump_label.c
26175@@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
26176 * Jump label is enabled for the first time.
26177 * So we expect a default_nop...
26178 */
26179- if (unlikely(memcmp((void *)entry->code, default_nop, 5)
26180+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
26181 != 0))
26182 bug_at((void *)entry->code, __LINE__);
26183 } else {
26184@@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
26185 * ...otherwise expect an ideal_nop. Otherwise
26186 * something went horribly wrong.
26187 */
26188- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
26189+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
26190 != 0))
26191 bug_at((void *)entry->code, __LINE__);
26192 }
26193@@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
26194 * are converting the default nop to the ideal nop.
26195 */
26196 if (init) {
26197- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
26198+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
26199 bug_at((void *)entry->code, __LINE__);
26200 } else {
26201 code.jump = 0xe9;
26202 code.offset = entry->target -
26203 (entry->code + JUMP_LABEL_NOP_SIZE);
26204- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
26205+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
26206 bug_at((void *)entry->code, __LINE__);
26207 }
26208 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
26209diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
26210index 7ec1d5f..5a7d130 100644
26211--- a/arch/x86/kernel/kgdb.c
26212+++ b/arch/x86/kernel/kgdb.c
26213@@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
26214 #ifdef CONFIG_X86_32
26215 switch (regno) {
26216 case GDB_SS:
26217- if (!user_mode_vm(regs))
26218+ if (!user_mode(regs))
26219 *(unsigned long *)mem = __KERNEL_DS;
26220 break;
26221 case GDB_SP:
26222- if (!user_mode_vm(regs))
26223+ if (!user_mode(regs))
26224 *(unsigned long *)mem = kernel_stack_pointer(regs);
26225 break;
26226 case GDB_GS:
26227@@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
26228 bp->attr.bp_addr = breakinfo[breakno].addr;
26229 bp->attr.bp_len = breakinfo[breakno].len;
26230 bp->attr.bp_type = breakinfo[breakno].type;
26231- info->address = breakinfo[breakno].addr;
26232+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
26233+ info->address = ktla_ktva(breakinfo[breakno].addr);
26234+ else
26235+ info->address = breakinfo[breakno].addr;
26236 info->len = breakinfo[breakno].len;
26237 info->type = breakinfo[breakno].type;
26238 val = arch_install_hw_breakpoint(bp);
26239@@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
26240 case 'k':
26241 /* clear the trace bit */
26242 linux_regs->flags &= ~X86_EFLAGS_TF;
26243- atomic_set(&kgdb_cpu_doing_single_step, -1);
26244+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
26245
26246 /* set the trace bit if we're stepping */
26247 if (remcomInBuffer[0] == 's') {
26248 linux_regs->flags |= X86_EFLAGS_TF;
26249- atomic_set(&kgdb_cpu_doing_single_step,
26250+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
26251 raw_smp_processor_id());
26252 }
26253
26254@@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
26255
26256 switch (cmd) {
26257 case DIE_DEBUG:
26258- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
26259+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
26260 if (user_mode(regs))
26261 return single_step_cont(regs, args);
26262 break;
26263@@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
26264 #endif /* CONFIG_DEBUG_RODATA */
26265
26266 bpt->type = BP_BREAKPOINT;
26267- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
26268+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
26269 BREAK_INSTR_SIZE);
26270 if (err)
26271 return err;
26272- err = probe_kernel_write((char *)bpt->bpt_addr,
26273+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
26274 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
26275 #ifdef CONFIG_DEBUG_RODATA
26276 if (!err)
26277@@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
26278 return -EBUSY;
26279 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
26280 BREAK_INSTR_SIZE);
26281- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
26282+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
26283 if (err)
26284 return err;
26285 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
26286@@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
26287 if (mutex_is_locked(&text_mutex))
26288 goto knl_write;
26289 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
26290- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
26291+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
26292 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
26293 goto knl_write;
26294 return err;
26295 knl_write:
26296 #endif /* CONFIG_DEBUG_RODATA */
26297- return probe_kernel_write((char *)bpt->bpt_addr,
26298+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
26299 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
26300 }
26301
26302diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
26303index 67e6d19..731ed28 100644
26304--- a/arch/x86/kernel/kprobes/core.c
26305+++ b/arch/x86/kernel/kprobes/core.c
26306@@ -120,9 +120,12 @@ __synthesize_relative_insn(void *from, void *to, u8 op)
26307 s32 raddr;
26308 } __packed *insn;
26309
26310- insn = (struct __arch_relative_insn *)from;
26311+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
26312+
26313+ pax_open_kernel();
26314 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
26315 insn->op = op;
26316+ pax_close_kernel();
26317 }
26318
26319 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
26320@@ -168,7 +171,7 @@ int can_boost(kprobe_opcode_t *opcodes)
26321 kprobe_opcode_t opcode;
26322 kprobe_opcode_t *orig_opcodes = opcodes;
26323
26324- if (search_exception_tables((unsigned long)opcodes))
26325+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
26326 return 0; /* Page fault may occur on this address. */
26327
26328 retry:
26329@@ -242,9 +245,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
26330 * for the first byte, we can recover the original instruction
26331 * from it and kp->opcode.
26332 */
26333- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
26334+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
26335 buf[0] = kp->opcode;
26336- return (unsigned long)buf;
26337+ return ktva_ktla((unsigned long)buf);
26338 }
26339
26340 /*
26341@@ -336,7 +339,9 @@ int __copy_instruction(u8 *dest, u8 *src)
26342 /* Another subsystem puts a breakpoint, failed to recover */
26343 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
26344 return 0;
26345+ pax_open_kernel();
26346 memcpy(dest, insn.kaddr, insn.length);
26347+ pax_close_kernel();
26348
26349 #ifdef CONFIG_X86_64
26350 if (insn_rip_relative(&insn)) {
26351@@ -363,7 +368,9 @@ int __copy_instruction(u8 *dest, u8 *src)
26352 return 0;
26353 }
26354 disp = (u8 *) dest + insn_offset_displacement(&insn);
26355+ pax_open_kernel();
26356 *(s32 *) disp = (s32) newdisp;
26357+ pax_close_kernel();
26358 }
26359 #endif
26360 return insn.length;
26361@@ -505,7 +512,7 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
26362 * nor set current_kprobe, because it doesn't use single
26363 * stepping.
26364 */
26365- regs->ip = (unsigned long)p->ainsn.insn;
26366+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
26367 preempt_enable_no_resched();
26368 return;
26369 }
26370@@ -522,9 +529,9 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
26371 regs->flags &= ~X86_EFLAGS_IF;
26372 /* single step inline if the instruction is an int3 */
26373 if (p->opcode == BREAKPOINT_INSTRUCTION)
26374- regs->ip = (unsigned long)p->addr;
26375+ regs->ip = ktla_ktva((unsigned long)p->addr);
26376 else
26377- regs->ip = (unsigned long)p->ainsn.insn;
26378+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
26379 }
26380 NOKPROBE_SYMBOL(setup_singlestep);
26381
26382@@ -574,7 +581,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
26383 struct kprobe *p;
26384 struct kprobe_ctlblk *kcb;
26385
26386- if (user_mode_vm(regs))
26387+ if (user_mode(regs))
26388 return 0;
26389
26390 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
26391@@ -609,7 +616,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
26392 setup_singlestep(p, regs, kcb, 0);
26393 return 1;
26394 }
26395- } else if (*addr != BREAKPOINT_INSTRUCTION) {
26396+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
26397 /*
26398 * The breakpoint instruction was removed right
26399 * after we hit it. Another cpu has removed
26400@@ -656,6 +663,9 @@ static void __used kretprobe_trampoline_holder(void)
26401 " movq %rax, 152(%rsp)\n"
26402 RESTORE_REGS_STRING
26403 " popfq\n"
26404+#ifdef KERNEXEC_PLUGIN
26405+ " btsq $63,(%rsp)\n"
26406+#endif
26407 #else
26408 " pushf\n"
26409 SAVE_REGS_STRING
26410@@ -796,7 +806,7 @@ static void resume_execution(struct kprobe *p, struct pt_regs *regs,
26411 struct kprobe_ctlblk *kcb)
26412 {
26413 unsigned long *tos = stack_addr(regs);
26414- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
26415+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
26416 unsigned long orig_ip = (unsigned long)p->addr;
26417 kprobe_opcode_t *insn = p->ainsn.insn;
26418
26419@@ -979,7 +989,7 @@ int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
26420 struct die_args *args = data;
26421 int ret = NOTIFY_DONE;
26422
26423- if (args->regs && user_mode_vm(args->regs))
26424+ if (args->regs && user_mode(args->regs))
26425 return ret;
26426
26427 if (val == DIE_GPF) {
26428diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
26429index f1314d0..15f3154 100644
26430--- a/arch/x86/kernel/kprobes/opt.c
26431+++ b/arch/x86/kernel/kprobes/opt.c
26432@@ -79,6 +79,7 @@ found:
26433 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
26434 static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
26435 {
26436+ pax_open_kernel();
26437 #ifdef CONFIG_X86_64
26438 *addr++ = 0x48;
26439 *addr++ = 0xbf;
26440@@ -86,6 +87,7 @@ static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
26441 *addr++ = 0xb8;
26442 #endif
26443 *(unsigned long *)addr = val;
26444+ pax_close_kernel();
26445 }
26446
26447 asm (
26448@@ -337,7 +339,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
26449 * Verify if the address gap is in 2GB range, because this uses
26450 * a relative jump.
26451 */
26452- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
26453+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
26454 if (abs(rel) > 0x7fffffff) {
26455 __arch_remove_optimized_kprobe(op, 0);
26456 return -ERANGE;
26457@@ -354,16 +356,18 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
26458 op->optinsn.size = ret;
26459
26460 /* Copy arch-dep-instance from template */
26461- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
26462+ pax_open_kernel();
26463+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
26464+ pax_close_kernel();
26465
26466 /* Set probe information */
26467 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
26468
26469 /* Set probe function call */
26470- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
26471+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
26472
26473 /* Set returning jmp instruction at the tail of out-of-line buffer */
26474- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
26475+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
26476 (u8 *)op->kp.addr + op->optinsn.size);
26477
26478 flush_icache_range((unsigned long) buf,
26479@@ -388,7 +392,7 @@ void arch_optimize_kprobes(struct list_head *oplist)
26480 WARN_ON(kprobe_disabled(&op->kp));
26481
26482 /* Backup instructions which will be replaced by jump address */
26483- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
26484+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
26485 RELATIVE_ADDR_SIZE);
26486
26487 insn_buf[0] = RELATIVEJUMP_OPCODE;
26488@@ -436,7 +440,7 @@ int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
26489 /* This kprobe is really able to run optimized path. */
26490 op = container_of(p, struct optimized_kprobe, kp);
26491 /* Detour through copied instructions */
26492- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
26493+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
26494 if (!reenter)
26495 reset_current_kprobe();
26496 preempt_enable_no_resched();
26497diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
26498index c2bedae..25e7ab60 100644
26499--- a/arch/x86/kernel/ksysfs.c
26500+++ b/arch/x86/kernel/ksysfs.c
26501@@ -184,7 +184,7 @@ out:
26502
26503 static struct kobj_attribute type_attr = __ATTR_RO(type);
26504
26505-static struct bin_attribute data_attr = {
26506+static bin_attribute_no_const data_attr __read_only = {
26507 .attr = {
26508 .name = "data",
26509 .mode = S_IRUGO,
26510diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
26511index c37886d..d851d32 100644
26512--- a/arch/x86/kernel/ldt.c
26513+++ b/arch/x86/kernel/ldt.c
26514@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
26515 if (reload) {
26516 #ifdef CONFIG_SMP
26517 preempt_disable();
26518- load_LDT(pc);
26519+ load_LDT_nolock(pc);
26520 if (!cpumask_equal(mm_cpumask(current->mm),
26521 cpumask_of(smp_processor_id())))
26522 smp_call_function(flush_ldt, current->mm, 1);
26523 preempt_enable();
26524 #else
26525- load_LDT(pc);
26526+ load_LDT_nolock(pc);
26527 #endif
26528 }
26529 if (oldsize) {
26530@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
26531 return err;
26532
26533 for (i = 0; i < old->size; i++)
26534- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
26535+ write_ldt_entry(new->ldt, i, old->ldt + i);
26536 return 0;
26537 }
26538
26539@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
26540 retval = copy_ldt(&mm->context, &old_mm->context);
26541 mutex_unlock(&old_mm->context.lock);
26542 }
26543+
26544+ if (tsk == current) {
26545+ mm->context.vdso = 0;
26546+
26547+#ifdef CONFIG_X86_32
26548+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26549+ mm->context.user_cs_base = 0UL;
26550+ mm->context.user_cs_limit = ~0UL;
26551+
26552+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
26553+ cpus_clear(mm->context.cpu_user_cs_mask);
26554+#endif
26555+
26556+#endif
26557+#endif
26558+
26559+ }
26560+
26561 return retval;
26562 }
26563
26564@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
26565 }
26566 }
26567
26568+#ifdef CONFIG_PAX_SEGMEXEC
26569+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
26570+ error = -EINVAL;
26571+ goto out_unlock;
26572+ }
26573+#endif
26574+
26575 if (!IS_ENABLED(CONFIG_X86_16BIT) && !ldt_info.seg_32bit) {
26576 error = -EINVAL;
26577 goto out_unlock;
26578diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
26579index 1667b1d..16492c5 100644
26580--- a/arch/x86/kernel/machine_kexec_32.c
26581+++ b/arch/x86/kernel/machine_kexec_32.c
26582@@ -25,7 +25,7 @@
26583 #include <asm/cacheflush.h>
26584 #include <asm/debugreg.h>
26585
26586-static void set_idt(void *newidt, __u16 limit)
26587+static void set_idt(struct desc_struct *newidt, __u16 limit)
26588 {
26589 struct desc_ptr curidt;
26590
26591@@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
26592 }
26593
26594
26595-static void set_gdt(void *newgdt, __u16 limit)
26596+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
26597 {
26598 struct desc_ptr curgdt;
26599
26600@@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
26601 }
26602
26603 control_page = page_address(image->control_code_page);
26604- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
26605+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
26606
26607 relocate_kernel_ptr = control_page;
26608 page_list[PA_CONTROL_PAGE] = __pa(control_page);
26609diff --git a/arch/x86/kernel/mcount_64.S b/arch/x86/kernel/mcount_64.S
26610index c73aecf..4c63630 100644
26611--- a/arch/x86/kernel/mcount_64.S
26612+++ b/arch/x86/kernel/mcount_64.S
26613@@ -7,7 +7,7 @@
26614 #include <linux/linkage.h>
26615 #include <asm/ptrace.h>
26616 #include <asm/ftrace.h>
26617-
26618+#include <asm/alternative-asm.h>
26619
26620 .code64
26621 .section .entry.text, "ax"
26622@@ -24,8 +24,9 @@
26623 #ifdef CONFIG_DYNAMIC_FTRACE
26624
26625 ENTRY(function_hook)
26626+ pax_force_retaddr
26627 retq
26628-END(function_hook)
26629+ENDPROC(function_hook)
26630
26631 /* skip is set if stack has been adjusted */
26632 .macro ftrace_caller_setup skip=0
26633@@ -62,8 +63,9 @@ GLOBAL(ftrace_graph_call)
26634 #endif
26635
26636 GLOBAL(ftrace_stub)
26637+ pax_force_retaddr
26638 retq
26639-END(ftrace_caller)
26640+ENDPROC(ftrace_caller)
26641
26642 ENTRY(ftrace_regs_caller)
26643 /* Save the current flags before compare (in SS location)*/
26644@@ -127,7 +129,7 @@ GLOBAL(ftrace_regs_call)
26645 popfq
26646 jmp ftrace_stub
26647
26648-END(ftrace_regs_caller)
26649+ENDPROC(ftrace_regs_caller)
26650
26651
26652 #else /* ! CONFIG_DYNAMIC_FTRACE */
26653@@ -145,6 +147,7 @@ ENTRY(function_hook)
26654 #endif
26655
26656 GLOBAL(ftrace_stub)
26657+ pax_force_retaddr
26658 retq
26659
26660 trace:
26661@@ -158,12 +161,13 @@ trace:
26662 #endif
26663 subq $MCOUNT_INSN_SIZE, %rdi
26664
26665+ pax_force_fptr ftrace_trace_function
26666 call *ftrace_trace_function
26667
26668 MCOUNT_RESTORE_FRAME
26669
26670 jmp ftrace_stub
26671-END(function_hook)
26672+ENDPROC(function_hook)
26673 #endif /* CONFIG_DYNAMIC_FTRACE */
26674 #endif /* CONFIG_FUNCTION_TRACER */
26675
26676@@ -185,8 +189,9 @@ ENTRY(ftrace_graph_caller)
26677
26678 MCOUNT_RESTORE_FRAME
26679
26680+ pax_force_retaddr
26681 retq
26682-END(ftrace_graph_caller)
26683+ENDPROC(ftrace_graph_caller)
26684
26685 GLOBAL(return_to_handler)
26686 subq $24, %rsp
26687@@ -202,5 +207,7 @@ GLOBAL(return_to_handler)
26688 movq 8(%rsp), %rdx
26689 movq (%rsp), %rax
26690 addq $24, %rsp
26691+ pax_force_fptr %rdi
26692 jmp *%rdi
26693+ENDPROC(return_to_handler)
26694 #endif
26695diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
26696index e69f988..da078ea 100644
26697--- a/arch/x86/kernel/module.c
26698+++ b/arch/x86/kernel/module.c
26699@@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
26700 }
26701 #endif
26702
26703-void *module_alloc(unsigned long size)
26704+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
26705 {
26706- if (PAGE_ALIGN(size) > MODULES_LEN)
26707+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
26708 return NULL;
26709 return __vmalloc_node_range(size, 1,
26710 MODULES_VADDR + get_module_load_offset(),
26711- MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
26712- PAGE_KERNEL_EXEC, NUMA_NO_NODE,
26713+ MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
26714+ prot, NUMA_NO_NODE,
26715 __builtin_return_address(0));
26716 }
26717
26718+void *module_alloc(unsigned long size)
26719+{
26720+
26721+#ifdef CONFIG_PAX_KERNEXEC
26722+ return __module_alloc(size, PAGE_KERNEL);
26723+#else
26724+ return __module_alloc(size, PAGE_KERNEL_EXEC);
26725+#endif
26726+
26727+}
26728+
26729+#ifdef CONFIG_PAX_KERNEXEC
26730+#ifdef CONFIG_X86_32
26731+void *module_alloc_exec(unsigned long size)
26732+{
26733+ struct vm_struct *area;
26734+
26735+ if (size == 0)
26736+ return NULL;
26737+
26738+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
26739+return area ? area->addr : NULL;
26740+}
26741+EXPORT_SYMBOL(module_alloc_exec);
26742+
26743+void module_free_exec(struct module *mod, void *module_region)
26744+{
26745+ vunmap(module_region);
26746+}
26747+EXPORT_SYMBOL(module_free_exec);
26748+#else
26749+void module_free_exec(struct module *mod, void *module_region)
26750+{
26751+ module_free(mod, module_region);
26752+}
26753+EXPORT_SYMBOL(module_free_exec);
26754+
26755+void *module_alloc_exec(unsigned long size)
26756+{
26757+ return __module_alloc(size, PAGE_KERNEL_RX);
26758+}
26759+EXPORT_SYMBOL(module_alloc_exec);
26760+#endif
26761+#endif
26762+
26763 #ifdef CONFIG_X86_32
26764 int apply_relocate(Elf32_Shdr *sechdrs,
26765 const char *strtab,
26766@@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26767 unsigned int i;
26768 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
26769 Elf32_Sym *sym;
26770- uint32_t *location;
26771+ uint32_t *plocation, location;
26772
26773 DEBUGP("Applying relocate section %u to %u\n",
26774 relsec, sechdrs[relsec].sh_info);
26775 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
26776 /* This is where to make the change */
26777- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26778- + rel[i].r_offset;
26779+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26780+ location = (uint32_t)plocation;
26781+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26782+ plocation = ktla_ktva((void *)plocation);
26783 /* This is the symbol it is referring to. Note that all
26784 undefined symbols have been resolved. */
26785 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26786@@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26787 switch (ELF32_R_TYPE(rel[i].r_info)) {
26788 case R_386_32:
26789 /* We add the value into the location given */
26790- *location += sym->st_value;
26791+ pax_open_kernel();
26792+ *plocation += sym->st_value;
26793+ pax_close_kernel();
26794 break;
26795 case R_386_PC32:
26796 /* Add the value, subtract its position */
26797- *location += sym->st_value - (uint32_t)location;
26798+ pax_open_kernel();
26799+ *plocation += sym->st_value - location;
26800+ pax_close_kernel();
26801 break;
26802 default:
26803 pr_err("%s: Unknown relocation: %u\n",
26804@@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26805 case R_X86_64_NONE:
26806 break;
26807 case R_X86_64_64:
26808+ pax_open_kernel();
26809 *(u64 *)loc = val;
26810+ pax_close_kernel();
26811 break;
26812 case R_X86_64_32:
26813+ pax_open_kernel();
26814 *(u32 *)loc = val;
26815+ pax_close_kernel();
26816 if (val != *(u32 *)loc)
26817 goto overflow;
26818 break;
26819 case R_X86_64_32S:
26820+ pax_open_kernel();
26821 *(s32 *)loc = val;
26822+ pax_close_kernel();
26823 if ((s64)val != *(s32 *)loc)
26824 goto overflow;
26825 break;
26826 case R_X86_64_PC32:
26827 val -= (u64)loc;
26828+ pax_open_kernel();
26829 *(u32 *)loc = val;
26830+ pax_close_kernel();
26831+
26832 #if 0
26833 if ((s64)val != *(s32 *)loc)
26834 goto overflow;
26835diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26836index c9603ac..9f88728 100644
26837--- a/arch/x86/kernel/msr.c
26838+++ b/arch/x86/kernel/msr.c
26839@@ -37,6 +37,7 @@
26840 #include <linux/notifier.h>
26841 #include <linux/uaccess.h>
26842 #include <linux/gfp.h>
26843+#include <linux/grsecurity.h>
26844
26845 #include <asm/processor.h>
26846 #include <asm/msr.h>
26847@@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26848 int err = 0;
26849 ssize_t bytes = 0;
26850
26851+#ifdef CONFIG_GRKERNSEC_KMEM
26852+ gr_handle_msr_write();
26853+ return -EPERM;
26854+#endif
26855+
26856 if (count % 8)
26857 return -EINVAL; /* Invalid chunk size */
26858
26859@@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26860 err = -EBADF;
26861 break;
26862 }
26863+#ifdef CONFIG_GRKERNSEC_KMEM
26864+ gr_handle_msr_write();
26865+ return -EPERM;
26866+#endif
26867 if (copy_from_user(&regs, uregs, sizeof regs)) {
26868 err = -EFAULT;
26869 break;
26870@@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26871 return notifier_from_errno(err);
26872 }
26873
26874-static struct notifier_block __refdata msr_class_cpu_notifier = {
26875+static struct notifier_block msr_class_cpu_notifier = {
26876 .notifier_call = msr_class_cpu_callback,
26877 };
26878
26879diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26880index c3e985d..110a36a 100644
26881--- a/arch/x86/kernel/nmi.c
26882+++ b/arch/x86/kernel/nmi.c
26883@@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
26884
26885 static void nmi_max_handler(struct irq_work *w)
26886 {
26887- struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
26888+ struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
26889 int remainder_ns, decimal_msecs;
26890- u64 whole_msecs = ACCESS_ONCE(a->max_duration);
26891+ u64 whole_msecs = ACCESS_ONCE(n->max_duration);
26892
26893 remainder_ns = do_div(whole_msecs, (1000 * 1000));
26894 decimal_msecs = remainder_ns / 1000;
26895
26896 printk_ratelimited(KERN_INFO
26897 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
26898- a->handler, whole_msecs, decimal_msecs);
26899+ n->action->handler, whole_msecs, decimal_msecs);
26900 }
26901
26902 static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26903@@ -134,11 +134,11 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26904 delta = sched_clock() - delta;
26905 trace_nmi_handler(a->handler, (int)delta, thishandled);
26906
26907- if (delta < nmi_longest_ns || delta < a->max_duration)
26908+ if (delta < nmi_longest_ns || delta < a->work->max_duration)
26909 continue;
26910
26911- a->max_duration = delta;
26912- irq_work_queue(&a->irq_work);
26913+ a->work->max_duration = delta;
26914+ irq_work_queue(&a->work->irq_work);
26915 }
26916
26917 rcu_read_unlock();
26918@@ -148,7 +148,7 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26919 }
26920 NOKPROBE_SYMBOL(nmi_handle);
26921
26922-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26923+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26924 {
26925 struct nmi_desc *desc = nmi_to_desc(type);
26926 unsigned long flags;
26927@@ -156,7 +156,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26928 if (!action->handler)
26929 return -EINVAL;
26930
26931- init_irq_work(&action->irq_work, nmi_max_handler);
26932+ action->work->action = action;
26933+ init_irq_work(&action->work->irq_work, nmi_max_handler);
26934
26935 spin_lock_irqsave(&desc->lock, flags);
26936
26937@@ -174,9 +175,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26938 * event confuses some handlers (kdump uses this flag)
26939 */
26940 if (action->flags & NMI_FLAG_FIRST)
26941- list_add_rcu(&action->list, &desc->head);
26942+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26943 else
26944- list_add_tail_rcu(&action->list, &desc->head);
26945+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26946
26947 spin_unlock_irqrestore(&desc->lock, flags);
26948 return 0;
26949@@ -199,7 +200,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26950 if (!strcmp(n->name, name)) {
26951 WARN(in_nmi(),
26952 "Trying to free NMI (%s) from NMI context!\n", n->name);
26953- list_del_rcu(&n->list);
26954+ pax_list_del_rcu((struct list_head *)&n->list);
26955 break;
26956 }
26957 }
26958@@ -528,6 +529,17 @@ static inline void nmi_nesting_postprocess(void)
26959 dotraplinkage notrace void
26960 do_nmi(struct pt_regs *regs, long error_code)
26961 {
26962+
26963+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26964+ if (!user_mode(regs)) {
26965+ unsigned long cs = regs->cs & 0xFFFF;
26966+ unsigned long ip = ktva_ktla(regs->ip);
26967+
26968+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26969+ regs->ip = ip;
26970+ }
26971+#endif
26972+
26973 nmi_nesting_preprocess(regs);
26974
26975 nmi_enter();
26976diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26977index 6d9582e..f746287 100644
26978--- a/arch/x86/kernel/nmi_selftest.c
26979+++ b/arch/x86/kernel/nmi_selftest.c
26980@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26981 {
26982 /* trap all the unknown NMIs we may generate */
26983 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26984- __initdata);
26985+ __initconst);
26986 }
26987
26988 static void __init cleanup_nmi_testsuite(void)
26989@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26990 unsigned long timeout;
26991
26992 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26993- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26994+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26995 nmi_fail = FAILURE;
26996 return;
26997 }
26998diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26999index bbb6c73..24a58ef 100644
27000--- a/arch/x86/kernel/paravirt-spinlocks.c
27001+++ b/arch/x86/kernel/paravirt-spinlocks.c
27002@@ -8,7 +8,7 @@
27003
27004 #include <asm/paravirt.h>
27005
27006-struct pv_lock_ops pv_lock_ops = {
27007+struct pv_lock_ops pv_lock_ops __read_only = {
27008 #ifdef CONFIG_SMP
27009 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
27010 .unlock_kick = paravirt_nop,
27011diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
27012index 548d25f..f8fb99c 100644
27013--- a/arch/x86/kernel/paravirt.c
27014+++ b/arch/x86/kernel/paravirt.c
27015@@ -56,6 +56,9 @@ u64 _paravirt_ident_64(u64 x)
27016 {
27017 return x;
27018 }
27019+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
27020+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
27021+#endif
27022
27023 void __init default_banner(void)
27024 {
27025@@ -142,16 +145,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
27026
27027 if (opfunc == NULL)
27028 /* If there's no function, patch it with a ud2a (BUG) */
27029- ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
27030- else if (opfunc == _paravirt_nop)
27031+ ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
27032+ else if (opfunc == (void *)_paravirt_nop)
27033 /* If the operation is a nop, then nop the callsite */
27034 ret = paravirt_patch_nop();
27035
27036 /* identity functions just return their single argument */
27037- else if (opfunc == _paravirt_ident_32)
27038+ else if (opfunc == (void *)_paravirt_ident_32)
27039 ret = paravirt_patch_ident_32(insnbuf, len);
27040- else if (opfunc == _paravirt_ident_64)
27041+ else if (opfunc == (void *)_paravirt_ident_64)
27042 ret = paravirt_patch_ident_64(insnbuf, len);
27043+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
27044+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
27045+ ret = paravirt_patch_ident_64(insnbuf, len);
27046+#endif
27047
27048 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
27049 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
27050@@ -176,7 +183,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
27051 if (insn_len > len || start == NULL)
27052 insn_len = len;
27053 else
27054- memcpy(insnbuf, start, insn_len);
27055+ memcpy(insnbuf, ktla_ktva(start), insn_len);
27056
27057 return insn_len;
27058 }
27059@@ -300,7 +307,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
27060 return this_cpu_read(paravirt_lazy_mode);
27061 }
27062
27063-struct pv_info pv_info = {
27064+struct pv_info pv_info __read_only = {
27065 .name = "bare hardware",
27066 .paravirt_enabled = 0,
27067 .kernel_rpl = 0,
27068@@ -311,16 +318,16 @@ struct pv_info pv_info = {
27069 #endif
27070 };
27071
27072-struct pv_init_ops pv_init_ops = {
27073+struct pv_init_ops pv_init_ops __read_only = {
27074 .patch = native_patch,
27075 };
27076
27077-struct pv_time_ops pv_time_ops = {
27078+struct pv_time_ops pv_time_ops __read_only = {
27079 .sched_clock = native_sched_clock,
27080 .steal_clock = native_steal_clock,
27081 };
27082
27083-__visible struct pv_irq_ops pv_irq_ops = {
27084+__visible struct pv_irq_ops pv_irq_ops __read_only = {
27085 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
27086 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
27087 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
27088@@ -332,7 +339,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
27089 #endif
27090 };
27091
27092-__visible struct pv_cpu_ops pv_cpu_ops = {
27093+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
27094 .cpuid = native_cpuid,
27095 .get_debugreg = native_get_debugreg,
27096 .set_debugreg = native_set_debugreg,
27097@@ -395,21 +402,26 @@ NOKPROBE_SYMBOL(native_get_debugreg);
27098 NOKPROBE_SYMBOL(native_set_debugreg);
27099 NOKPROBE_SYMBOL(native_load_idt);
27100
27101-struct pv_apic_ops pv_apic_ops = {
27102+struct pv_apic_ops pv_apic_ops __read_only= {
27103 #ifdef CONFIG_X86_LOCAL_APIC
27104 .startup_ipi_hook = paravirt_nop,
27105 #endif
27106 };
27107
27108-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
27109+#ifdef CONFIG_X86_32
27110+#ifdef CONFIG_X86_PAE
27111+/* 64-bit pagetable entries */
27112+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
27113+#else
27114 /* 32-bit pagetable entries */
27115 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
27116+#endif
27117 #else
27118 /* 64-bit pagetable entries */
27119 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
27120 #endif
27121
27122-struct pv_mmu_ops pv_mmu_ops = {
27123+struct pv_mmu_ops pv_mmu_ops __read_only = {
27124
27125 .read_cr2 = native_read_cr2,
27126 .write_cr2 = native_write_cr2,
27127@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
27128 .make_pud = PTE_IDENT,
27129
27130 .set_pgd = native_set_pgd,
27131+ .set_pgd_batched = native_set_pgd_batched,
27132 #endif
27133 #endif /* PAGETABLE_LEVELS >= 3 */
27134
27135@@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
27136 },
27137
27138 .set_fixmap = native_set_fixmap,
27139+
27140+#ifdef CONFIG_PAX_KERNEXEC
27141+ .pax_open_kernel = native_pax_open_kernel,
27142+ .pax_close_kernel = native_pax_close_kernel,
27143+#endif
27144+
27145 };
27146
27147 EXPORT_SYMBOL_GPL(pv_time_ops);
27148diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
27149index 0497f71..7186c0d 100644
27150--- a/arch/x86/kernel/pci-calgary_64.c
27151+++ b/arch/x86/kernel/pci-calgary_64.c
27152@@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
27153 tce_space = be64_to_cpu(readq(target));
27154 tce_space = tce_space & TAR_SW_BITS;
27155
27156- tce_space = tce_space & (~specified_table_size);
27157+ tce_space = tce_space & (~(unsigned long)specified_table_size);
27158 info->tce_space = (u64 *)__va(tce_space);
27159 }
27160 }
27161diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
27162index 35ccf75..7a15747 100644
27163--- a/arch/x86/kernel/pci-iommu_table.c
27164+++ b/arch/x86/kernel/pci-iommu_table.c
27165@@ -2,7 +2,7 @@
27166 #include <asm/iommu_table.h>
27167 #include <linux/string.h>
27168 #include <linux/kallsyms.h>
27169-
27170+#include <linux/sched.h>
27171
27172 #define DEBUG 1
27173
27174diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
27175index 77dd0ad..9ec4723 100644
27176--- a/arch/x86/kernel/pci-swiotlb.c
27177+++ b/arch/x86/kernel/pci-swiotlb.c
27178@@ -33,7 +33,7 @@ void x86_swiotlb_free_coherent(struct device *dev, size_t size,
27179 struct dma_attrs *attrs)
27180 {
27181 if (is_swiotlb_buffer(dma_to_phys(dev, dma_addr)))
27182- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
27183+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
27184 else
27185 dma_generic_free_coherent(dev, size, vaddr, dma_addr, attrs);
27186 }
27187diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
27188index ca7f0d5..8996469 100644
27189--- a/arch/x86/kernel/preempt.S
27190+++ b/arch/x86/kernel/preempt.S
27191@@ -3,12 +3,14 @@
27192 #include <asm/dwarf2.h>
27193 #include <asm/asm.h>
27194 #include <asm/calling.h>
27195+#include <asm/alternative-asm.h>
27196
27197 ENTRY(___preempt_schedule)
27198 CFI_STARTPROC
27199 SAVE_ALL
27200 call preempt_schedule
27201 RESTORE_ALL
27202+ pax_force_retaddr
27203 ret
27204 CFI_ENDPROC
27205
27206@@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
27207 SAVE_ALL
27208 call preempt_schedule_context
27209 RESTORE_ALL
27210+ pax_force_retaddr
27211 ret
27212 CFI_ENDPROC
27213
27214diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
27215index f804dc9..7c62095 100644
27216--- a/arch/x86/kernel/process.c
27217+++ b/arch/x86/kernel/process.c
27218@@ -36,7 +36,8 @@
27219 * section. Since TSS's are completely CPU-local, we want them
27220 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
27221 */
27222-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
27223+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
27224+EXPORT_SYMBOL(init_tss);
27225
27226 #ifdef CONFIG_X86_64
27227 static DEFINE_PER_CPU(unsigned char, is_idle);
27228@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
27229 task_xstate_cachep =
27230 kmem_cache_create("task_xstate", xstate_size,
27231 __alignof__(union thread_xstate),
27232- SLAB_PANIC | SLAB_NOTRACK, NULL);
27233+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
27234 setup_xstate_comp();
27235 }
27236
27237@@ -106,7 +107,7 @@ void exit_thread(void)
27238 unsigned long *bp = t->io_bitmap_ptr;
27239
27240 if (bp) {
27241- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
27242+ struct tss_struct *tss = init_tss + get_cpu();
27243
27244 t->io_bitmap_ptr = NULL;
27245 clear_thread_flag(TIF_IO_BITMAP);
27246@@ -126,6 +127,9 @@ void flush_thread(void)
27247 {
27248 struct task_struct *tsk = current;
27249
27250+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
27251+ loadsegment(gs, 0);
27252+#endif
27253 flush_ptrace_hw_breakpoint(tsk);
27254 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
27255 drop_init_fpu(tsk);
27256@@ -272,7 +276,7 @@ static void __exit_idle(void)
27257 void exit_idle(void)
27258 {
27259 /* idle loop has pid 0 */
27260- if (current->pid)
27261+ if (task_pid_nr(current))
27262 return;
27263 __exit_idle();
27264 }
27265@@ -325,7 +329,7 @@ bool xen_set_default_idle(void)
27266 return ret;
27267 }
27268 #endif
27269-void stop_this_cpu(void *dummy)
27270+__noreturn void stop_this_cpu(void *dummy)
27271 {
27272 local_irq_disable();
27273 /*
27274@@ -454,16 +458,37 @@ static int __init idle_setup(char *str)
27275 }
27276 early_param("idle", idle_setup);
27277
27278-unsigned long arch_align_stack(unsigned long sp)
27279+#ifdef CONFIG_PAX_RANDKSTACK
27280+void pax_randomize_kstack(struct pt_regs *regs)
27281 {
27282- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
27283- sp -= get_random_int() % 8192;
27284- return sp & ~0xf;
27285-}
27286+ struct thread_struct *thread = &current->thread;
27287+ unsigned long time;
27288
27289-unsigned long arch_randomize_brk(struct mm_struct *mm)
27290-{
27291- unsigned long range_end = mm->brk + 0x02000000;
27292- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
27293-}
27294+ if (!randomize_va_space)
27295+ return;
27296+
27297+ if (v8086_mode(regs))
27298+ return;
27299
27300+ rdtscl(time);
27301+
27302+ /* P4 seems to return a 0 LSB, ignore it */
27303+#ifdef CONFIG_MPENTIUM4
27304+ time &= 0x3EUL;
27305+ time <<= 2;
27306+#elif defined(CONFIG_X86_64)
27307+ time &= 0xFUL;
27308+ time <<= 4;
27309+#else
27310+ time &= 0x1FUL;
27311+ time <<= 3;
27312+#endif
27313+
27314+ thread->sp0 ^= time;
27315+ load_sp0(init_tss + smp_processor_id(), thread);
27316+
27317+#ifdef CONFIG_X86_64
27318+ this_cpu_write(kernel_stack, thread->sp0);
27319+#endif
27320+}
27321+#endif
27322diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
27323index 7bc86bb..0ea06e8 100644
27324--- a/arch/x86/kernel/process_32.c
27325+++ b/arch/x86/kernel/process_32.c
27326@@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
27327 unsigned long thread_saved_pc(struct task_struct *tsk)
27328 {
27329 return ((unsigned long *)tsk->thread.sp)[3];
27330+//XXX return tsk->thread.eip;
27331 }
27332
27333 void __show_regs(struct pt_regs *regs, int all)
27334@@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
27335 unsigned long sp;
27336 unsigned short ss, gs;
27337
27338- if (user_mode_vm(regs)) {
27339+ if (user_mode(regs)) {
27340 sp = regs->sp;
27341 ss = regs->ss & 0xffff;
27342- gs = get_user_gs(regs);
27343 } else {
27344 sp = kernel_stack_pointer(regs);
27345 savesegment(ss, ss);
27346- savesegment(gs, gs);
27347 }
27348+ gs = get_user_gs(regs);
27349
27350 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
27351 (u16)regs->cs, regs->ip, regs->flags,
27352- smp_processor_id());
27353+ raw_smp_processor_id());
27354 print_symbol("EIP is at %s\n", regs->ip);
27355
27356 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
27357@@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
27358 int copy_thread(unsigned long clone_flags, unsigned long sp,
27359 unsigned long arg, struct task_struct *p)
27360 {
27361- struct pt_regs *childregs = task_pt_regs(p);
27362+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
27363 struct task_struct *tsk;
27364 int err;
27365
27366 p->thread.sp = (unsigned long) childregs;
27367 p->thread.sp0 = (unsigned long) (childregs+1);
27368+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
27369
27370 if (unlikely(p->flags & PF_KTHREAD)) {
27371 /* kernel thread */
27372 memset(childregs, 0, sizeof(struct pt_regs));
27373 p->thread.ip = (unsigned long) ret_from_kernel_thread;
27374- task_user_gs(p) = __KERNEL_STACK_CANARY;
27375- childregs->ds = __USER_DS;
27376- childregs->es = __USER_DS;
27377+ savesegment(gs, childregs->gs);
27378+ childregs->ds = __KERNEL_DS;
27379+ childregs->es = __KERNEL_DS;
27380 childregs->fs = __KERNEL_PERCPU;
27381 childregs->bx = sp; /* function */
27382 childregs->bp = arg;
27383@@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27384 struct thread_struct *prev = &prev_p->thread,
27385 *next = &next_p->thread;
27386 int cpu = smp_processor_id();
27387- struct tss_struct *tss = &per_cpu(init_tss, cpu);
27388+ struct tss_struct *tss = init_tss + cpu;
27389 fpu_switch_t fpu;
27390
27391 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
27392@@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27393 */
27394 lazy_save_gs(prev->gs);
27395
27396+#ifdef CONFIG_PAX_MEMORY_UDEREF
27397+ __set_fs(task_thread_info(next_p)->addr_limit);
27398+#endif
27399+
27400 /*
27401 * Load the per-thread Thread-Local Storage descriptor.
27402 */
27403@@ -314,9 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27404 */
27405 arch_end_context_switch(next_p);
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(current_task, next_p);
27411+ this_cpu_write(current_tinfo, &next_p->tinfo);
27412+ this_cpu_write(kernel_stack, next->sp0);
27413
27414 /*
27415 * Restore %gs if needed (which is common)
27416@@ -326,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27417
27418 switch_fpu_finish(next_p, fpu);
27419
27420- this_cpu_write(current_task, next_p);
27421-
27422 return prev_p;
27423 }
27424
27425@@ -357,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
27426 } while (count++ < 16);
27427 return 0;
27428 }
27429-
27430diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
27431index ca5b02d..c0b2f6a 100644
27432--- a/arch/x86/kernel/process_64.c
27433+++ b/arch/x86/kernel/process_64.c
27434@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
27435 struct pt_regs *childregs;
27436 struct task_struct *me = current;
27437
27438- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
27439+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
27440 childregs = task_pt_regs(p);
27441 p->thread.sp = (unsigned long) childregs;
27442 p->thread.usersp = me->thread.usersp;
27443+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
27444 set_tsk_thread_flag(p, TIF_FORK);
27445 p->thread.fpu_counter = 0;
27446 p->thread.io_bitmap_ptr = NULL;
27447@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
27448 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
27449 savesegment(es, p->thread.es);
27450 savesegment(ds, p->thread.ds);
27451+ savesegment(ss, p->thread.ss);
27452+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
27453 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
27454
27455 if (unlikely(p->flags & PF_KTHREAD)) {
27456@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27457 struct thread_struct *prev = &prev_p->thread;
27458 struct thread_struct *next = &next_p->thread;
27459 int cpu = smp_processor_id();
27460- struct tss_struct *tss = &per_cpu(init_tss, cpu);
27461+ struct tss_struct *tss = init_tss + cpu;
27462 unsigned fsindex, gsindex;
27463 fpu_switch_t fpu;
27464
27465@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27466 if (unlikely(next->ds | prev->ds))
27467 loadsegment(ds, next->ds);
27468
27469+ savesegment(ss, prev->ss);
27470+ if (unlikely(next->ss != prev->ss))
27471+ loadsegment(ss, next->ss);
27472
27473 /* We must save %fs and %gs before load_TLS() because
27474 * %fs and %gs may be cleared by load_TLS().
27475@@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27476 prev->usersp = this_cpu_read(old_rsp);
27477 this_cpu_write(old_rsp, next->usersp);
27478 this_cpu_write(current_task, next_p);
27479+ this_cpu_write(current_tinfo, &next_p->tinfo);
27480
27481 /*
27482 * If it were not for PREEMPT_ACTIVE we could guarantee that the
27483@@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27484 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
27485 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
27486
27487- this_cpu_write(kernel_stack,
27488- (unsigned long)task_stack_page(next_p) +
27489- THREAD_SIZE - KERNEL_STACK_OFFSET);
27490+ this_cpu_write(kernel_stack, next->sp0);
27491
27492 /*
27493 * Now maybe reload the debug registers and handle I/O bitmaps
27494@@ -443,12 +448,11 @@ unsigned long get_wchan(struct task_struct *p)
27495 if (!p || p == current || p->state == TASK_RUNNING)
27496 return 0;
27497 stack = (unsigned long)task_stack_page(p);
27498- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
27499+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
27500 return 0;
27501 fp = *(u64 *)(p->thread.sp);
27502 do {
27503- if (fp < (unsigned long)stack ||
27504- fp >= (unsigned long)stack+THREAD_SIZE)
27505+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
27506 return 0;
27507 ip = *(u64 *)(fp+8);
27508 if (!in_sched_functions(ip))
27509diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
27510index b1a5dfa..ed94526 100644
27511--- a/arch/x86/kernel/ptrace.c
27512+++ b/arch/x86/kernel/ptrace.c
27513@@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
27514 unsigned long sp = (unsigned long)&regs->sp;
27515 u32 *prev_esp;
27516
27517- if (context == (sp & ~(THREAD_SIZE - 1)))
27518+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
27519 return sp;
27520
27521- prev_esp = (u32 *)(context);
27522+ prev_esp = *(u32 **)(context);
27523 if (prev_esp)
27524 return (unsigned long)prev_esp;
27525
27526@@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
27527 if (child->thread.gs != value)
27528 return do_arch_prctl(child, ARCH_SET_GS, value);
27529 return 0;
27530+
27531+ case offsetof(struct user_regs_struct,ip):
27532+ /*
27533+ * Protect against any attempt to set ip to an
27534+ * impossible address. There are dragons lurking if the
27535+ * address is noncanonical. (This explicitly allows
27536+ * setting ip to TASK_SIZE_MAX, because user code can do
27537+ * that all by itself by running off the end of its
27538+ * address space.
27539+ */
27540+ if (value > TASK_SIZE_MAX)
27541+ return -EIO;
27542+ break;
27543+
27544 #endif
27545 }
27546
27547@@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
27548 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
27549 {
27550 int i;
27551- int dr7 = 0;
27552+ unsigned long dr7 = 0;
27553 struct arch_hw_breakpoint *info;
27554
27555 for (i = 0; i < HBP_NUM; i++) {
27556@@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
27557 unsigned long addr, unsigned long data)
27558 {
27559 int ret;
27560- unsigned long __user *datap = (unsigned long __user *)data;
27561+ unsigned long __user *datap = (__force unsigned long __user *)data;
27562
27563 switch (request) {
27564 /* read the word at location addr in the USER area. */
27565@@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
27566 if ((int) addr < 0)
27567 return -EIO;
27568 ret = do_get_thread_area(child, addr,
27569- (struct user_desc __user *)data);
27570+ (__force struct user_desc __user *) data);
27571 break;
27572
27573 case PTRACE_SET_THREAD_AREA:
27574 if ((int) addr < 0)
27575 return -EIO;
27576 ret = do_set_thread_area(child, addr,
27577- (struct user_desc __user *)data, 0);
27578+ (__force struct user_desc __user *) data, 0);
27579 break;
27580 #endif
27581
27582@@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
27583
27584 #ifdef CONFIG_X86_64
27585
27586-static struct user_regset x86_64_regsets[] __read_mostly = {
27587+static user_regset_no_const x86_64_regsets[] __read_only = {
27588 [REGSET_GENERAL] = {
27589 .core_note_type = NT_PRSTATUS,
27590 .n = sizeof(struct user_regs_struct) / sizeof(long),
27591@@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
27592 #endif /* CONFIG_X86_64 */
27593
27594 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
27595-static struct user_regset x86_32_regsets[] __read_mostly = {
27596+static user_regset_no_const x86_32_regsets[] __read_only = {
27597 [REGSET_GENERAL] = {
27598 .core_note_type = NT_PRSTATUS,
27599 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
27600@@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
27601 */
27602 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
27603
27604-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
27605+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
27606 {
27607 #ifdef CONFIG_X86_64
27608 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
27609@@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
27610 memset(info, 0, sizeof(*info));
27611 info->si_signo = SIGTRAP;
27612 info->si_code = si_code;
27613- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
27614+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
27615 }
27616
27617 void user_single_step_siginfo(struct task_struct *tsk,
27618@@ -1441,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
27619 force_sig_info(SIGTRAP, &info, tsk);
27620 }
27621
27622+#ifdef CONFIG_GRKERNSEC_SETXID
27623+extern void gr_delayed_cred_worker(void);
27624+#endif
27625+
27626 /*
27627 * We must return the syscall number to actually look up in the table.
27628 * This can be -1L to skip running any syscall at all.
27629@@ -1451,6 +1469,11 @@ long syscall_trace_enter(struct pt_regs *regs)
27630
27631 user_exit();
27632
27633+#ifdef CONFIG_GRKERNSEC_SETXID
27634+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
27635+ gr_delayed_cred_worker();
27636+#endif
27637+
27638 /*
27639 * If we stepped into a sysenter/syscall insn, it trapped in
27640 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
27641@@ -1506,6 +1529,11 @@ void syscall_trace_leave(struct pt_regs *regs)
27642 */
27643 user_exit();
27644
27645+#ifdef CONFIG_GRKERNSEC_SETXID
27646+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
27647+ gr_delayed_cred_worker();
27648+#endif
27649+
27650 audit_syscall_exit(regs);
27651
27652 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
27653diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
27654index 2f355d2..e75ed0a 100644
27655--- a/arch/x86/kernel/pvclock.c
27656+++ b/arch/x86/kernel/pvclock.c
27657@@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
27658 reset_hung_task_detector();
27659 }
27660
27661-static atomic64_t last_value = ATOMIC64_INIT(0);
27662+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
27663
27664 void pvclock_resume(void)
27665 {
27666- atomic64_set(&last_value, 0);
27667+ atomic64_set_unchecked(&last_value, 0);
27668 }
27669
27670 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
27671@@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
27672 * updating at the same time, and one of them could be slightly behind,
27673 * making the assumption that last_value always go forward fail to hold.
27674 */
27675- last = atomic64_read(&last_value);
27676+ last = atomic64_read_unchecked(&last_value);
27677 do {
27678 if (ret < last)
27679 return last;
27680- last = atomic64_cmpxchg(&last_value, last, ret);
27681+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
27682 } while (unlikely(last != ret));
27683
27684 return ret;
27685diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
27686index 17962e6..47f55db 100644
27687--- a/arch/x86/kernel/reboot.c
27688+++ b/arch/x86/kernel/reboot.c
27689@@ -69,6 +69,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
27690
27691 void __noreturn machine_real_restart(unsigned int type)
27692 {
27693+
27694+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
27695+ struct desc_struct *gdt;
27696+#endif
27697+
27698 local_irq_disable();
27699
27700 /*
27701@@ -96,7 +101,29 @@ void __noreturn machine_real_restart(unsigned int type)
27702
27703 /* Jump to the identity-mapped low memory code */
27704 #ifdef CONFIG_X86_32
27705- asm volatile("jmpl *%0" : :
27706+
27707+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
27708+ gdt = get_cpu_gdt_table(smp_processor_id());
27709+ pax_open_kernel();
27710+#ifdef CONFIG_PAX_MEMORY_UDEREF
27711+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
27712+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
27713+ loadsegment(ds, __KERNEL_DS);
27714+ loadsegment(es, __KERNEL_DS);
27715+ loadsegment(ss, __KERNEL_DS);
27716+#endif
27717+#ifdef CONFIG_PAX_KERNEXEC
27718+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
27719+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
27720+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
27721+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
27722+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
27723+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
27724+#endif
27725+ pax_close_kernel();
27726+#endif
27727+
27728+ asm volatile("ljmpl *%0" : :
27729 "rm" (real_mode_header->machine_real_restart_asm),
27730 "a" (type));
27731 #else
27732@@ -500,7 +527,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
27733 * This means that this function can never return, it can misbehave
27734 * by not rebooting properly and hanging.
27735 */
27736-static void native_machine_emergency_restart(void)
27737+static void __noreturn native_machine_emergency_restart(void)
27738 {
27739 int i;
27740 int attempt = 0;
27741@@ -620,13 +647,13 @@ void native_machine_shutdown(void)
27742 #endif
27743 }
27744
27745-static void __machine_emergency_restart(int emergency)
27746+static void __noreturn __machine_emergency_restart(int emergency)
27747 {
27748 reboot_emergency = emergency;
27749 machine_ops.emergency_restart();
27750 }
27751
27752-static void native_machine_restart(char *__unused)
27753+static void __noreturn native_machine_restart(char *__unused)
27754 {
27755 pr_notice("machine restart\n");
27756
27757@@ -635,7 +662,7 @@ static void native_machine_restart(char *__unused)
27758 __machine_emergency_restart(0);
27759 }
27760
27761-static void native_machine_halt(void)
27762+static void __noreturn native_machine_halt(void)
27763 {
27764 /* Stop other cpus and apics */
27765 machine_shutdown();
27766@@ -645,7 +672,7 @@ static void native_machine_halt(void)
27767 stop_this_cpu(NULL);
27768 }
27769
27770-static void native_machine_power_off(void)
27771+static void __noreturn native_machine_power_off(void)
27772 {
27773 if (pm_power_off) {
27774 if (!reboot_force)
27775@@ -654,9 +681,10 @@ static void native_machine_power_off(void)
27776 }
27777 /* A fallback in case there is no PM info available */
27778 tboot_shutdown(TB_SHUTDOWN_HALT);
27779+ unreachable();
27780 }
27781
27782-struct machine_ops machine_ops = {
27783+struct machine_ops machine_ops __read_only = {
27784 .power_off = native_machine_power_off,
27785 .shutdown = native_machine_shutdown,
27786 .emergency_restart = native_machine_emergency_restart,
27787diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
27788index c8e41e9..64049ef 100644
27789--- a/arch/x86/kernel/reboot_fixups_32.c
27790+++ b/arch/x86/kernel/reboot_fixups_32.c
27791@@ -57,7 +57,7 @@ struct device_fixup {
27792 unsigned int vendor;
27793 unsigned int device;
27794 void (*reboot_fixup)(struct pci_dev *);
27795-};
27796+} __do_const;
27797
27798 /*
27799 * PCI ids solely used for fixups_table go here
27800diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
27801index 3fd2c69..a444264 100644
27802--- a/arch/x86/kernel/relocate_kernel_64.S
27803+++ b/arch/x86/kernel/relocate_kernel_64.S
27804@@ -96,8 +96,7 @@ relocate_kernel:
27805
27806 /* jump to identity mapped page */
27807 addq $(identity_mapped - relocate_kernel), %r8
27808- pushq %r8
27809- ret
27810+ jmp *%r8
27811
27812 identity_mapped:
27813 /* set return address to 0 if not preserving context */
27814diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
27815index 41ead8d..7ccde23 100644
27816--- a/arch/x86/kernel/setup.c
27817+++ b/arch/x86/kernel/setup.c
27818@@ -110,6 +110,7 @@
27819 #include <asm/mce.h>
27820 #include <asm/alternative.h>
27821 #include <asm/prom.h>
27822+#include <asm/boot.h>
27823
27824 /*
27825 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
27826@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
27827 #endif
27828
27829
27830-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
27831-__visible unsigned long mmu_cr4_features;
27832+#ifdef CONFIG_X86_64
27833+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
27834+#elif defined(CONFIG_X86_PAE)
27835+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
27836 #else
27837-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27838+__visible unsigned long mmu_cr4_features __read_only;
27839 #endif
27840
27841+void set_in_cr4(unsigned long mask)
27842+{
27843+ unsigned long cr4 = read_cr4();
27844+
27845+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27846+ return;
27847+
27848+ pax_open_kernel();
27849+ mmu_cr4_features |= mask;
27850+ pax_close_kernel();
27851+
27852+ if (trampoline_cr4_features)
27853+ *trampoline_cr4_features = mmu_cr4_features;
27854+ cr4 |= mask;
27855+ write_cr4(cr4);
27856+}
27857+EXPORT_SYMBOL(set_in_cr4);
27858+
27859+void clear_in_cr4(unsigned long mask)
27860+{
27861+ unsigned long cr4 = read_cr4();
27862+
27863+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27864+ return;
27865+
27866+ pax_open_kernel();
27867+ mmu_cr4_features &= ~mask;
27868+ pax_close_kernel();
27869+
27870+ if (trampoline_cr4_features)
27871+ *trampoline_cr4_features = mmu_cr4_features;
27872+ cr4 &= ~mask;
27873+ write_cr4(cr4);
27874+}
27875+EXPORT_SYMBOL(clear_in_cr4);
27876+
27877 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27878 int bootloader_type, bootloader_version;
27879
27880@@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27881 * area (640->1Mb) as ram even though it is not.
27882 * take them out.
27883 */
27884- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27885+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27886
27887 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27888 }
27889@@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27890 /* called before trim_bios_range() to spare extra sanitize */
27891 static void __init e820_add_kernel_range(void)
27892 {
27893- u64 start = __pa_symbol(_text);
27894+ u64 start = __pa_symbol(ktla_ktva(_text));
27895 u64 size = __pa_symbol(_end) - start;
27896
27897 /*
27898@@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27899
27900 void __init setup_arch(char **cmdline_p)
27901 {
27902+#ifdef CONFIG_X86_32
27903+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27904+#else
27905 memblock_reserve(__pa_symbol(_text),
27906 (unsigned long)__bss_stop - (unsigned long)_text);
27907+#endif
27908
27909 early_reserve_initrd();
27910
27911@@ -946,14 +989,14 @@ void __init setup_arch(char **cmdline_p)
27912
27913 if (!boot_params.hdr.root_flags)
27914 root_mountflags &= ~MS_RDONLY;
27915- init_mm.start_code = (unsigned long) _text;
27916- init_mm.end_code = (unsigned long) _etext;
27917+ init_mm.start_code = ktla_ktva((unsigned long) _text);
27918+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
27919 init_mm.end_data = (unsigned long) _edata;
27920 init_mm.brk = _brk_end;
27921
27922- code_resource.start = __pa_symbol(_text);
27923- code_resource.end = __pa_symbol(_etext)-1;
27924- data_resource.start = __pa_symbol(_etext);
27925+ code_resource.start = __pa_symbol(ktla_ktva(_text));
27926+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27927+ data_resource.start = __pa_symbol(_sdata);
27928 data_resource.end = __pa_symbol(_edata)-1;
27929 bss_resource.start = __pa_symbol(__bss_start);
27930 bss_resource.end = __pa_symbol(__bss_stop)-1;
27931diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27932index 5cdff03..80fa283 100644
27933--- a/arch/x86/kernel/setup_percpu.c
27934+++ b/arch/x86/kernel/setup_percpu.c
27935@@ -21,19 +21,17 @@
27936 #include <asm/cpu.h>
27937 #include <asm/stackprotector.h>
27938
27939-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27940+#ifdef CONFIG_SMP
27941+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27942 EXPORT_PER_CPU_SYMBOL(cpu_number);
27943+#endif
27944
27945-#ifdef CONFIG_X86_64
27946 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27947-#else
27948-#define BOOT_PERCPU_OFFSET 0
27949-#endif
27950
27951 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27952 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27953
27954-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27955+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27956 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27957 };
27958 EXPORT_SYMBOL(__per_cpu_offset);
27959@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27960 {
27961 #ifdef CONFIG_NEED_MULTIPLE_NODES
27962 pg_data_t *last = NULL;
27963- unsigned int cpu;
27964+ int cpu;
27965
27966 for_each_possible_cpu(cpu) {
27967 int node = early_cpu_to_node(cpu);
27968@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27969 {
27970 #ifdef CONFIG_X86_32
27971 struct desc_struct gdt;
27972+ unsigned long base = per_cpu_offset(cpu);
27973
27974- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27975- 0x2 | DESCTYPE_S, 0x8);
27976- gdt.s = 1;
27977+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27978+ 0x83 | DESCTYPE_S, 0xC);
27979 write_gdt_entry(get_cpu_gdt_table(cpu),
27980 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27981 #endif
27982@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27983 /* alrighty, percpu areas up and running */
27984 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27985 for_each_possible_cpu(cpu) {
27986+#ifdef CONFIG_CC_STACKPROTECTOR
27987+#ifdef CONFIG_X86_32
27988+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
27989+#endif
27990+#endif
27991 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27992 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27993 per_cpu(cpu_number, cpu) = cpu;
27994@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27995 */
27996 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27997 #endif
27998+#ifdef CONFIG_CC_STACKPROTECTOR
27999+#ifdef CONFIG_X86_32
28000+ if (!cpu)
28001+ per_cpu(stack_canary.canary, cpu) = canary;
28002+#endif
28003+#endif
28004 /*
28005 * Up to this point, the boot CPU has been using .init.data
28006 * area. Reload any changed state for the boot CPU.
28007diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
28008index ed37a76..39f936e 100644
28009--- a/arch/x86/kernel/signal.c
28010+++ b/arch/x86/kernel/signal.c
28011@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
28012 * Align the stack pointer according to the i386 ABI,
28013 * i.e. so that on function entry ((sp + 4) & 15) == 0.
28014 */
28015- sp = ((sp + 4) & -16ul) - 4;
28016+ sp = ((sp - 12) & -16ul) - 4;
28017 #else /* !CONFIG_X86_32 */
28018 sp = round_down(sp, 16) - 8;
28019 #endif
28020@@ -298,10 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
28021 }
28022
28023 if (current->mm->context.vdso)
28024- restorer = current->mm->context.vdso +
28025- selected_vdso32->sym___kernel_sigreturn;
28026+ restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_sigreturn);
28027 else
28028- restorer = &frame->retcode;
28029+ restorer = (void __user *)&frame->retcode;
28030 if (ksig->ka.sa.sa_flags & SA_RESTORER)
28031 restorer = ksig->ka.sa.sa_restorer;
28032
28033@@ -315,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
28034 * reasons and because gdb uses it as a signature to notice
28035 * signal handler stack frames.
28036 */
28037- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
28038+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
28039
28040 if (err)
28041 return -EFAULT;
28042@@ -362,8 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
28043 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
28044
28045 /* Set up to return from userspace. */
28046- restorer = current->mm->context.vdso +
28047- selected_vdso32->sym___kernel_rt_sigreturn;
28048+ if (current->mm->context.vdso)
28049+ restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_rt_sigreturn);
28050+ else
28051+ restorer = (void __user *)&frame->retcode;
28052 if (ksig->ka.sa.sa_flags & SA_RESTORER)
28053 restorer = ksig->ka.sa.sa_restorer;
28054 put_user_ex(restorer, &frame->pretcode);
28055@@ -375,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
28056 * reasons and because gdb uses it as a signature to notice
28057 * signal handler stack frames.
28058 */
28059- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
28060+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
28061 } put_user_catch(err);
28062
28063 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
28064@@ -611,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
28065 {
28066 int usig = signr_convert(ksig->sig);
28067 sigset_t *set = sigmask_to_save();
28068- compat_sigset_t *cset = (compat_sigset_t *) set;
28069+ sigset_t sigcopy;
28070+ compat_sigset_t *cset;
28071+
28072+ sigcopy = *set;
28073+
28074+ cset = (compat_sigset_t *) &sigcopy;
28075
28076 /* Set up the stack frame */
28077 if (is_ia32_frame()) {
28078@@ -622,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
28079 } else if (is_x32_frame()) {
28080 return x32_setup_rt_frame(ksig, cset, regs);
28081 } else {
28082- return __setup_rt_frame(ksig->sig, ksig, set, regs);
28083+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
28084 }
28085 }
28086
28087diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
28088index be8e1bd..a3d93fa 100644
28089--- a/arch/x86/kernel/smp.c
28090+++ b/arch/x86/kernel/smp.c
28091@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
28092
28093 __setup("nonmi_ipi", nonmi_ipi_setup);
28094
28095-struct smp_ops smp_ops = {
28096+struct smp_ops smp_ops __read_only = {
28097 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
28098 .smp_prepare_cpus = native_smp_prepare_cpus,
28099 .smp_cpus_done = native_smp_cpus_done,
28100diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
28101index 42a2dca..35a07aa 100644
28102--- a/arch/x86/kernel/smpboot.c
28103+++ b/arch/x86/kernel/smpboot.c
28104@@ -226,14 +226,17 @@ static void notrace start_secondary(void *unused)
28105
28106 enable_start_cpu0 = 0;
28107
28108-#ifdef CONFIG_X86_32
28109+ /* otherwise gcc will move up smp_processor_id before the cpu_init */
28110+ barrier();
28111+
28112 /* switch away from the initial page table */
28113+#ifdef CONFIG_PAX_PER_CPU_PGD
28114+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
28115+#else
28116 load_cr3(swapper_pg_dir);
28117+#endif
28118 __flush_tlb_all();
28119-#endif
28120
28121- /* otherwise gcc will move up smp_processor_id before the cpu_init */
28122- barrier();
28123 /*
28124 * Check TSC synchronization with the BP:
28125 */
28126@@ -760,8 +763,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
28127 alternatives_enable_smp();
28128
28129 idle->thread.sp = (unsigned long) (((struct pt_regs *)
28130- (THREAD_SIZE + task_stack_page(idle))) - 1);
28131+ (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
28132 per_cpu(current_task, cpu) = idle;
28133+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
28134
28135 #ifdef CONFIG_X86_32
28136 /* Stack for startup_32 can be just as for start_secondary onwards */
28137@@ -770,10 +774,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
28138 clear_tsk_thread_flag(idle, TIF_FORK);
28139 initial_gs = per_cpu_offset(cpu);
28140 #endif
28141- per_cpu(kernel_stack, cpu) =
28142- (unsigned long)task_stack_page(idle) -
28143- KERNEL_STACK_OFFSET + THREAD_SIZE;
28144+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
28145+ pax_open_kernel();
28146 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
28147+ pax_close_kernel();
28148 initial_code = (unsigned long)start_secondary;
28149 stack_start = idle->thread.sp;
28150
28151@@ -919,6 +923,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
28152 /* the FPU context is blank, nobody can own it */
28153 __cpu_disable_lazy_restore(cpu);
28154
28155+#ifdef CONFIG_PAX_PER_CPU_PGD
28156+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
28157+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28158+ KERNEL_PGD_PTRS);
28159+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
28160+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28161+ KERNEL_PGD_PTRS);
28162+#endif
28163+
28164 err = do_boot_cpu(apicid, cpu, tidle);
28165 if (err) {
28166 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
28167diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
28168index 9b4d51d..5d28b58 100644
28169--- a/arch/x86/kernel/step.c
28170+++ b/arch/x86/kernel/step.c
28171@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
28172 struct desc_struct *desc;
28173 unsigned long base;
28174
28175- seg &= ~7UL;
28176+ seg >>= 3;
28177
28178 mutex_lock(&child->mm->context.lock);
28179- if (unlikely((seg >> 3) >= child->mm->context.size))
28180+ if (unlikely(seg >= child->mm->context.size))
28181 addr = -1L; /* bogus selector, access would fault */
28182 else {
28183 desc = child->mm->context.ldt + seg;
28184@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
28185 addr += base;
28186 }
28187 mutex_unlock(&child->mm->context.lock);
28188- }
28189+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
28190+ addr = ktla_ktva(addr);
28191
28192 return addr;
28193 }
28194@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
28195 unsigned char opcode[15];
28196 unsigned long addr = convert_ip_to_linear(child, regs);
28197
28198+ if (addr == -EINVAL)
28199+ return 0;
28200+
28201 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
28202 for (i = 0; i < copied; i++) {
28203 switch (opcode[i]) {
28204diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
28205new file mode 100644
28206index 0000000..5877189
28207--- /dev/null
28208+++ b/arch/x86/kernel/sys_i386_32.c
28209@@ -0,0 +1,189 @@
28210+/*
28211+ * This file contains various random system calls that
28212+ * have a non-standard calling sequence on the Linux/i386
28213+ * platform.
28214+ */
28215+
28216+#include <linux/errno.h>
28217+#include <linux/sched.h>
28218+#include <linux/mm.h>
28219+#include <linux/fs.h>
28220+#include <linux/smp.h>
28221+#include <linux/sem.h>
28222+#include <linux/msg.h>
28223+#include <linux/shm.h>
28224+#include <linux/stat.h>
28225+#include <linux/syscalls.h>
28226+#include <linux/mman.h>
28227+#include <linux/file.h>
28228+#include <linux/utsname.h>
28229+#include <linux/ipc.h>
28230+#include <linux/elf.h>
28231+
28232+#include <linux/uaccess.h>
28233+#include <linux/unistd.h>
28234+
28235+#include <asm/syscalls.h>
28236+
28237+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
28238+{
28239+ unsigned long pax_task_size = TASK_SIZE;
28240+
28241+#ifdef CONFIG_PAX_SEGMEXEC
28242+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
28243+ pax_task_size = SEGMEXEC_TASK_SIZE;
28244+#endif
28245+
28246+ if (flags & MAP_FIXED)
28247+ if (len > pax_task_size || addr > pax_task_size - len)
28248+ return -EINVAL;
28249+
28250+ return 0;
28251+}
28252+
28253+/*
28254+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
28255+ */
28256+static unsigned long get_align_mask(void)
28257+{
28258+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
28259+ return 0;
28260+
28261+ if (!(current->flags & PF_RANDOMIZE))
28262+ return 0;
28263+
28264+ return va_align.mask;
28265+}
28266+
28267+unsigned long
28268+arch_get_unmapped_area(struct file *filp, unsigned long addr,
28269+ unsigned long len, unsigned long pgoff, unsigned long flags)
28270+{
28271+ struct mm_struct *mm = current->mm;
28272+ struct vm_area_struct *vma;
28273+ unsigned long pax_task_size = TASK_SIZE;
28274+ struct vm_unmapped_area_info info;
28275+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
28276+
28277+#ifdef CONFIG_PAX_SEGMEXEC
28278+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28279+ pax_task_size = SEGMEXEC_TASK_SIZE;
28280+#endif
28281+
28282+ pax_task_size -= PAGE_SIZE;
28283+
28284+ if (len > pax_task_size)
28285+ return -ENOMEM;
28286+
28287+ if (flags & MAP_FIXED)
28288+ return addr;
28289+
28290+#ifdef CONFIG_PAX_RANDMMAP
28291+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28292+#endif
28293+
28294+ if (addr) {
28295+ addr = PAGE_ALIGN(addr);
28296+ if (pax_task_size - len >= addr) {
28297+ vma = find_vma(mm, addr);
28298+ if (check_heap_stack_gap(vma, addr, len, offset))
28299+ return addr;
28300+ }
28301+ }
28302+
28303+ info.flags = 0;
28304+ info.length = len;
28305+ info.align_mask = filp ? get_align_mask() : 0;
28306+ info.align_offset = pgoff << PAGE_SHIFT;
28307+ info.threadstack_offset = offset;
28308+
28309+#ifdef CONFIG_PAX_PAGEEXEC
28310+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
28311+ info.low_limit = 0x00110000UL;
28312+ info.high_limit = mm->start_code;
28313+
28314+#ifdef CONFIG_PAX_RANDMMAP
28315+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28316+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
28317+#endif
28318+
28319+ if (info.low_limit < info.high_limit) {
28320+ addr = vm_unmapped_area(&info);
28321+ if (!IS_ERR_VALUE(addr))
28322+ return addr;
28323+ }
28324+ } else
28325+#endif
28326+
28327+ info.low_limit = mm->mmap_base;
28328+ info.high_limit = pax_task_size;
28329+
28330+ return vm_unmapped_area(&info);
28331+}
28332+
28333+unsigned long
28334+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
28335+ const unsigned long len, const unsigned long pgoff,
28336+ const unsigned long flags)
28337+{
28338+ struct vm_area_struct *vma;
28339+ struct mm_struct *mm = current->mm;
28340+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
28341+ struct vm_unmapped_area_info info;
28342+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
28343+
28344+#ifdef CONFIG_PAX_SEGMEXEC
28345+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28346+ pax_task_size = SEGMEXEC_TASK_SIZE;
28347+#endif
28348+
28349+ pax_task_size -= PAGE_SIZE;
28350+
28351+ /* requested length too big for entire address space */
28352+ if (len > pax_task_size)
28353+ return -ENOMEM;
28354+
28355+ if (flags & MAP_FIXED)
28356+ return addr;
28357+
28358+#ifdef CONFIG_PAX_PAGEEXEC
28359+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
28360+ goto bottomup;
28361+#endif
28362+
28363+#ifdef CONFIG_PAX_RANDMMAP
28364+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28365+#endif
28366+
28367+ /* requesting a specific address */
28368+ if (addr) {
28369+ addr = PAGE_ALIGN(addr);
28370+ if (pax_task_size - len >= addr) {
28371+ vma = find_vma(mm, addr);
28372+ if (check_heap_stack_gap(vma, addr, len, offset))
28373+ return addr;
28374+ }
28375+ }
28376+
28377+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
28378+ info.length = len;
28379+ info.low_limit = PAGE_SIZE;
28380+ info.high_limit = mm->mmap_base;
28381+ info.align_mask = filp ? get_align_mask() : 0;
28382+ info.align_offset = pgoff << PAGE_SHIFT;
28383+ info.threadstack_offset = offset;
28384+
28385+ addr = vm_unmapped_area(&info);
28386+ if (!(addr & ~PAGE_MASK))
28387+ return addr;
28388+ VM_BUG_ON(addr != -ENOMEM);
28389+
28390+bottomup:
28391+ /*
28392+ * A failed mmap() very likely causes application failure,
28393+ * so fall back to the bottom-up function here. This scenario
28394+ * can happen with large stack limits and large mmap()
28395+ * allocations.
28396+ */
28397+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
28398+}
28399diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
28400index 30277e2..5664a29 100644
28401--- a/arch/x86/kernel/sys_x86_64.c
28402+++ b/arch/x86/kernel/sys_x86_64.c
28403@@ -81,8 +81,8 @@ out:
28404 return error;
28405 }
28406
28407-static void find_start_end(unsigned long flags, unsigned long *begin,
28408- unsigned long *end)
28409+static void find_start_end(struct mm_struct *mm, unsigned long flags,
28410+ unsigned long *begin, unsigned long *end)
28411 {
28412 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
28413 unsigned long new_begin;
28414@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
28415 *begin = new_begin;
28416 }
28417 } else {
28418- *begin = current->mm->mmap_legacy_base;
28419+ *begin = mm->mmap_legacy_base;
28420 *end = TASK_SIZE;
28421 }
28422 }
28423@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
28424 struct vm_area_struct *vma;
28425 struct vm_unmapped_area_info info;
28426 unsigned long begin, end;
28427+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
28428
28429 if (flags & MAP_FIXED)
28430 return addr;
28431
28432- find_start_end(flags, &begin, &end);
28433+ find_start_end(mm, flags, &begin, &end);
28434
28435 if (len > end)
28436 return -ENOMEM;
28437
28438+#ifdef CONFIG_PAX_RANDMMAP
28439+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28440+#endif
28441+
28442 if (addr) {
28443 addr = PAGE_ALIGN(addr);
28444 vma = find_vma(mm, addr);
28445- if (end - len >= addr &&
28446- (!vma || addr + len <= vma->vm_start))
28447+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
28448 return addr;
28449 }
28450
28451@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
28452 info.high_limit = end;
28453 info.align_mask = filp ? get_align_mask() : 0;
28454 info.align_offset = pgoff << PAGE_SHIFT;
28455+ info.threadstack_offset = offset;
28456 return vm_unmapped_area(&info);
28457 }
28458
28459@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
28460 struct mm_struct *mm = current->mm;
28461 unsigned long addr = addr0;
28462 struct vm_unmapped_area_info info;
28463+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
28464
28465 /* requested length too big for entire address space */
28466 if (len > TASK_SIZE)
28467@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
28468 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
28469 goto bottomup;
28470
28471+#ifdef CONFIG_PAX_RANDMMAP
28472+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28473+#endif
28474+
28475 /* requesting a specific address */
28476 if (addr) {
28477 addr = PAGE_ALIGN(addr);
28478 vma = find_vma(mm, addr);
28479- if (TASK_SIZE - len >= addr &&
28480- (!vma || addr + len <= vma->vm_start))
28481+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
28482 return addr;
28483 }
28484
28485@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
28486 info.high_limit = mm->mmap_base;
28487 info.align_mask = filp ? get_align_mask() : 0;
28488 info.align_offset = pgoff << PAGE_SHIFT;
28489+ info.threadstack_offset = offset;
28490 addr = vm_unmapped_area(&info);
28491 if (!(addr & ~PAGE_MASK))
28492 return addr;
28493diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
28494index 91a4496..bb87552 100644
28495--- a/arch/x86/kernel/tboot.c
28496+++ b/arch/x86/kernel/tboot.c
28497@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
28498
28499 void tboot_shutdown(u32 shutdown_type)
28500 {
28501- void (*shutdown)(void);
28502+ void (* __noreturn shutdown)(void);
28503
28504 if (!tboot_enabled())
28505 return;
28506@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
28507
28508 switch_to_tboot_pt();
28509
28510- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
28511+ shutdown = (void *)(unsigned long)tboot->shutdown_entry;
28512 shutdown();
28513
28514 /* should not reach here */
28515@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
28516 return -ENODEV;
28517 }
28518
28519-static atomic_t ap_wfs_count;
28520+static atomic_unchecked_t ap_wfs_count;
28521
28522 static int tboot_wait_for_aps(int num_aps)
28523 {
28524@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
28525 {
28526 switch (action) {
28527 case CPU_DYING:
28528- atomic_inc(&ap_wfs_count);
28529+ atomic_inc_unchecked(&ap_wfs_count);
28530 if (num_online_cpus() == 1)
28531- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
28532+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
28533 return NOTIFY_BAD;
28534 break;
28535 }
28536@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
28537
28538 tboot_create_trampoline();
28539
28540- atomic_set(&ap_wfs_count, 0);
28541+ atomic_set_unchecked(&ap_wfs_count, 0);
28542 register_hotcpu_notifier(&tboot_cpu_notifier);
28543
28544 #ifdef CONFIG_DEBUG_FS
28545diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
28546index 0fa2960..91eabbe 100644
28547--- a/arch/x86/kernel/time.c
28548+++ b/arch/x86/kernel/time.c
28549@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
28550 {
28551 unsigned long pc = instruction_pointer(regs);
28552
28553- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
28554+ if (!user_mode(regs) && in_lock_functions(pc)) {
28555 #ifdef CONFIG_FRAME_POINTER
28556- return *(unsigned long *)(regs->bp + sizeof(long));
28557+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
28558 #else
28559 unsigned long *sp =
28560 (unsigned long *)kernel_stack_pointer(regs);
28561@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
28562 * or above a saved flags. Eflags has bits 22-31 zero,
28563 * kernel addresses don't.
28564 */
28565+
28566+#ifdef CONFIG_PAX_KERNEXEC
28567+ return ktla_ktva(sp[0]);
28568+#else
28569 if (sp[0] >> 22)
28570 return sp[0];
28571 if (sp[1] >> 22)
28572 return sp[1];
28573 #endif
28574+
28575+#endif
28576 }
28577 return pc;
28578 }
28579diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
28580index f7fec09..9991981 100644
28581--- a/arch/x86/kernel/tls.c
28582+++ b/arch/x86/kernel/tls.c
28583@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
28584 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
28585 return -EINVAL;
28586
28587+#ifdef CONFIG_PAX_SEGMEXEC
28588+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
28589+ return -EINVAL;
28590+#endif
28591+
28592 set_tls_desc(p, idx, &info, 1);
28593
28594 return 0;
28595@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
28596
28597 if (kbuf)
28598 info = kbuf;
28599- else if (__copy_from_user(infobuf, ubuf, count))
28600+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
28601 return -EFAULT;
28602 else
28603 info = infobuf;
28604diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
28605index 1c113db..287b42e 100644
28606--- a/arch/x86/kernel/tracepoint.c
28607+++ b/arch/x86/kernel/tracepoint.c
28608@@ -9,11 +9,11 @@
28609 #include <linux/atomic.h>
28610
28611 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
28612-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
28613+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
28614 (unsigned long) trace_idt_table };
28615
28616 /* No need to be aligned, but done to keep all IDTs defined the same way. */
28617-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
28618+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
28619
28620 static int trace_irq_vector_refcount;
28621 static DEFINE_MUTEX(irq_vector_mutex);
28622diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
28623index de801f2..f189dcf 100644
28624--- a/arch/x86/kernel/traps.c
28625+++ b/arch/x86/kernel/traps.c
28626@@ -67,7 +67,7 @@
28627 #include <asm/proto.h>
28628
28629 /* No need to be aligned, but done to keep all IDTs defined the same way. */
28630-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
28631+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
28632 #else
28633 #include <asm/processor-flags.h>
28634 #include <asm/setup.h>
28635@@ -76,7 +76,7 @@ asmlinkage int system_call(void);
28636 #endif
28637
28638 /* Must be page-aligned because the real IDT is used in a fixmap. */
28639-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
28640+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
28641
28642 DECLARE_BITMAP(used_vectors, NR_VECTORS);
28643 EXPORT_SYMBOL_GPL(used_vectors);
28644@@ -108,11 +108,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
28645 }
28646
28647 static nokprobe_inline int
28648-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
28649+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
28650 struct pt_regs *regs, long error_code)
28651 {
28652 #ifdef CONFIG_X86_32
28653- if (regs->flags & X86_VM_MASK) {
28654+ if (v8086_mode(regs)) {
28655 /*
28656 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
28657 * On nmi (interrupt 2), do_trap should not be called.
28658@@ -125,12 +125,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
28659 return -1;
28660 }
28661 #endif
28662- if (!user_mode(regs)) {
28663+ if (!user_mode_novm(regs)) {
28664 if (!fixup_exception(regs)) {
28665 tsk->thread.error_code = error_code;
28666 tsk->thread.trap_nr = trapnr;
28667+
28668+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28669+ if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
28670+ str = "PAX: suspicious stack segment fault";
28671+#endif
28672+
28673 die(str, regs, error_code);
28674 }
28675+
28676+#ifdef CONFIG_PAX_REFCOUNT
28677+ if (trapnr == X86_TRAP_OF)
28678+ pax_report_refcount_overflow(regs);
28679+#endif
28680+
28681 return 0;
28682 }
28683
28684@@ -169,7 +181,7 @@ static siginfo_t *fill_trap_info(struct pt_regs *regs, int signr, int trapnr,
28685 }
28686
28687 static void
28688-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28689+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
28690 long error_code, siginfo_t *info)
28691 {
28692 struct task_struct *tsk = current;
28693@@ -193,7 +205,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28694 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
28695 printk_ratelimit()) {
28696 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
28697- tsk->comm, tsk->pid, str,
28698+ tsk->comm, task_pid_nr(tsk), str,
28699 regs->ip, regs->sp, error_code);
28700 print_vma_addr(" in ", regs->ip);
28701 pr_cont("\n");
28702@@ -274,6 +286,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
28703 tsk->thread.error_code = error_code;
28704 tsk->thread.trap_nr = X86_TRAP_DF;
28705
28706+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
28707+ if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
28708+ die("grsec: kernel stack overflow detected", regs, error_code);
28709+#endif
28710+
28711 #ifdef CONFIG_DOUBLEFAULT
28712 df_debug(regs, error_code);
28713 #endif
28714@@ -296,7 +313,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
28715 conditional_sti(regs);
28716
28717 #ifdef CONFIG_X86_32
28718- if (regs->flags & X86_VM_MASK) {
28719+ if (v8086_mode(regs)) {
28720 local_irq_enable();
28721 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
28722 goto exit;
28723@@ -304,18 +321,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
28724 #endif
28725
28726 tsk = current;
28727- if (!user_mode(regs)) {
28728+ if (!user_mode_novm(regs)) {
28729 if (fixup_exception(regs))
28730 goto exit;
28731
28732 tsk->thread.error_code = error_code;
28733 tsk->thread.trap_nr = X86_TRAP_GP;
28734 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
28735- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
28736+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
28737+
28738+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28739+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
28740+ die("PAX: suspicious general protection fault", regs, error_code);
28741+ else
28742+#endif
28743+
28744 die("general protection fault", regs, error_code);
28745+ }
28746 goto exit;
28747 }
28748
28749+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
28750+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
28751+ struct mm_struct *mm = tsk->mm;
28752+ unsigned long limit;
28753+
28754+ down_write(&mm->mmap_sem);
28755+ limit = mm->context.user_cs_limit;
28756+ if (limit < TASK_SIZE) {
28757+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
28758+ up_write(&mm->mmap_sem);
28759+ return;
28760+ }
28761+ up_write(&mm->mmap_sem);
28762+ }
28763+#endif
28764+
28765 tsk->thread.error_code = error_code;
28766 tsk->thread.trap_nr = X86_TRAP_GP;
28767
28768@@ -433,7 +474,7 @@ struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s)
28769 /* Copy the remainder of the stack from the current stack. */
28770 memmove(new_stack, s, offsetof(struct bad_iret_stack, regs.ip));
28771
28772- BUG_ON(!user_mode_vm(&new_stack->regs));
28773+ BUG_ON(!user_mode(&new_stack->regs));
28774 return new_stack;
28775 }
28776 #endif
28777@@ -518,7 +559,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28778 /* It's safe to allow irq's after DR6 has been saved */
28779 preempt_conditional_sti(regs);
28780
28781- if (regs->flags & X86_VM_MASK) {
28782+ if (v8086_mode(regs)) {
28783 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
28784 X86_TRAP_DB);
28785 preempt_conditional_cli(regs);
28786@@ -533,7 +574,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28787 * We already checked v86 mode above, so we can check for kernel mode
28788 * by just checking the CPL of CS.
28789 */
28790- if ((dr6 & DR_STEP) && !user_mode(regs)) {
28791+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
28792 tsk->thread.debugreg6 &= ~DR_STEP;
28793 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
28794 regs->flags &= ~X86_EFLAGS_TF;
28795@@ -566,7 +607,7 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)
28796 return;
28797 conditional_sti(regs);
28798
28799- if (!user_mode_vm(regs))
28800+ if (!user_mode(regs))
28801 {
28802 if (!fixup_exception(regs)) {
28803 task->thread.error_code = error_code;
28804diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
28805index b7e50bb..f4a93ae 100644
28806--- a/arch/x86/kernel/tsc.c
28807+++ b/arch/x86/kernel/tsc.c
28808@@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
28809 */
28810 smp_wmb();
28811
28812- ACCESS_ONCE(c2n->head) = data;
28813+ ACCESS_ONCE_RW(c2n->head) = data;
28814 }
28815
28816 /*
28817diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
28818index 5d1cbfe..2a21feb 100644
28819--- a/arch/x86/kernel/uprobes.c
28820+++ b/arch/x86/kernel/uprobes.c
28821@@ -845,7 +845,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
28822 int ret = NOTIFY_DONE;
28823
28824 /* We are only interested in userspace traps */
28825- if (regs && !user_mode_vm(regs))
28826+ if (regs && !user_mode(regs))
28827 return NOTIFY_DONE;
28828
28829 switch (val) {
28830@@ -919,7 +919,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
28831
28832 if (nleft != rasize) {
28833 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
28834- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
28835+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
28836
28837 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
28838 }
28839diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
28840index b9242ba..50c5edd 100644
28841--- a/arch/x86/kernel/verify_cpu.S
28842+++ b/arch/x86/kernel/verify_cpu.S
28843@@ -20,6 +20,7 @@
28844 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
28845 * arch/x86/kernel/trampoline_64.S: secondary processor verification
28846 * arch/x86/kernel/head_32.S: processor startup
28847+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
28848 *
28849 * verify_cpu, returns the status of longmode and SSE in register %eax.
28850 * 0: Success 1: Failure
28851diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
28852index e8edcf5..27f9344 100644
28853--- a/arch/x86/kernel/vm86_32.c
28854+++ b/arch/x86/kernel/vm86_32.c
28855@@ -44,6 +44,7 @@
28856 #include <linux/ptrace.h>
28857 #include <linux/audit.h>
28858 #include <linux/stddef.h>
28859+#include <linux/grsecurity.h>
28860
28861 #include <asm/uaccess.h>
28862 #include <asm/io.h>
28863@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28864 do_exit(SIGSEGV);
28865 }
28866
28867- tss = &per_cpu(init_tss, get_cpu());
28868+ tss = init_tss + get_cpu();
28869 current->thread.sp0 = current->thread.saved_sp0;
28870 current->thread.sysenter_cs = __KERNEL_CS;
28871 load_sp0(tss, &current->thread);
28872@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28873
28874 if (tsk->thread.saved_sp0)
28875 return -EPERM;
28876+
28877+#ifdef CONFIG_GRKERNSEC_VM86
28878+ if (!capable(CAP_SYS_RAWIO)) {
28879+ gr_handle_vm86();
28880+ return -EPERM;
28881+ }
28882+#endif
28883+
28884 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28885 offsetof(struct kernel_vm86_struct, vm86plus) -
28886 sizeof(info.regs));
28887@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28888 int tmp;
28889 struct vm86plus_struct __user *v86;
28890
28891+#ifdef CONFIG_GRKERNSEC_VM86
28892+ if (!capable(CAP_SYS_RAWIO)) {
28893+ gr_handle_vm86();
28894+ return -EPERM;
28895+ }
28896+#endif
28897+
28898 tsk = current;
28899 switch (cmd) {
28900 case VM86_REQUEST_IRQ:
28901@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28902 tsk->thread.saved_fs = info->regs32->fs;
28903 tsk->thread.saved_gs = get_user_gs(info->regs32);
28904
28905- tss = &per_cpu(init_tss, get_cpu());
28906+ tss = init_tss + get_cpu();
28907 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28908 if (cpu_has_sep)
28909 tsk->thread.sysenter_cs = 0;
28910@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28911 goto cannot_handle;
28912 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28913 goto cannot_handle;
28914- intr_ptr = (unsigned long __user *) (i << 2);
28915+ intr_ptr = (__force unsigned long __user *) (i << 2);
28916 if (get_user(segoffs, intr_ptr))
28917 goto cannot_handle;
28918 if ((segoffs >> 16) == BIOSSEG)
28919diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28920index 49edf2d..c0d1362 100644
28921--- a/arch/x86/kernel/vmlinux.lds.S
28922+++ b/arch/x86/kernel/vmlinux.lds.S
28923@@ -26,6 +26,13 @@
28924 #include <asm/page_types.h>
28925 #include <asm/cache.h>
28926 #include <asm/boot.h>
28927+#include <asm/segment.h>
28928+
28929+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28930+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28931+#else
28932+#define __KERNEL_TEXT_OFFSET 0
28933+#endif
28934
28935 #undef i386 /* in case the preprocessor is a 32bit one */
28936
28937@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28938
28939 PHDRS {
28940 text PT_LOAD FLAGS(5); /* R_E */
28941+#ifdef CONFIG_X86_32
28942+ module PT_LOAD FLAGS(5); /* R_E */
28943+#endif
28944+#ifdef CONFIG_XEN
28945+ rodata PT_LOAD FLAGS(5); /* R_E */
28946+#else
28947+ rodata PT_LOAD FLAGS(4); /* R__ */
28948+#endif
28949 data PT_LOAD FLAGS(6); /* RW_ */
28950-#ifdef CONFIG_X86_64
28951+ init.begin PT_LOAD FLAGS(6); /* RW_ */
28952 #ifdef CONFIG_SMP
28953 percpu PT_LOAD FLAGS(6); /* RW_ */
28954 #endif
28955+ text.init PT_LOAD FLAGS(5); /* R_E */
28956+ text.exit PT_LOAD FLAGS(5); /* R_E */
28957 init PT_LOAD FLAGS(7); /* RWE */
28958-#endif
28959 note PT_NOTE FLAGS(0); /* ___ */
28960 }
28961
28962 SECTIONS
28963 {
28964 #ifdef CONFIG_X86_32
28965- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28966- phys_startup_32 = startup_32 - LOAD_OFFSET;
28967+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28968 #else
28969- . = __START_KERNEL;
28970- phys_startup_64 = startup_64 - LOAD_OFFSET;
28971+ . = __START_KERNEL;
28972 #endif
28973
28974 /* Text and read-only data */
28975- .text : AT(ADDR(.text) - LOAD_OFFSET) {
28976- _text = .;
28977+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28978 /* bootstrapping code */
28979+#ifdef CONFIG_X86_32
28980+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28981+#else
28982+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28983+#endif
28984+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28985+ _text = .;
28986 HEAD_TEXT
28987 . = ALIGN(8);
28988 _stext = .;
28989@@ -104,13 +124,47 @@ SECTIONS
28990 IRQENTRY_TEXT
28991 *(.fixup)
28992 *(.gnu.warning)
28993- /* End of text section */
28994- _etext = .;
28995 } :text = 0x9090
28996
28997- NOTES :text :note
28998+ . += __KERNEL_TEXT_OFFSET;
28999
29000- EXCEPTION_TABLE(16) :text = 0x9090
29001+#ifdef CONFIG_X86_32
29002+ . = ALIGN(PAGE_SIZE);
29003+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
29004+
29005+#ifdef CONFIG_PAX_KERNEXEC
29006+ MODULES_EXEC_VADDR = .;
29007+ BYTE(0)
29008+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
29009+ . = ALIGN(HPAGE_SIZE) - 1;
29010+ MODULES_EXEC_END = .;
29011+#endif
29012+
29013+ } :module
29014+#endif
29015+
29016+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
29017+ /* End of text section */
29018+ BYTE(0)
29019+ _etext = . - __KERNEL_TEXT_OFFSET;
29020+ }
29021+
29022+#ifdef CONFIG_X86_32
29023+ . = ALIGN(PAGE_SIZE);
29024+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
29025+ . = ALIGN(PAGE_SIZE);
29026+ *(.empty_zero_page)
29027+ *(.initial_pg_fixmap)
29028+ *(.initial_pg_pmd)
29029+ *(.initial_page_table)
29030+ *(.swapper_pg_dir)
29031+ } :rodata
29032+#endif
29033+
29034+ . = ALIGN(PAGE_SIZE);
29035+ NOTES :rodata :note
29036+
29037+ EXCEPTION_TABLE(16) :rodata
29038
29039 #if defined(CONFIG_DEBUG_RODATA)
29040 /* .text should occupy whole number of pages */
29041@@ -122,16 +176,20 @@ SECTIONS
29042
29043 /* Data */
29044 .data : AT(ADDR(.data) - LOAD_OFFSET) {
29045+
29046+#ifdef CONFIG_PAX_KERNEXEC
29047+ . = ALIGN(HPAGE_SIZE);
29048+#else
29049+ . = ALIGN(PAGE_SIZE);
29050+#endif
29051+
29052 /* Start of data section */
29053 _sdata = .;
29054
29055 /* init_task */
29056 INIT_TASK_DATA(THREAD_SIZE)
29057
29058-#ifdef CONFIG_X86_32
29059- /* 32 bit has nosave before _edata */
29060 NOSAVE_DATA
29061-#endif
29062
29063 PAGE_ALIGNED_DATA(PAGE_SIZE)
29064
29065@@ -174,12 +232,19 @@ SECTIONS
29066 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
29067
29068 /* Init code and data - will be freed after init */
29069- . = ALIGN(PAGE_SIZE);
29070 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
29071+ BYTE(0)
29072+
29073+#ifdef CONFIG_PAX_KERNEXEC
29074+ . = ALIGN(HPAGE_SIZE);
29075+#else
29076+ . = ALIGN(PAGE_SIZE);
29077+#endif
29078+
29079 __init_begin = .; /* paired with __init_end */
29080- }
29081+ } :init.begin
29082
29083-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
29084+#ifdef CONFIG_SMP
29085 /*
29086 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
29087 * output PHDR, so the next output section - .init.text - should
29088@@ -188,12 +253,27 @@ SECTIONS
29089 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
29090 #endif
29091
29092- INIT_TEXT_SECTION(PAGE_SIZE)
29093-#ifdef CONFIG_X86_64
29094- :init
29095-#endif
29096+ . = ALIGN(PAGE_SIZE);
29097+ init_begin = .;
29098+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
29099+ VMLINUX_SYMBOL(_sinittext) = .;
29100+ INIT_TEXT
29101+ VMLINUX_SYMBOL(_einittext) = .;
29102+ . = ALIGN(PAGE_SIZE);
29103+ } :text.init
29104
29105- INIT_DATA_SECTION(16)
29106+ /*
29107+ * .exit.text is discard at runtime, not link time, to deal with
29108+ * references from .altinstructions and .eh_frame
29109+ */
29110+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
29111+ EXIT_TEXT
29112+ . = ALIGN(16);
29113+ } :text.exit
29114+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
29115+
29116+ . = ALIGN(PAGE_SIZE);
29117+ INIT_DATA_SECTION(16) :init
29118
29119 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
29120 __x86_cpu_dev_start = .;
29121@@ -264,19 +344,12 @@ SECTIONS
29122 }
29123
29124 . = ALIGN(8);
29125- /*
29126- * .exit.text is discard at runtime, not link time, to deal with
29127- * references from .altinstructions and .eh_frame
29128- */
29129- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
29130- EXIT_TEXT
29131- }
29132
29133 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
29134 EXIT_DATA
29135 }
29136
29137-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
29138+#ifndef CONFIG_SMP
29139 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
29140 #endif
29141
29142@@ -295,16 +368,10 @@ SECTIONS
29143 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
29144 __smp_locks = .;
29145 *(.smp_locks)
29146- . = ALIGN(PAGE_SIZE);
29147 __smp_locks_end = .;
29148+ . = ALIGN(PAGE_SIZE);
29149 }
29150
29151-#ifdef CONFIG_X86_64
29152- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
29153- NOSAVE_DATA
29154- }
29155-#endif
29156-
29157 /* BSS */
29158 . = ALIGN(PAGE_SIZE);
29159 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
29160@@ -320,6 +387,7 @@ SECTIONS
29161 __brk_base = .;
29162 . += 64 * 1024; /* 64k alignment slop space */
29163 *(.brk_reservation) /* areas brk users have reserved */
29164+ . = ALIGN(HPAGE_SIZE);
29165 __brk_limit = .;
29166 }
29167
29168@@ -346,13 +414,12 @@ SECTIONS
29169 * for the boot processor.
29170 */
29171 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
29172-INIT_PER_CPU(gdt_page);
29173 INIT_PER_CPU(irq_stack_union);
29174
29175 /*
29176 * Build-time check on the image size:
29177 */
29178-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
29179+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
29180 "kernel image bigger than KERNEL_IMAGE_SIZE");
29181
29182 #ifdef CONFIG_SMP
29183diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
29184index e1e1e80..1400089 100644
29185--- a/arch/x86/kernel/vsyscall_64.c
29186+++ b/arch/x86/kernel/vsyscall_64.c
29187@@ -54,15 +54,13 @@
29188
29189 DEFINE_VVAR(int, vgetcpu_mode);
29190
29191-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
29192+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
29193
29194 static int __init vsyscall_setup(char *str)
29195 {
29196 if (str) {
29197 if (!strcmp("emulate", str))
29198 vsyscall_mode = EMULATE;
29199- else if (!strcmp("native", str))
29200- vsyscall_mode = NATIVE;
29201 else if (!strcmp("none", str))
29202 vsyscall_mode = NONE;
29203 else
29204@@ -279,8 +277,7 @@ do_ret:
29205 return true;
29206
29207 sigsegv:
29208- force_sig(SIGSEGV, current);
29209- return true;
29210+ do_group_exit(SIGKILL);
29211 }
29212
29213 /*
29214@@ -331,10 +328,7 @@ void __init map_vsyscall(void)
29215 extern char __vsyscall_page;
29216 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
29217
29218- __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
29219- vsyscall_mode == NATIVE
29220- ? PAGE_KERNEL_VSYSCALL
29221- : PAGE_KERNEL_VVAR);
29222+ __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
29223 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_PAGE) !=
29224 (unsigned long)VSYSCALL_ADDR);
29225 }
29226diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
29227index 04068192..4d75aa6 100644
29228--- a/arch/x86/kernel/x8664_ksyms_64.c
29229+++ b/arch/x86/kernel/x8664_ksyms_64.c
29230@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
29231 EXPORT_SYMBOL(copy_user_generic_unrolled);
29232 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
29233 EXPORT_SYMBOL(__copy_user_nocache);
29234-EXPORT_SYMBOL(_copy_from_user);
29235-EXPORT_SYMBOL(_copy_to_user);
29236
29237 EXPORT_SYMBOL(copy_page);
29238 EXPORT_SYMBOL(clear_page);
29239@@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
29240 EXPORT_SYMBOL(___preempt_schedule_context);
29241 #endif
29242 #endif
29243+
29244+#ifdef CONFIG_PAX_PER_CPU_PGD
29245+EXPORT_SYMBOL(cpu_pgd);
29246+#endif
29247diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
29248index e48b674..a451dd9 100644
29249--- a/arch/x86/kernel/x86_init.c
29250+++ b/arch/x86/kernel/x86_init.c
29251@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
29252 static void default_nmi_init(void) { };
29253 static int default_i8042_detect(void) { return 1; };
29254
29255-struct x86_platform_ops x86_platform = {
29256+struct x86_platform_ops x86_platform __read_only = {
29257 .calibrate_tsc = native_calibrate_tsc,
29258 .get_wallclock = mach_get_cmos_time,
29259 .set_wallclock = mach_set_rtc_mmss,
29260@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
29261 EXPORT_SYMBOL_GPL(x86_platform);
29262
29263 #if defined(CONFIG_PCI_MSI)
29264-struct x86_msi_ops x86_msi = {
29265+struct x86_msi_ops x86_msi __read_only = {
29266 .setup_msi_irqs = native_setup_msi_irqs,
29267 .compose_msi_msg = native_compose_msi_msg,
29268 .teardown_msi_irq = native_teardown_msi_irq,
29269@@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
29270 }
29271 #endif
29272
29273-struct x86_io_apic_ops x86_io_apic_ops = {
29274+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
29275 .init = native_io_apic_init_mappings,
29276 .read = native_io_apic_read,
29277 .write = native_io_apic_write,
29278diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
29279index 4c540c4..0b985b0 100644
29280--- a/arch/x86/kernel/xsave.c
29281+++ b/arch/x86/kernel/xsave.c
29282@@ -167,18 +167,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
29283
29284 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
29285 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
29286- err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
29287+ err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
29288
29289 if (!use_xsave())
29290 return err;
29291
29292- err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
29293+ err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
29294
29295 /*
29296 * Read the xstate_bv which we copied (directly from the cpu or
29297 * from the state in task struct) to the user buffers.
29298 */
29299- err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
29300+ err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
29301
29302 /*
29303 * For legacy compatible, we always set FP/SSE bits in the bit
29304@@ -193,7 +193,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
29305 */
29306 xstate_bv |= XSTATE_FPSSE;
29307
29308- err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
29309+ err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
29310
29311 return err;
29312 }
29313@@ -202,6 +202,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
29314 {
29315 int err;
29316
29317+ buf = (struct xsave_struct __user *)____m(buf);
29318 if (use_xsave())
29319 err = xsave_user(buf);
29320 else if (use_fxsr())
29321@@ -312,6 +313,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
29322 */
29323 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
29324 {
29325+ buf = (void __user *)____m(buf);
29326 if (use_xsave()) {
29327 if ((unsigned long)buf % 64 || fx_only) {
29328 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
29329diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
29330index 38a0afe..94421a9 100644
29331--- a/arch/x86/kvm/cpuid.c
29332+++ b/arch/x86/kvm/cpuid.c
29333@@ -166,15 +166,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
29334 struct kvm_cpuid2 *cpuid,
29335 struct kvm_cpuid_entry2 __user *entries)
29336 {
29337- int r;
29338+ int r, i;
29339
29340 r = -E2BIG;
29341 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
29342 goto out;
29343 r = -EFAULT;
29344- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
29345- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
29346+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
29347 goto out;
29348+ for (i = 0; i < cpuid->nent; ++i) {
29349+ struct kvm_cpuid_entry2 cpuid_entry;
29350+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
29351+ goto out;
29352+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
29353+ }
29354 vcpu->arch.cpuid_nent = cpuid->nent;
29355 kvm_apic_set_version(vcpu);
29356 kvm_x86_ops->cpuid_update(vcpu);
29357@@ -189,15 +194,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
29358 struct kvm_cpuid2 *cpuid,
29359 struct kvm_cpuid_entry2 __user *entries)
29360 {
29361- int r;
29362+ int r, i;
29363
29364 r = -E2BIG;
29365 if (cpuid->nent < vcpu->arch.cpuid_nent)
29366 goto out;
29367 r = -EFAULT;
29368- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
29369- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
29370+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
29371 goto out;
29372+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
29373+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
29374+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
29375+ goto out;
29376+ }
29377 return 0;
29378
29379 out:
29380diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
29381index 08e8a89..0e9183e 100644
29382--- a/arch/x86/kvm/lapic.c
29383+++ b/arch/x86/kvm/lapic.c
29384@@ -55,7 +55,7 @@
29385 #define APIC_BUS_CYCLE_NS 1
29386
29387 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
29388-#define apic_debug(fmt, arg...)
29389+#define apic_debug(fmt, arg...) do {} while (0)
29390
29391 #define APIC_LVT_NUM 6
29392 /* 14 is the version for Xeon and Pentium 8.4.8*/
29393diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
29394index 4107765..d9eb358 100644
29395--- a/arch/x86/kvm/paging_tmpl.h
29396+++ b/arch/x86/kvm/paging_tmpl.h
29397@@ -331,7 +331,7 @@ retry_walk:
29398 if (unlikely(kvm_is_error_hva(host_addr)))
29399 goto error;
29400
29401- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
29402+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
29403 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
29404 goto error;
29405 walker->ptep_user[walker->level - 1] = ptep_user;
29406diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
29407index 78dadc3..fd84599 100644
29408--- a/arch/x86/kvm/svm.c
29409+++ b/arch/x86/kvm/svm.c
29410@@ -3547,7 +3547,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
29411 int cpu = raw_smp_processor_id();
29412
29413 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
29414+
29415+ pax_open_kernel();
29416 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
29417+ pax_close_kernel();
29418+
29419 load_TR_desc();
29420 }
29421
29422@@ -3948,6 +3952,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
29423 #endif
29424 #endif
29425
29426+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29427+ __set_fs(current_thread_info()->addr_limit);
29428+#endif
29429+
29430 reload_tss(vcpu);
29431
29432 local_irq_disable();
29433diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
29434index 41a5426..c0b3c00 100644
29435--- a/arch/x86/kvm/vmx.c
29436+++ b/arch/x86/kvm/vmx.c
29437@@ -1341,12 +1341,12 @@ static void vmcs_write64(unsigned long field, u64 value)
29438 #endif
29439 }
29440
29441-static void vmcs_clear_bits(unsigned long field, u32 mask)
29442+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
29443 {
29444 vmcs_writel(field, vmcs_readl(field) & ~mask);
29445 }
29446
29447-static void vmcs_set_bits(unsigned long field, u32 mask)
29448+static void vmcs_set_bits(unsigned long field, unsigned long mask)
29449 {
29450 vmcs_writel(field, vmcs_readl(field) | mask);
29451 }
29452@@ -1606,7 +1606,11 @@ static void reload_tss(void)
29453 struct desc_struct *descs;
29454
29455 descs = (void *)gdt->address;
29456+
29457+ pax_open_kernel();
29458 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
29459+ pax_close_kernel();
29460+
29461 load_TR_desc();
29462 }
29463
29464@@ -1834,6 +1838,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
29465 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
29466 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
29467
29468+#ifdef CONFIG_PAX_PER_CPU_PGD
29469+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
29470+#endif
29471+
29472 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
29473 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
29474 vmx->loaded_vmcs->cpu = cpu;
29475@@ -2123,7 +2131,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
29476 * reads and returns guest's timestamp counter "register"
29477 * guest_tsc = host_tsc + tsc_offset -- 21.3
29478 */
29479-static u64 guest_read_tsc(void)
29480+static u64 __intentional_overflow(-1) guest_read_tsc(void)
29481 {
29482 u64 host_tsc, tsc_offset;
29483
29484@@ -3114,8 +3122,11 @@ static __init int hardware_setup(void)
29485 if (!cpu_has_vmx_flexpriority())
29486 flexpriority_enabled = 0;
29487
29488- if (!cpu_has_vmx_tpr_shadow())
29489- kvm_x86_ops->update_cr8_intercept = NULL;
29490+ if (!cpu_has_vmx_tpr_shadow()) {
29491+ pax_open_kernel();
29492+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
29493+ pax_close_kernel();
29494+ }
29495
29496 if (enable_ept && !cpu_has_vmx_ept_2m_page())
29497 kvm_disable_largepages();
29498@@ -3126,13 +3137,15 @@ static __init int hardware_setup(void)
29499 if (!cpu_has_vmx_apicv())
29500 enable_apicv = 0;
29501
29502+ pax_open_kernel();
29503 if (enable_apicv)
29504- kvm_x86_ops->update_cr8_intercept = NULL;
29505+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
29506 else {
29507- kvm_x86_ops->hwapic_irr_update = NULL;
29508- kvm_x86_ops->deliver_posted_interrupt = NULL;
29509- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
29510+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
29511+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
29512+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
29513 }
29514+ pax_close_kernel();
29515
29516 if (nested)
29517 nested_vmx_setup_ctls_msrs();
29518@@ -4242,7 +4255,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
29519 unsigned long cr4;
29520
29521 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
29522+
29523+#ifndef CONFIG_PAX_PER_CPU_PGD
29524 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
29525+#endif
29526
29527 /* Save the most likely value for this task's CR4 in the VMCS. */
29528 cr4 = read_cr4();
29529@@ -4269,7 +4285,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
29530 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
29531 vmx->host_idt_base = dt.address;
29532
29533- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
29534+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
29535
29536 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
29537 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
29538@@ -7475,6 +7491,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29539 "jmp 2f \n\t"
29540 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
29541 "2: "
29542+
29543+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29544+ "ljmp %[cs],$3f\n\t"
29545+ "3: "
29546+#endif
29547+
29548 /* Save guest registers, load host registers, keep flags */
29549 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
29550 "pop %0 \n\t"
29551@@ -7527,6 +7549,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29552 #endif
29553 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
29554 [wordsize]"i"(sizeof(ulong))
29555+
29556+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29557+ ,[cs]"i"(__KERNEL_CS)
29558+#endif
29559+
29560 : "cc", "memory"
29561 #ifdef CONFIG_X86_64
29562 , "rax", "rbx", "rdi", "rsi"
29563@@ -7540,7 +7567,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29564 if (debugctlmsr)
29565 update_debugctlmsr(debugctlmsr);
29566
29567-#ifndef CONFIG_X86_64
29568+#ifdef CONFIG_X86_32
29569 /*
29570 * The sysexit path does not restore ds/es, so we must set them to
29571 * a reasonable value ourselves.
29572@@ -7549,8 +7576,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29573 * may be executed in interrupt context, which saves and restore segments
29574 * around it, nullifying its effect.
29575 */
29576- loadsegment(ds, __USER_DS);
29577- loadsegment(es, __USER_DS);
29578+ loadsegment(ds, __KERNEL_DS);
29579+ loadsegment(es, __KERNEL_DS);
29580+ loadsegment(ss, __KERNEL_DS);
29581+
29582+#ifdef CONFIG_PAX_KERNEXEC
29583+ loadsegment(fs, __KERNEL_PERCPU);
29584+#endif
29585+
29586+#ifdef CONFIG_PAX_MEMORY_UDEREF
29587+ __set_fs(current_thread_info()->addr_limit);
29588+#endif
29589+
29590 #endif
29591
29592 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
29593diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
29594index d6aeccf..cea125a 100644
29595--- a/arch/x86/kvm/x86.c
29596+++ b/arch/x86/kvm/x86.c
29597@@ -1857,8 +1857,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
29598 {
29599 struct kvm *kvm = vcpu->kvm;
29600 int lm = is_long_mode(vcpu);
29601- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29602- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29603+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29604+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29605 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
29606 : kvm->arch.xen_hvm_config.blob_size_32;
29607 u32 page_num = data & ~PAGE_MASK;
29608@@ -2779,6 +2779,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
29609 if (n < msr_list.nmsrs)
29610 goto out;
29611 r = -EFAULT;
29612+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
29613+ goto out;
29614 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
29615 num_msrs_to_save * sizeof(u32)))
29616 goto out;
29617@@ -5639,7 +5641,7 @@ static struct notifier_block pvclock_gtod_notifier = {
29618 };
29619 #endif
29620
29621-int kvm_arch_init(void *opaque)
29622+int kvm_arch_init(const void *opaque)
29623 {
29624 int r;
29625 struct kvm_x86_ops *ops = opaque;
29626diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
29627index aae9413..d11e829 100644
29628--- a/arch/x86/lguest/boot.c
29629+++ b/arch/x86/lguest/boot.c
29630@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
29631 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
29632 * Launcher to reboot us.
29633 */
29634-static void lguest_restart(char *reason)
29635+static __noreturn void lguest_restart(char *reason)
29636 {
29637 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
29638+ BUG();
29639 }
29640
29641 /*G:050
29642diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
29643index 00933d5..3a64af9 100644
29644--- a/arch/x86/lib/atomic64_386_32.S
29645+++ b/arch/x86/lib/atomic64_386_32.S
29646@@ -48,6 +48,10 @@ BEGIN(read)
29647 movl (v), %eax
29648 movl 4(v), %edx
29649 RET_ENDP
29650+BEGIN(read_unchecked)
29651+ movl (v), %eax
29652+ movl 4(v), %edx
29653+RET_ENDP
29654 #undef v
29655
29656 #define v %esi
29657@@ -55,6 +59,10 @@ BEGIN(set)
29658 movl %ebx, (v)
29659 movl %ecx, 4(v)
29660 RET_ENDP
29661+BEGIN(set_unchecked)
29662+ movl %ebx, (v)
29663+ movl %ecx, 4(v)
29664+RET_ENDP
29665 #undef v
29666
29667 #define v %esi
29668@@ -70,6 +78,20 @@ RET_ENDP
29669 BEGIN(add)
29670 addl %eax, (v)
29671 adcl %edx, 4(v)
29672+
29673+#ifdef CONFIG_PAX_REFCOUNT
29674+ jno 0f
29675+ subl %eax, (v)
29676+ sbbl %edx, 4(v)
29677+ int $4
29678+0:
29679+ _ASM_EXTABLE(0b, 0b)
29680+#endif
29681+
29682+RET_ENDP
29683+BEGIN(add_unchecked)
29684+ addl %eax, (v)
29685+ adcl %edx, 4(v)
29686 RET_ENDP
29687 #undef v
29688
29689@@ -77,6 +99,24 @@ RET_ENDP
29690 BEGIN(add_return)
29691 addl (v), %eax
29692 adcl 4(v), %edx
29693+
29694+#ifdef CONFIG_PAX_REFCOUNT
29695+ into
29696+1234:
29697+ _ASM_EXTABLE(1234b, 2f)
29698+#endif
29699+
29700+ movl %eax, (v)
29701+ movl %edx, 4(v)
29702+
29703+#ifdef CONFIG_PAX_REFCOUNT
29704+2:
29705+#endif
29706+
29707+RET_ENDP
29708+BEGIN(add_return_unchecked)
29709+ addl (v), %eax
29710+ adcl 4(v), %edx
29711 movl %eax, (v)
29712 movl %edx, 4(v)
29713 RET_ENDP
29714@@ -86,6 +126,20 @@ RET_ENDP
29715 BEGIN(sub)
29716 subl %eax, (v)
29717 sbbl %edx, 4(v)
29718+
29719+#ifdef CONFIG_PAX_REFCOUNT
29720+ jno 0f
29721+ addl %eax, (v)
29722+ adcl %edx, 4(v)
29723+ int $4
29724+0:
29725+ _ASM_EXTABLE(0b, 0b)
29726+#endif
29727+
29728+RET_ENDP
29729+BEGIN(sub_unchecked)
29730+ subl %eax, (v)
29731+ sbbl %edx, 4(v)
29732 RET_ENDP
29733 #undef v
29734
29735@@ -96,6 +150,27 @@ BEGIN(sub_return)
29736 sbbl $0, %edx
29737 addl (v), %eax
29738 adcl 4(v), %edx
29739+
29740+#ifdef CONFIG_PAX_REFCOUNT
29741+ into
29742+1234:
29743+ _ASM_EXTABLE(1234b, 2f)
29744+#endif
29745+
29746+ movl %eax, (v)
29747+ movl %edx, 4(v)
29748+
29749+#ifdef CONFIG_PAX_REFCOUNT
29750+2:
29751+#endif
29752+
29753+RET_ENDP
29754+BEGIN(sub_return_unchecked)
29755+ negl %edx
29756+ negl %eax
29757+ sbbl $0, %edx
29758+ addl (v), %eax
29759+ adcl 4(v), %edx
29760 movl %eax, (v)
29761 movl %edx, 4(v)
29762 RET_ENDP
29763@@ -105,6 +180,20 @@ RET_ENDP
29764 BEGIN(inc)
29765 addl $1, (v)
29766 adcl $0, 4(v)
29767+
29768+#ifdef CONFIG_PAX_REFCOUNT
29769+ jno 0f
29770+ subl $1, (v)
29771+ sbbl $0, 4(v)
29772+ int $4
29773+0:
29774+ _ASM_EXTABLE(0b, 0b)
29775+#endif
29776+
29777+RET_ENDP
29778+BEGIN(inc_unchecked)
29779+ addl $1, (v)
29780+ adcl $0, 4(v)
29781 RET_ENDP
29782 #undef v
29783
29784@@ -114,6 +203,26 @@ BEGIN(inc_return)
29785 movl 4(v), %edx
29786 addl $1, %eax
29787 adcl $0, %edx
29788+
29789+#ifdef CONFIG_PAX_REFCOUNT
29790+ into
29791+1234:
29792+ _ASM_EXTABLE(1234b, 2f)
29793+#endif
29794+
29795+ movl %eax, (v)
29796+ movl %edx, 4(v)
29797+
29798+#ifdef CONFIG_PAX_REFCOUNT
29799+2:
29800+#endif
29801+
29802+RET_ENDP
29803+BEGIN(inc_return_unchecked)
29804+ movl (v), %eax
29805+ movl 4(v), %edx
29806+ addl $1, %eax
29807+ adcl $0, %edx
29808 movl %eax, (v)
29809 movl %edx, 4(v)
29810 RET_ENDP
29811@@ -123,6 +232,20 @@ RET_ENDP
29812 BEGIN(dec)
29813 subl $1, (v)
29814 sbbl $0, 4(v)
29815+
29816+#ifdef CONFIG_PAX_REFCOUNT
29817+ jno 0f
29818+ addl $1, (v)
29819+ adcl $0, 4(v)
29820+ int $4
29821+0:
29822+ _ASM_EXTABLE(0b, 0b)
29823+#endif
29824+
29825+RET_ENDP
29826+BEGIN(dec_unchecked)
29827+ subl $1, (v)
29828+ sbbl $0, 4(v)
29829 RET_ENDP
29830 #undef v
29831
29832@@ -132,6 +255,26 @@ BEGIN(dec_return)
29833 movl 4(v), %edx
29834 subl $1, %eax
29835 sbbl $0, %edx
29836+
29837+#ifdef CONFIG_PAX_REFCOUNT
29838+ into
29839+1234:
29840+ _ASM_EXTABLE(1234b, 2f)
29841+#endif
29842+
29843+ movl %eax, (v)
29844+ movl %edx, 4(v)
29845+
29846+#ifdef CONFIG_PAX_REFCOUNT
29847+2:
29848+#endif
29849+
29850+RET_ENDP
29851+BEGIN(dec_return_unchecked)
29852+ movl (v), %eax
29853+ movl 4(v), %edx
29854+ subl $1, %eax
29855+ sbbl $0, %edx
29856 movl %eax, (v)
29857 movl %edx, 4(v)
29858 RET_ENDP
29859@@ -143,6 +286,13 @@ BEGIN(add_unless)
29860 adcl %edx, %edi
29861 addl (v), %eax
29862 adcl 4(v), %edx
29863+
29864+#ifdef CONFIG_PAX_REFCOUNT
29865+ into
29866+1234:
29867+ _ASM_EXTABLE(1234b, 2f)
29868+#endif
29869+
29870 cmpl %eax, %ecx
29871 je 3f
29872 1:
29873@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
29874 1:
29875 addl $1, %eax
29876 adcl $0, %edx
29877+
29878+#ifdef CONFIG_PAX_REFCOUNT
29879+ into
29880+1234:
29881+ _ASM_EXTABLE(1234b, 2f)
29882+#endif
29883+
29884 movl %eax, (v)
29885 movl %edx, 4(v)
29886 movl $1, %eax
29887@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
29888 movl 4(v), %edx
29889 subl $1, %eax
29890 sbbl $0, %edx
29891+
29892+#ifdef CONFIG_PAX_REFCOUNT
29893+ into
29894+1234:
29895+ _ASM_EXTABLE(1234b, 1f)
29896+#endif
29897+
29898 js 1f
29899 movl %eax, (v)
29900 movl %edx, 4(v)
29901diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
29902index f5cc9eb..51fa319 100644
29903--- a/arch/x86/lib/atomic64_cx8_32.S
29904+++ b/arch/x86/lib/atomic64_cx8_32.S
29905@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
29906 CFI_STARTPROC
29907
29908 read64 %ecx
29909+ pax_force_retaddr
29910 ret
29911 CFI_ENDPROC
29912 ENDPROC(atomic64_read_cx8)
29913
29914+ENTRY(atomic64_read_unchecked_cx8)
29915+ CFI_STARTPROC
29916+
29917+ read64 %ecx
29918+ pax_force_retaddr
29919+ ret
29920+ CFI_ENDPROC
29921+ENDPROC(atomic64_read_unchecked_cx8)
29922+
29923 ENTRY(atomic64_set_cx8)
29924 CFI_STARTPROC
29925
29926@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
29927 cmpxchg8b (%esi)
29928 jne 1b
29929
29930+ pax_force_retaddr
29931 ret
29932 CFI_ENDPROC
29933 ENDPROC(atomic64_set_cx8)
29934
29935+ENTRY(atomic64_set_unchecked_cx8)
29936+ CFI_STARTPROC
29937+
29938+1:
29939+/* we don't need LOCK_PREFIX since aligned 64-bit writes
29940+ * are atomic on 586 and newer */
29941+ cmpxchg8b (%esi)
29942+ jne 1b
29943+
29944+ pax_force_retaddr
29945+ ret
29946+ CFI_ENDPROC
29947+ENDPROC(atomic64_set_unchecked_cx8)
29948+
29949 ENTRY(atomic64_xchg_cx8)
29950 CFI_STARTPROC
29951
29952@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
29953 cmpxchg8b (%esi)
29954 jne 1b
29955
29956+ pax_force_retaddr
29957 ret
29958 CFI_ENDPROC
29959 ENDPROC(atomic64_xchg_cx8)
29960
29961-.macro addsub_return func ins insc
29962-ENTRY(atomic64_\func\()_return_cx8)
29963+.macro addsub_return func ins insc unchecked=""
29964+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29965 CFI_STARTPROC
29966 SAVE ebp
29967 SAVE ebx
29968@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
29969 movl %edx, %ecx
29970 \ins\()l %esi, %ebx
29971 \insc\()l %edi, %ecx
29972+
29973+.ifb \unchecked
29974+#ifdef CONFIG_PAX_REFCOUNT
29975+ into
29976+2:
29977+ _ASM_EXTABLE(2b, 3f)
29978+#endif
29979+.endif
29980+
29981 LOCK_PREFIX
29982 cmpxchg8b (%ebp)
29983 jne 1b
29984-
29985-10:
29986 movl %ebx, %eax
29987 movl %ecx, %edx
29988+
29989+.ifb \unchecked
29990+#ifdef CONFIG_PAX_REFCOUNT
29991+3:
29992+#endif
29993+.endif
29994+
29995 RESTORE edi
29996 RESTORE esi
29997 RESTORE ebx
29998 RESTORE ebp
29999+ pax_force_retaddr
30000 ret
30001 CFI_ENDPROC
30002-ENDPROC(atomic64_\func\()_return_cx8)
30003+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
30004 .endm
30005
30006 addsub_return add add adc
30007 addsub_return sub sub sbb
30008+addsub_return add add adc _unchecked
30009+addsub_return sub sub sbb _unchecked
30010
30011-.macro incdec_return func ins insc
30012-ENTRY(atomic64_\func\()_return_cx8)
30013+.macro incdec_return func ins insc unchecked=""
30014+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
30015 CFI_STARTPROC
30016 SAVE ebx
30017
30018@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
30019 movl %edx, %ecx
30020 \ins\()l $1, %ebx
30021 \insc\()l $0, %ecx
30022+
30023+.ifb \unchecked
30024+#ifdef CONFIG_PAX_REFCOUNT
30025+ into
30026+2:
30027+ _ASM_EXTABLE(2b, 3f)
30028+#endif
30029+.endif
30030+
30031 LOCK_PREFIX
30032 cmpxchg8b (%esi)
30033 jne 1b
30034
30035-10:
30036 movl %ebx, %eax
30037 movl %ecx, %edx
30038+
30039+.ifb \unchecked
30040+#ifdef CONFIG_PAX_REFCOUNT
30041+3:
30042+#endif
30043+.endif
30044+
30045 RESTORE ebx
30046+ pax_force_retaddr
30047 ret
30048 CFI_ENDPROC
30049-ENDPROC(atomic64_\func\()_return_cx8)
30050+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
30051 .endm
30052
30053 incdec_return inc add adc
30054 incdec_return dec sub sbb
30055+incdec_return inc add adc _unchecked
30056+incdec_return dec sub sbb _unchecked
30057
30058 ENTRY(atomic64_dec_if_positive_cx8)
30059 CFI_STARTPROC
30060@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
30061 movl %edx, %ecx
30062 subl $1, %ebx
30063 sbb $0, %ecx
30064+
30065+#ifdef CONFIG_PAX_REFCOUNT
30066+ into
30067+1234:
30068+ _ASM_EXTABLE(1234b, 2f)
30069+#endif
30070+
30071 js 2f
30072 LOCK_PREFIX
30073 cmpxchg8b (%esi)
30074@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
30075 movl %ebx, %eax
30076 movl %ecx, %edx
30077 RESTORE ebx
30078+ pax_force_retaddr
30079 ret
30080 CFI_ENDPROC
30081 ENDPROC(atomic64_dec_if_positive_cx8)
30082@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
30083 movl %edx, %ecx
30084 addl %ebp, %ebx
30085 adcl %edi, %ecx
30086+
30087+#ifdef CONFIG_PAX_REFCOUNT
30088+ into
30089+1234:
30090+ _ASM_EXTABLE(1234b, 3f)
30091+#endif
30092+
30093 LOCK_PREFIX
30094 cmpxchg8b (%esi)
30095 jne 1b
30096@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
30097 CFI_ADJUST_CFA_OFFSET -8
30098 RESTORE ebx
30099 RESTORE ebp
30100+ pax_force_retaddr
30101 ret
30102 4:
30103 cmpl %edx, 4(%esp)
30104@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
30105 xorl %ecx, %ecx
30106 addl $1, %ebx
30107 adcl %edx, %ecx
30108+
30109+#ifdef CONFIG_PAX_REFCOUNT
30110+ into
30111+1234:
30112+ _ASM_EXTABLE(1234b, 3f)
30113+#endif
30114+
30115 LOCK_PREFIX
30116 cmpxchg8b (%esi)
30117 jne 1b
30118@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
30119 movl $1, %eax
30120 3:
30121 RESTORE ebx
30122+ pax_force_retaddr
30123 ret
30124 CFI_ENDPROC
30125 ENDPROC(atomic64_inc_not_zero_cx8)
30126diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
30127index e78b8eee..7e173a8 100644
30128--- a/arch/x86/lib/checksum_32.S
30129+++ b/arch/x86/lib/checksum_32.S
30130@@ -29,7 +29,8 @@
30131 #include <asm/dwarf2.h>
30132 #include <asm/errno.h>
30133 #include <asm/asm.h>
30134-
30135+#include <asm/segment.h>
30136+
30137 /*
30138 * computes a partial checksum, e.g. for TCP/UDP fragments
30139 */
30140@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
30141
30142 #define ARGBASE 16
30143 #define FP 12
30144-
30145-ENTRY(csum_partial_copy_generic)
30146+
30147+ENTRY(csum_partial_copy_generic_to_user)
30148 CFI_STARTPROC
30149+
30150+#ifdef CONFIG_PAX_MEMORY_UDEREF
30151+ pushl_cfi %gs
30152+ popl_cfi %es
30153+ jmp csum_partial_copy_generic
30154+#endif
30155+
30156+ENTRY(csum_partial_copy_generic_from_user)
30157+
30158+#ifdef CONFIG_PAX_MEMORY_UDEREF
30159+ pushl_cfi %gs
30160+ popl_cfi %ds
30161+#endif
30162+
30163+ENTRY(csum_partial_copy_generic)
30164 subl $4,%esp
30165 CFI_ADJUST_CFA_OFFSET 4
30166 pushl_cfi %edi
30167@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
30168 jmp 4f
30169 SRC(1: movw (%esi), %bx )
30170 addl $2, %esi
30171-DST( movw %bx, (%edi) )
30172+DST( movw %bx, %es:(%edi) )
30173 addl $2, %edi
30174 addw %bx, %ax
30175 adcl $0, %eax
30176@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
30177 SRC(1: movl (%esi), %ebx )
30178 SRC( movl 4(%esi), %edx )
30179 adcl %ebx, %eax
30180-DST( movl %ebx, (%edi) )
30181+DST( movl %ebx, %es:(%edi) )
30182 adcl %edx, %eax
30183-DST( movl %edx, 4(%edi) )
30184+DST( movl %edx, %es:4(%edi) )
30185
30186 SRC( movl 8(%esi), %ebx )
30187 SRC( movl 12(%esi), %edx )
30188 adcl %ebx, %eax
30189-DST( movl %ebx, 8(%edi) )
30190+DST( movl %ebx, %es:8(%edi) )
30191 adcl %edx, %eax
30192-DST( movl %edx, 12(%edi) )
30193+DST( movl %edx, %es:12(%edi) )
30194
30195 SRC( movl 16(%esi), %ebx )
30196 SRC( movl 20(%esi), %edx )
30197 adcl %ebx, %eax
30198-DST( movl %ebx, 16(%edi) )
30199+DST( movl %ebx, %es:16(%edi) )
30200 adcl %edx, %eax
30201-DST( movl %edx, 20(%edi) )
30202+DST( movl %edx, %es:20(%edi) )
30203
30204 SRC( movl 24(%esi), %ebx )
30205 SRC( movl 28(%esi), %edx )
30206 adcl %ebx, %eax
30207-DST( movl %ebx, 24(%edi) )
30208+DST( movl %ebx, %es:24(%edi) )
30209 adcl %edx, %eax
30210-DST( movl %edx, 28(%edi) )
30211+DST( movl %edx, %es:28(%edi) )
30212
30213 lea 32(%esi), %esi
30214 lea 32(%edi), %edi
30215@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
30216 shrl $2, %edx # This clears CF
30217 SRC(3: movl (%esi), %ebx )
30218 adcl %ebx, %eax
30219-DST( movl %ebx, (%edi) )
30220+DST( movl %ebx, %es:(%edi) )
30221 lea 4(%esi), %esi
30222 lea 4(%edi), %edi
30223 dec %edx
30224@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
30225 jb 5f
30226 SRC( movw (%esi), %cx )
30227 leal 2(%esi), %esi
30228-DST( movw %cx, (%edi) )
30229+DST( movw %cx, %es:(%edi) )
30230 leal 2(%edi), %edi
30231 je 6f
30232 shll $16,%ecx
30233 SRC(5: movb (%esi), %cl )
30234-DST( movb %cl, (%edi) )
30235+DST( movb %cl, %es:(%edi) )
30236 6: addl %ecx, %eax
30237 adcl $0, %eax
30238 7:
30239@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
30240
30241 6001:
30242 movl ARGBASE+20(%esp), %ebx # src_err_ptr
30243- movl $-EFAULT, (%ebx)
30244+ movl $-EFAULT, %ss:(%ebx)
30245
30246 # zero the complete destination - computing the rest
30247 # is too much work
30248@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
30249
30250 6002:
30251 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
30252- movl $-EFAULT,(%ebx)
30253+ movl $-EFAULT,%ss:(%ebx)
30254 jmp 5000b
30255
30256 .previous
30257
30258+ pushl_cfi %ss
30259+ popl_cfi %ds
30260+ pushl_cfi %ss
30261+ popl_cfi %es
30262 popl_cfi %ebx
30263 CFI_RESTORE ebx
30264 popl_cfi %esi
30265@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
30266 popl_cfi %ecx # equivalent to addl $4,%esp
30267 ret
30268 CFI_ENDPROC
30269-ENDPROC(csum_partial_copy_generic)
30270+ENDPROC(csum_partial_copy_generic_to_user)
30271
30272 #else
30273
30274 /* Version for PentiumII/PPro */
30275
30276 #define ROUND1(x) \
30277+ nop; nop; nop; \
30278 SRC(movl x(%esi), %ebx ) ; \
30279 addl %ebx, %eax ; \
30280- DST(movl %ebx, x(%edi) ) ;
30281+ DST(movl %ebx, %es:x(%edi)) ;
30282
30283 #define ROUND(x) \
30284+ nop; nop; nop; \
30285 SRC(movl x(%esi), %ebx ) ; \
30286 adcl %ebx, %eax ; \
30287- DST(movl %ebx, x(%edi) ) ;
30288+ DST(movl %ebx, %es:x(%edi)) ;
30289
30290 #define ARGBASE 12
30291-
30292-ENTRY(csum_partial_copy_generic)
30293+
30294+ENTRY(csum_partial_copy_generic_to_user)
30295 CFI_STARTPROC
30296+
30297+#ifdef CONFIG_PAX_MEMORY_UDEREF
30298+ pushl_cfi %gs
30299+ popl_cfi %es
30300+ jmp csum_partial_copy_generic
30301+#endif
30302+
30303+ENTRY(csum_partial_copy_generic_from_user)
30304+
30305+#ifdef CONFIG_PAX_MEMORY_UDEREF
30306+ pushl_cfi %gs
30307+ popl_cfi %ds
30308+#endif
30309+
30310+ENTRY(csum_partial_copy_generic)
30311 pushl_cfi %ebx
30312 CFI_REL_OFFSET ebx, 0
30313 pushl_cfi %edi
30314@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
30315 subl %ebx, %edi
30316 lea -1(%esi),%edx
30317 andl $-32,%edx
30318- lea 3f(%ebx,%ebx), %ebx
30319+ lea 3f(%ebx,%ebx,2), %ebx
30320 testl %esi, %esi
30321 jmp *%ebx
30322 1: addl $64,%esi
30323@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
30324 jb 5f
30325 SRC( movw (%esi), %dx )
30326 leal 2(%esi), %esi
30327-DST( movw %dx, (%edi) )
30328+DST( movw %dx, %es:(%edi) )
30329 leal 2(%edi), %edi
30330 je 6f
30331 shll $16,%edx
30332 5:
30333 SRC( movb (%esi), %dl )
30334-DST( movb %dl, (%edi) )
30335+DST( movb %dl, %es:(%edi) )
30336 6: addl %edx, %eax
30337 adcl $0, %eax
30338 7:
30339 .section .fixup, "ax"
30340 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
30341- movl $-EFAULT, (%ebx)
30342+ movl $-EFAULT, %ss:(%ebx)
30343 # zero the complete destination (computing the rest is too much work)
30344 movl ARGBASE+8(%esp),%edi # dst
30345 movl ARGBASE+12(%esp),%ecx # len
30346@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
30347 rep; stosb
30348 jmp 7b
30349 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
30350- movl $-EFAULT, (%ebx)
30351+ movl $-EFAULT, %ss:(%ebx)
30352 jmp 7b
30353 .previous
30354
30355+#ifdef CONFIG_PAX_MEMORY_UDEREF
30356+ pushl_cfi %ss
30357+ popl_cfi %ds
30358+ pushl_cfi %ss
30359+ popl_cfi %es
30360+#endif
30361+
30362 popl_cfi %esi
30363 CFI_RESTORE esi
30364 popl_cfi %edi
30365@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
30366 CFI_RESTORE ebx
30367 ret
30368 CFI_ENDPROC
30369-ENDPROC(csum_partial_copy_generic)
30370+ENDPROC(csum_partial_copy_generic_to_user)
30371
30372 #undef ROUND
30373 #undef ROUND1
30374diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
30375index f2145cf..cea889d 100644
30376--- a/arch/x86/lib/clear_page_64.S
30377+++ b/arch/x86/lib/clear_page_64.S
30378@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
30379 movl $4096/8,%ecx
30380 xorl %eax,%eax
30381 rep stosq
30382+ pax_force_retaddr
30383 ret
30384 CFI_ENDPROC
30385 ENDPROC(clear_page_c)
30386@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
30387 movl $4096,%ecx
30388 xorl %eax,%eax
30389 rep stosb
30390+ pax_force_retaddr
30391 ret
30392 CFI_ENDPROC
30393 ENDPROC(clear_page_c_e)
30394@@ -43,6 +45,7 @@ ENTRY(clear_page)
30395 leaq 64(%rdi),%rdi
30396 jnz .Lloop
30397 nop
30398+ pax_force_retaddr
30399 ret
30400 CFI_ENDPROC
30401 .Lclear_page_end:
30402@@ -58,7 +61,7 @@ ENDPROC(clear_page)
30403
30404 #include <asm/cpufeature.h>
30405
30406- .section .altinstr_replacement,"ax"
30407+ .section .altinstr_replacement,"a"
30408 1: .byte 0xeb /* jmp <disp8> */
30409 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
30410 2: .byte 0xeb /* jmp <disp8> */
30411diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
30412index 1e572c5..2a162cd 100644
30413--- a/arch/x86/lib/cmpxchg16b_emu.S
30414+++ b/arch/x86/lib/cmpxchg16b_emu.S
30415@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
30416
30417 popf
30418 mov $1, %al
30419+ pax_force_retaddr
30420 ret
30421
30422 not_same:
30423 popf
30424 xor %al,%al
30425+ pax_force_retaddr
30426 ret
30427
30428 CFI_ENDPROC
30429diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
30430index 176cca6..e0d658e 100644
30431--- a/arch/x86/lib/copy_page_64.S
30432+++ b/arch/x86/lib/copy_page_64.S
30433@@ -9,6 +9,7 @@ copy_page_rep:
30434 CFI_STARTPROC
30435 movl $4096/8, %ecx
30436 rep movsq
30437+ pax_force_retaddr
30438 ret
30439 CFI_ENDPROC
30440 ENDPROC(copy_page_rep)
30441@@ -24,8 +25,8 @@ ENTRY(copy_page)
30442 CFI_ADJUST_CFA_OFFSET 2*8
30443 movq %rbx, (%rsp)
30444 CFI_REL_OFFSET rbx, 0
30445- movq %r12, 1*8(%rsp)
30446- CFI_REL_OFFSET r12, 1*8
30447+ movq %r13, 1*8(%rsp)
30448+ CFI_REL_OFFSET r13, 1*8
30449
30450 movl $(4096/64)-5, %ecx
30451 .p2align 4
30452@@ -38,7 +39,7 @@ ENTRY(copy_page)
30453 movq 0x8*4(%rsi), %r9
30454 movq 0x8*5(%rsi), %r10
30455 movq 0x8*6(%rsi), %r11
30456- movq 0x8*7(%rsi), %r12
30457+ movq 0x8*7(%rsi), %r13
30458
30459 prefetcht0 5*64(%rsi)
30460
30461@@ -49,7 +50,7 @@ ENTRY(copy_page)
30462 movq %r9, 0x8*4(%rdi)
30463 movq %r10, 0x8*5(%rdi)
30464 movq %r11, 0x8*6(%rdi)
30465- movq %r12, 0x8*7(%rdi)
30466+ movq %r13, 0x8*7(%rdi)
30467
30468 leaq 64 (%rsi), %rsi
30469 leaq 64 (%rdi), %rdi
30470@@ -68,7 +69,7 @@ ENTRY(copy_page)
30471 movq 0x8*4(%rsi), %r9
30472 movq 0x8*5(%rsi), %r10
30473 movq 0x8*6(%rsi), %r11
30474- movq 0x8*7(%rsi), %r12
30475+ movq 0x8*7(%rsi), %r13
30476
30477 movq %rax, 0x8*0(%rdi)
30478 movq %rbx, 0x8*1(%rdi)
30479@@ -77,7 +78,7 @@ ENTRY(copy_page)
30480 movq %r9, 0x8*4(%rdi)
30481 movq %r10, 0x8*5(%rdi)
30482 movq %r11, 0x8*6(%rdi)
30483- movq %r12, 0x8*7(%rdi)
30484+ movq %r13, 0x8*7(%rdi)
30485
30486 leaq 64(%rdi), %rdi
30487 leaq 64(%rsi), %rsi
30488@@ -85,10 +86,11 @@ ENTRY(copy_page)
30489
30490 movq (%rsp), %rbx
30491 CFI_RESTORE rbx
30492- movq 1*8(%rsp), %r12
30493- CFI_RESTORE r12
30494+ movq 1*8(%rsp), %r13
30495+ CFI_RESTORE r13
30496 addq $2*8, %rsp
30497 CFI_ADJUST_CFA_OFFSET -2*8
30498+ pax_force_retaddr
30499 ret
30500 .Lcopy_page_end:
30501 CFI_ENDPROC
30502@@ -99,7 +101,7 @@ ENDPROC(copy_page)
30503
30504 #include <asm/cpufeature.h>
30505
30506- .section .altinstr_replacement,"ax"
30507+ .section .altinstr_replacement,"a"
30508 1: .byte 0xeb /* jmp <disp8> */
30509 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
30510 2:
30511diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
30512index dee945d..a84067b 100644
30513--- a/arch/x86/lib/copy_user_64.S
30514+++ b/arch/x86/lib/copy_user_64.S
30515@@ -18,31 +18,7 @@
30516 #include <asm/alternative-asm.h>
30517 #include <asm/asm.h>
30518 #include <asm/smap.h>
30519-
30520-/*
30521- * By placing feature2 after feature1 in altinstructions section, we logically
30522- * implement:
30523- * If CPU has feature2, jmp to alt2 is used
30524- * else if CPU has feature1, jmp to alt1 is used
30525- * else jmp to orig is used.
30526- */
30527- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
30528-0:
30529- .byte 0xe9 /* 32bit jump */
30530- .long \orig-1f /* by default jump to orig */
30531-1:
30532- .section .altinstr_replacement,"ax"
30533-2: .byte 0xe9 /* near jump with 32bit immediate */
30534- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
30535-3: .byte 0xe9 /* near jump with 32bit immediate */
30536- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
30537- .previous
30538-
30539- .section .altinstructions,"a"
30540- altinstruction_entry 0b,2b,\feature1,5,5
30541- altinstruction_entry 0b,3b,\feature2,5,5
30542- .previous
30543- .endm
30544+#include <asm/pgtable.h>
30545
30546 .macro ALIGN_DESTINATION
30547 #ifdef FIX_ALIGNMENT
30548@@ -70,52 +46,6 @@
30549 #endif
30550 .endm
30551
30552-/* Standard copy_to_user with segment limit checking */
30553-ENTRY(_copy_to_user)
30554- CFI_STARTPROC
30555- GET_THREAD_INFO(%rax)
30556- movq %rdi,%rcx
30557- addq %rdx,%rcx
30558- jc bad_to_user
30559- cmpq TI_addr_limit(%rax),%rcx
30560- ja bad_to_user
30561- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
30562- copy_user_generic_unrolled,copy_user_generic_string, \
30563- copy_user_enhanced_fast_string
30564- CFI_ENDPROC
30565-ENDPROC(_copy_to_user)
30566-
30567-/* Standard copy_from_user with segment limit checking */
30568-ENTRY(_copy_from_user)
30569- CFI_STARTPROC
30570- GET_THREAD_INFO(%rax)
30571- movq %rsi,%rcx
30572- addq %rdx,%rcx
30573- jc bad_from_user
30574- cmpq TI_addr_limit(%rax),%rcx
30575- ja bad_from_user
30576- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
30577- copy_user_generic_unrolled,copy_user_generic_string, \
30578- copy_user_enhanced_fast_string
30579- CFI_ENDPROC
30580-ENDPROC(_copy_from_user)
30581-
30582- .section .fixup,"ax"
30583- /* must zero dest */
30584-ENTRY(bad_from_user)
30585-bad_from_user:
30586- CFI_STARTPROC
30587- movl %edx,%ecx
30588- xorl %eax,%eax
30589- rep
30590- stosb
30591-bad_to_user:
30592- movl %edx,%eax
30593- ret
30594- CFI_ENDPROC
30595-ENDPROC(bad_from_user)
30596- .previous
30597-
30598 /*
30599 * copy_user_generic_unrolled - memory copy with exception handling.
30600 * This version is for CPUs like P4 that don't have efficient micro
30601@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
30602 */
30603 ENTRY(copy_user_generic_unrolled)
30604 CFI_STARTPROC
30605+ ASM_PAX_OPEN_USERLAND
30606 ASM_STAC
30607 cmpl $8,%edx
30608 jb 20f /* less then 8 bytes, go to byte copy loop */
30609@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
30610 jnz 21b
30611 23: xor %eax,%eax
30612 ASM_CLAC
30613+ ASM_PAX_CLOSE_USERLAND
30614+ pax_force_retaddr
30615 ret
30616
30617 .section .fixup,"ax"
30618@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
30619 */
30620 ENTRY(copy_user_generic_string)
30621 CFI_STARTPROC
30622+ ASM_PAX_OPEN_USERLAND
30623 ASM_STAC
30624 cmpl $8,%edx
30625 jb 2f /* less than 8 bytes, go to byte copy loop */
30626@@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
30627 movsb
30628 xorl %eax,%eax
30629 ASM_CLAC
30630+ ASM_PAX_CLOSE_USERLAND
30631+ pax_force_retaddr
30632 ret
30633
30634 .section .fixup,"ax"
30635@@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
30636 */
30637 ENTRY(copy_user_enhanced_fast_string)
30638 CFI_STARTPROC
30639+ ASM_PAX_OPEN_USERLAND
30640 ASM_STAC
30641 movl %edx,%ecx
30642 1: rep
30643 movsb
30644 xorl %eax,%eax
30645 ASM_CLAC
30646+ ASM_PAX_CLOSE_USERLAND
30647+ pax_force_retaddr
30648 ret
30649
30650 .section .fixup,"ax"
30651diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
30652index 6a4f43c..c70fb52 100644
30653--- a/arch/x86/lib/copy_user_nocache_64.S
30654+++ b/arch/x86/lib/copy_user_nocache_64.S
30655@@ -8,6 +8,7 @@
30656
30657 #include <linux/linkage.h>
30658 #include <asm/dwarf2.h>
30659+#include <asm/alternative-asm.h>
30660
30661 #define FIX_ALIGNMENT 1
30662
30663@@ -16,6 +17,7 @@
30664 #include <asm/thread_info.h>
30665 #include <asm/asm.h>
30666 #include <asm/smap.h>
30667+#include <asm/pgtable.h>
30668
30669 .macro ALIGN_DESTINATION
30670 #ifdef FIX_ALIGNMENT
30671@@ -49,6 +51,16 @@
30672 */
30673 ENTRY(__copy_user_nocache)
30674 CFI_STARTPROC
30675+
30676+#ifdef CONFIG_PAX_MEMORY_UDEREF
30677+ mov pax_user_shadow_base,%rcx
30678+ cmp %rcx,%rsi
30679+ jae 1f
30680+ add %rcx,%rsi
30681+1:
30682+#endif
30683+
30684+ ASM_PAX_OPEN_USERLAND
30685 ASM_STAC
30686 cmpl $8,%edx
30687 jb 20f /* less then 8 bytes, go to byte copy loop */
30688@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
30689 jnz 21b
30690 23: xorl %eax,%eax
30691 ASM_CLAC
30692+ ASM_PAX_CLOSE_USERLAND
30693 sfence
30694+ pax_force_retaddr
30695 ret
30696
30697 .section .fixup,"ax"
30698diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
30699index 2419d5f..fe52d0e 100644
30700--- a/arch/x86/lib/csum-copy_64.S
30701+++ b/arch/x86/lib/csum-copy_64.S
30702@@ -9,6 +9,7 @@
30703 #include <asm/dwarf2.h>
30704 #include <asm/errno.h>
30705 #include <asm/asm.h>
30706+#include <asm/alternative-asm.h>
30707
30708 /*
30709 * Checksum copy with exception handling.
30710@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
30711 CFI_ADJUST_CFA_OFFSET 7*8
30712 movq %rbx, 2*8(%rsp)
30713 CFI_REL_OFFSET rbx, 2*8
30714- movq %r12, 3*8(%rsp)
30715- CFI_REL_OFFSET r12, 3*8
30716+ movq %r15, 3*8(%rsp)
30717+ CFI_REL_OFFSET r15, 3*8
30718 movq %r14, 4*8(%rsp)
30719 CFI_REL_OFFSET r14, 4*8
30720 movq %r13, 5*8(%rsp)
30721@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
30722 movl %edx, %ecx
30723
30724 xorl %r9d, %r9d
30725- movq %rcx, %r12
30726+ movq %rcx, %r15
30727
30728- shrq $6, %r12
30729+ shrq $6, %r15
30730 jz .Lhandle_tail /* < 64 */
30731
30732 clc
30733
30734 /* main loop. clear in 64 byte blocks */
30735 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
30736- /* r11: temp3, rdx: temp4, r12 loopcnt */
30737+ /* r11: temp3, rdx: temp4, r15 loopcnt */
30738 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
30739 .p2align 4
30740 .Lloop:
30741@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
30742 adcq %r14, %rax
30743 adcq %r13, %rax
30744
30745- decl %r12d
30746+ decl %r15d
30747
30748 dest
30749 movq %rbx, (%rsi)
30750@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
30751 .Lende:
30752 movq 2*8(%rsp), %rbx
30753 CFI_RESTORE rbx
30754- movq 3*8(%rsp), %r12
30755- CFI_RESTORE r12
30756+ movq 3*8(%rsp), %r15
30757+ CFI_RESTORE r15
30758 movq 4*8(%rsp), %r14
30759 CFI_RESTORE r14
30760 movq 5*8(%rsp), %r13
30761@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
30762 CFI_RESTORE rbp
30763 addq $7*8, %rsp
30764 CFI_ADJUST_CFA_OFFSET -7*8
30765+ pax_force_retaddr
30766 ret
30767 CFI_RESTORE_STATE
30768
30769diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
30770index 7609e0e..b449b98 100644
30771--- a/arch/x86/lib/csum-wrappers_64.c
30772+++ b/arch/x86/lib/csum-wrappers_64.c
30773@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
30774 len -= 2;
30775 }
30776 }
30777+ pax_open_userland();
30778 stac();
30779- isum = csum_partial_copy_generic((__force const void *)src,
30780+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
30781 dst, len, isum, errp, NULL);
30782 clac();
30783+ pax_close_userland();
30784 if (unlikely(*errp))
30785 goto out_err;
30786
30787@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
30788 }
30789
30790 *errp = 0;
30791+ pax_open_userland();
30792 stac();
30793- ret = csum_partial_copy_generic(src, (void __force *)dst,
30794+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
30795 len, isum, NULL, errp);
30796 clac();
30797+ pax_close_userland();
30798 return ret;
30799 }
30800 EXPORT_SYMBOL(csum_partial_copy_to_user);
30801diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
30802index a451235..1daa956 100644
30803--- a/arch/x86/lib/getuser.S
30804+++ b/arch/x86/lib/getuser.S
30805@@ -33,17 +33,40 @@
30806 #include <asm/thread_info.h>
30807 #include <asm/asm.h>
30808 #include <asm/smap.h>
30809+#include <asm/segment.h>
30810+#include <asm/pgtable.h>
30811+#include <asm/alternative-asm.h>
30812+
30813+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30814+#define __copyuser_seg gs;
30815+#else
30816+#define __copyuser_seg
30817+#endif
30818
30819 .text
30820 ENTRY(__get_user_1)
30821 CFI_STARTPROC
30822+
30823+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30824 GET_THREAD_INFO(%_ASM_DX)
30825 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30826 jae bad_get_user
30827 ASM_STAC
30828-1: movzbl (%_ASM_AX),%edx
30829+
30830+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30831+ mov pax_user_shadow_base,%_ASM_DX
30832+ cmp %_ASM_DX,%_ASM_AX
30833+ jae 1234f
30834+ add %_ASM_DX,%_ASM_AX
30835+1234:
30836+#endif
30837+
30838+#endif
30839+
30840+1: __copyuser_seg movzbl (%_ASM_AX),%edx
30841 xor %eax,%eax
30842 ASM_CLAC
30843+ pax_force_retaddr
30844 ret
30845 CFI_ENDPROC
30846 ENDPROC(__get_user_1)
30847@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
30848 ENTRY(__get_user_2)
30849 CFI_STARTPROC
30850 add $1,%_ASM_AX
30851+
30852+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30853 jc bad_get_user
30854 GET_THREAD_INFO(%_ASM_DX)
30855 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30856 jae bad_get_user
30857 ASM_STAC
30858-2: movzwl -1(%_ASM_AX),%edx
30859+
30860+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30861+ mov pax_user_shadow_base,%_ASM_DX
30862+ cmp %_ASM_DX,%_ASM_AX
30863+ jae 1234f
30864+ add %_ASM_DX,%_ASM_AX
30865+1234:
30866+#endif
30867+
30868+#endif
30869+
30870+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
30871 xor %eax,%eax
30872 ASM_CLAC
30873+ pax_force_retaddr
30874 ret
30875 CFI_ENDPROC
30876 ENDPROC(__get_user_2)
30877@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
30878 ENTRY(__get_user_4)
30879 CFI_STARTPROC
30880 add $3,%_ASM_AX
30881+
30882+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30883 jc bad_get_user
30884 GET_THREAD_INFO(%_ASM_DX)
30885 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30886 jae bad_get_user
30887 ASM_STAC
30888-3: movl -3(%_ASM_AX),%edx
30889+
30890+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30891+ mov pax_user_shadow_base,%_ASM_DX
30892+ cmp %_ASM_DX,%_ASM_AX
30893+ jae 1234f
30894+ add %_ASM_DX,%_ASM_AX
30895+1234:
30896+#endif
30897+
30898+#endif
30899+
30900+3: __copyuser_seg movl -3(%_ASM_AX),%edx
30901 xor %eax,%eax
30902 ASM_CLAC
30903+ pax_force_retaddr
30904 ret
30905 CFI_ENDPROC
30906 ENDPROC(__get_user_4)
30907@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
30908 GET_THREAD_INFO(%_ASM_DX)
30909 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30910 jae bad_get_user
30911+
30912+#ifdef CONFIG_PAX_MEMORY_UDEREF
30913+ mov pax_user_shadow_base,%_ASM_DX
30914+ cmp %_ASM_DX,%_ASM_AX
30915+ jae 1234f
30916+ add %_ASM_DX,%_ASM_AX
30917+1234:
30918+#endif
30919+
30920 ASM_STAC
30921 4: movq -7(%_ASM_AX),%rdx
30922 xor %eax,%eax
30923 ASM_CLAC
30924+ pax_force_retaddr
30925 ret
30926 #else
30927 add $7,%_ASM_AX
30928@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
30929 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30930 jae bad_get_user_8
30931 ASM_STAC
30932-4: movl -7(%_ASM_AX),%edx
30933-5: movl -3(%_ASM_AX),%ecx
30934+4: __copyuser_seg movl -7(%_ASM_AX),%edx
30935+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
30936 xor %eax,%eax
30937 ASM_CLAC
30938+ pax_force_retaddr
30939 ret
30940 #endif
30941 CFI_ENDPROC
30942@@ -113,6 +175,7 @@ bad_get_user:
30943 xor %edx,%edx
30944 mov $(-EFAULT),%_ASM_AX
30945 ASM_CLAC
30946+ pax_force_retaddr
30947 ret
30948 CFI_ENDPROC
30949 END(bad_get_user)
30950@@ -124,6 +187,7 @@ bad_get_user_8:
30951 xor %ecx,%ecx
30952 mov $(-EFAULT),%_ASM_AX
30953 ASM_CLAC
30954+ pax_force_retaddr
30955 ret
30956 CFI_ENDPROC
30957 END(bad_get_user_8)
30958diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
30959index 54fcffe..7be149e 100644
30960--- a/arch/x86/lib/insn.c
30961+++ b/arch/x86/lib/insn.c
30962@@ -20,8 +20,10 @@
30963
30964 #ifdef __KERNEL__
30965 #include <linux/string.h>
30966+#include <asm/pgtable_types.h>
30967 #else
30968 #include <string.h>
30969+#define ktla_ktva(addr) addr
30970 #endif
30971 #include <asm/inat.h>
30972 #include <asm/insn.h>
30973@@ -53,8 +55,8 @@
30974 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
30975 {
30976 memset(insn, 0, sizeof(*insn));
30977- insn->kaddr = kaddr;
30978- insn->next_byte = kaddr;
30979+ insn->kaddr = ktla_ktva(kaddr);
30980+ insn->next_byte = ktla_ktva(kaddr);
30981 insn->x86_64 = x86_64 ? 1 : 0;
30982 insn->opnd_bytes = 4;
30983 if (x86_64)
30984diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
30985index 05a95e7..326f2fa 100644
30986--- a/arch/x86/lib/iomap_copy_64.S
30987+++ b/arch/x86/lib/iomap_copy_64.S
30988@@ -17,6 +17,7 @@
30989
30990 #include <linux/linkage.h>
30991 #include <asm/dwarf2.h>
30992+#include <asm/alternative-asm.h>
30993
30994 /*
30995 * override generic version in lib/iomap_copy.c
30996@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
30997 CFI_STARTPROC
30998 movl %edx,%ecx
30999 rep movsd
31000+ pax_force_retaddr
31001 ret
31002 CFI_ENDPROC
31003 ENDPROC(__iowrite32_copy)
31004diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
31005index 56313a3..0db417e 100644
31006--- a/arch/x86/lib/memcpy_64.S
31007+++ b/arch/x86/lib/memcpy_64.S
31008@@ -24,7 +24,7 @@
31009 * This gets patched over the unrolled variant (below) via the
31010 * alternative instructions framework:
31011 */
31012- .section .altinstr_replacement, "ax", @progbits
31013+ .section .altinstr_replacement, "a", @progbits
31014 .Lmemcpy_c:
31015 movq %rdi, %rax
31016 movq %rdx, %rcx
31017@@ -33,6 +33,7 @@
31018 rep movsq
31019 movl %edx, %ecx
31020 rep movsb
31021+ pax_force_retaddr
31022 ret
31023 .Lmemcpy_e:
31024 .previous
31025@@ -44,11 +45,12 @@
31026 * This gets patched over the unrolled variant (below) via the
31027 * alternative instructions framework:
31028 */
31029- .section .altinstr_replacement, "ax", @progbits
31030+ .section .altinstr_replacement, "a", @progbits
31031 .Lmemcpy_c_e:
31032 movq %rdi, %rax
31033 movq %rdx, %rcx
31034 rep movsb
31035+ pax_force_retaddr
31036 ret
31037 .Lmemcpy_e_e:
31038 .previous
31039@@ -136,6 +138,7 @@ ENTRY(memcpy)
31040 movq %r9, 1*8(%rdi)
31041 movq %r10, -2*8(%rdi, %rdx)
31042 movq %r11, -1*8(%rdi, %rdx)
31043+ pax_force_retaddr
31044 retq
31045 .p2align 4
31046 .Lless_16bytes:
31047@@ -148,6 +151,7 @@ ENTRY(memcpy)
31048 movq -1*8(%rsi, %rdx), %r9
31049 movq %r8, 0*8(%rdi)
31050 movq %r9, -1*8(%rdi, %rdx)
31051+ pax_force_retaddr
31052 retq
31053 .p2align 4
31054 .Lless_8bytes:
31055@@ -161,6 +165,7 @@ ENTRY(memcpy)
31056 movl -4(%rsi, %rdx), %r8d
31057 movl %ecx, (%rdi)
31058 movl %r8d, -4(%rdi, %rdx)
31059+ pax_force_retaddr
31060 retq
31061 .p2align 4
31062 .Lless_3bytes:
31063@@ -179,6 +184,7 @@ ENTRY(memcpy)
31064 movb %cl, (%rdi)
31065
31066 .Lend:
31067+ pax_force_retaddr
31068 retq
31069 CFI_ENDPROC
31070 ENDPROC(memcpy)
31071diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
31072index 65268a6..dd1de11 100644
31073--- a/arch/x86/lib/memmove_64.S
31074+++ b/arch/x86/lib/memmove_64.S
31075@@ -202,14 +202,16 @@ ENTRY(memmove)
31076 movb (%rsi), %r11b
31077 movb %r11b, (%rdi)
31078 13:
31079+ pax_force_retaddr
31080 retq
31081 CFI_ENDPROC
31082
31083- .section .altinstr_replacement,"ax"
31084+ .section .altinstr_replacement,"a"
31085 .Lmemmove_begin_forward_efs:
31086 /* Forward moving data. */
31087 movq %rdx, %rcx
31088 rep movsb
31089+ pax_force_retaddr
31090 retq
31091 .Lmemmove_end_forward_efs:
31092 .previous
31093diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
31094index 2dcb380..2eb79fe 100644
31095--- a/arch/x86/lib/memset_64.S
31096+++ b/arch/x86/lib/memset_64.S
31097@@ -16,7 +16,7 @@
31098 *
31099 * rax original destination
31100 */
31101- .section .altinstr_replacement, "ax", @progbits
31102+ .section .altinstr_replacement, "a", @progbits
31103 .Lmemset_c:
31104 movq %rdi,%r9
31105 movq %rdx,%rcx
31106@@ -30,6 +30,7 @@
31107 movl %edx,%ecx
31108 rep stosb
31109 movq %r9,%rax
31110+ pax_force_retaddr
31111 ret
31112 .Lmemset_e:
31113 .previous
31114@@ -45,13 +46,14 @@
31115 *
31116 * rax original destination
31117 */
31118- .section .altinstr_replacement, "ax", @progbits
31119+ .section .altinstr_replacement, "a", @progbits
31120 .Lmemset_c_e:
31121 movq %rdi,%r9
31122 movb %sil,%al
31123 movq %rdx,%rcx
31124 rep stosb
31125 movq %r9,%rax
31126+ pax_force_retaddr
31127 ret
31128 .Lmemset_e_e:
31129 .previous
31130@@ -118,6 +120,7 @@ ENTRY(__memset)
31131
31132 .Lende:
31133 movq %r10,%rax
31134+ pax_force_retaddr
31135 ret
31136
31137 CFI_RESTORE_STATE
31138diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
31139index c9f2d9b..e7fd2c0 100644
31140--- a/arch/x86/lib/mmx_32.c
31141+++ b/arch/x86/lib/mmx_32.c
31142@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
31143 {
31144 void *p;
31145 int i;
31146+ unsigned long cr0;
31147
31148 if (unlikely(in_interrupt()))
31149 return __memcpy(to, from, len);
31150@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
31151 kernel_fpu_begin();
31152
31153 __asm__ __volatile__ (
31154- "1: prefetch (%0)\n" /* This set is 28 bytes */
31155- " prefetch 64(%0)\n"
31156- " prefetch 128(%0)\n"
31157- " prefetch 192(%0)\n"
31158- " prefetch 256(%0)\n"
31159+ "1: prefetch (%1)\n" /* This set is 28 bytes */
31160+ " prefetch 64(%1)\n"
31161+ " prefetch 128(%1)\n"
31162+ " prefetch 192(%1)\n"
31163+ " prefetch 256(%1)\n"
31164 "2: \n"
31165 ".section .fixup, \"ax\"\n"
31166- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31167+ "3: \n"
31168+
31169+#ifdef CONFIG_PAX_KERNEXEC
31170+ " movl %%cr0, %0\n"
31171+ " movl %0, %%eax\n"
31172+ " andl $0xFFFEFFFF, %%eax\n"
31173+ " movl %%eax, %%cr0\n"
31174+#endif
31175+
31176+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31177+
31178+#ifdef CONFIG_PAX_KERNEXEC
31179+ " movl %0, %%cr0\n"
31180+#endif
31181+
31182 " jmp 2b\n"
31183 ".previous\n"
31184 _ASM_EXTABLE(1b, 3b)
31185- : : "r" (from));
31186+ : "=&r" (cr0) : "r" (from) : "ax");
31187
31188 for ( ; i > 5; i--) {
31189 __asm__ __volatile__ (
31190- "1: prefetch 320(%0)\n"
31191- "2: movq (%0), %%mm0\n"
31192- " movq 8(%0), %%mm1\n"
31193- " movq 16(%0), %%mm2\n"
31194- " movq 24(%0), %%mm3\n"
31195- " movq %%mm0, (%1)\n"
31196- " movq %%mm1, 8(%1)\n"
31197- " movq %%mm2, 16(%1)\n"
31198- " movq %%mm3, 24(%1)\n"
31199- " movq 32(%0), %%mm0\n"
31200- " movq 40(%0), %%mm1\n"
31201- " movq 48(%0), %%mm2\n"
31202- " movq 56(%0), %%mm3\n"
31203- " movq %%mm0, 32(%1)\n"
31204- " movq %%mm1, 40(%1)\n"
31205- " movq %%mm2, 48(%1)\n"
31206- " movq %%mm3, 56(%1)\n"
31207+ "1: prefetch 320(%1)\n"
31208+ "2: movq (%1), %%mm0\n"
31209+ " movq 8(%1), %%mm1\n"
31210+ " movq 16(%1), %%mm2\n"
31211+ " movq 24(%1), %%mm3\n"
31212+ " movq %%mm0, (%2)\n"
31213+ " movq %%mm1, 8(%2)\n"
31214+ " movq %%mm2, 16(%2)\n"
31215+ " movq %%mm3, 24(%2)\n"
31216+ " movq 32(%1), %%mm0\n"
31217+ " movq 40(%1), %%mm1\n"
31218+ " movq 48(%1), %%mm2\n"
31219+ " movq 56(%1), %%mm3\n"
31220+ " movq %%mm0, 32(%2)\n"
31221+ " movq %%mm1, 40(%2)\n"
31222+ " movq %%mm2, 48(%2)\n"
31223+ " movq %%mm3, 56(%2)\n"
31224 ".section .fixup, \"ax\"\n"
31225- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31226+ "3:\n"
31227+
31228+#ifdef CONFIG_PAX_KERNEXEC
31229+ " movl %%cr0, %0\n"
31230+ " movl %0, %%eax\n"
31231+ " andl $0xFFFEFFFF, %%eax\n"
31232+ " movl %%eax, %%cr0\n"
31233+#endif
31234+
31235+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31236+
31237+#ifdef CONFIG_PAX_KERNEXEC
31238+ " movl %0, %%cr0\n"
31239+#endif
31240+
31241 " jmp 2b\n"
31242 ".previous\n"
31243 _ASM_EXTABLE(1b, 3b)
31244- : : "r" (from), "r" (to) : "memory");
31245+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
31246
31247 from += 64;
31248 to += 64;
31249@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
31250 static void fast_copy_page(void *to, void *from)
31251 {
31252 int i;
31253+ unsigned long cr0;
31254
31255 kernel_fpu_begin();
31256
31257@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
31258 * but that is for later. -AV
31259 */
31260 __asm__ __volatile__(
31261- "1: prefetch (%0)\n"
31262- " prefetch 64(%0)\n"
31263- " prefetch 128(%0)\n"
31264- " prefetch 192(%0)\n"
31265- " prefetch 256(%0)\n"
31266+ "1: prefetch (%1)\n"
31267+ " prefetch 64(%1)\n"
31268+ " prefetch 128(%1)\n"
31269+ " prefetch 192(%1)\n"
31270+ " prefetch 256(%1)\n"
31271 "2: \n"
31272 ".section .fixup, \"ax\"\n"
31273- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31274+ "3: \n"
31275+
31276+#ifdef CONFIG_PAX_KERNEXEC
31277+ " movl %%cr0, %0\n"
31278+ " movl %0, %%eax\n"
31279+ " andl $0xFFFEFFFF, %%eax\n"
31280+ " movl %%eax, %%cr0\n"
31281+#endif
31282+
31283+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31284+
31285+#ifdef CONFIG_PAX_KERNEXEC
31286+ " movl %0, %%cr0\n"
31287+#endif
31288+
31289 " jmp 2b\n"
31290 ".previous\n"
31291- _ASM_EXTABLE(1b, 3b) : : "r" (from));
31292+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
31293
31294 for (i = 0; i < (4096-320)/64; i++) {
31295 __asm__ __volatile__ (
31296- "1: prefetch 320(%0)\n"
31297- "2: movq (%0), %%mm0\n"
31298- " movntq %%mm0, (%1)\n"
31299- " movq 8(%0), %%mm1\n"
31300- " movntq %%mm1, 8(%1)\n"
31301- " movq 16(%0), %%mm2\n"
31302- " movntq %%mm2, 16(%1)\n"
31303- " movq 24(%0), %%mm3\n"
31304- " movntq %%mm3, 24(%1)\n"
31305- " movq 32(%0), %%mm4\n"
31306- " movntq %%mm4, 32(%1)\n"
31307- " movq 40(%0), %%mm5\n"
31308- " movntq %%mm5, 40(%1)\n"
31309- " movq 48(%0), %%mm6\n"
31310- " movntq %%mm6, 48(%1)\n"
31311- " movq 56(%0), %%mm7\n"
31312- " movntq %%mm7, 56(%1)\n"
31313+ "1: prefetch 320(%1)\n"
31314+ "2: movq (%1), %%mm0\n"
31315+ " movntq %%mm0, (%2)\n"
31316+ " movq 8(%1), %%mm1\n"
31317+ " movntq %%mm1, 8(%2)\n"
31318+ " movq 16(%1), %%mm2\n"
31319+ " movntq %%mm2, 16(%2)\n"
31320+ " movq 24(%1), %%mm3\n"
31321+ " movntq %%mm3, 24(%2)\n"
31322+ " movq 32(%1), %%mm4\n"
31323+ " movntq %%mm4, 32(%2)\n"
31324+ " movq 40(%1), %%mm5\n"
31325+ " movntq %%mm5, 40(%2)\n"
31326+ " movq 48(%1), %%mm6\n"
31327+ " movntq %%mm6, 48(%2)\n"
31328+ " movq 56(%1), %%mm7\n"
31329+ " movntq %%mm7, 56(%2)\n"
31330 ".section .fixup, \"ax\"\n"
31331- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31332+ "3:\n"
31333+
31334+#ifdef CONFIG_PAX_KERNEXEC
31335+ " movl %%cr0, %0\n"
31336+ " movl %0, %%eax\n"
31337+ " andl $0xFFFEFFFF, %%eax\n"
31338+ " movl %%eax, %%cr0\n"
31339+#endif
31340+
31341+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31342+
31343+#ifdef CONFIG_PAX_KERNEXEC
31344+ " movl %0, %%cr0\n"
31345+#endif
31346+
31347 " jmp 2b\n"
31348 ".previous\n"
31349- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
31350+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
31351
31352 from += 64;
31353 to += 64;
31354@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
31355 static void fast_copy_page(void *to, void *from)
31356 {
31357 int i;
31358+ unsigned long cr0;
31359
31360 kernel_fpu_begin();
31361
31362 __asm__ __volatile__ (
31363- "1: prefetch (%0)\n"
31364- " prefetch 64(%0)\n"
31365- " prefetch 128(%0)\n"
31366- " prefetch 192(%0)\n"
31367- " prefetch 256(%0)\n"
31368+ "1: prefetch (%1)\n"
31369+ " prefetch 64(%1)\n"
31370+ " prefetch 128(%1)\n"
31371+ " prefetch 192(%1)\n"
31372+ " prefetch 256(%1)\n"
31373 "2: \n"
31374 ".section .fixup, \"ax\"\n"
31375- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31376+ "3: \n"
31377+
31378+#ifdef CONFIG_PAX_KERNEXEC
31379+ " movl %%cr0, %0\n"
31380+ " movl %0, %%eax\n"
31381+ " andl $0xFFFEFFFF, %%eax\n"
31382+ " movl %%eax, %%cr0\n"
31383+#endif
31384+
31385+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31386+
31387+#ifdef CONFIG_PAX_KERNEXEC
31388+ " movl %0, %%cr0\n"
31389+#endif
31390+
31391 " jmp 2b\n"
31392 ".previous\n"
31393- _ASM_EXTABLE(1b, 3b) : : "r" (from));
31394+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
31395
31396 for (i = 0; i < 4096/64; i++) {
31397 __asm__ __volatile__ (
31398- "1: prefetch 320(%0)\n"
31399- "2: movq (%0), %%mm0\n"
31400- " movq 8(%0), %%mm1\n"
31401- " movq 16(%0), %%mm2\n"
31402- " movq 24(%0), %%mm3\n"
31403- " movq %%mm0, (%1)\n"
31404- " movq %%mm1, 8(%1)\n"
31405- " movq %%mm2, 16(%1)\n"
31406- " movq %%mm3, 24(%1)\n"
31407- " movq 32(%0), %%mm0\n"
31408- " movq 40(%0), %%mm1\n"
31409- " movq 48(%0), %%mm2\n"
31410- " movq 56(%0), %%mm3\n"
31411- " movq %%mm0, 32(%1)\n"
31412- " movq %%mm1, 40(%1)\n"
31413- " movq %%mm2, 48(%1)\n"
31414- " movq %%mm3, 56(%1)\n"
31415+ "1: prefetch 320(%1)\n"
31416+ "2: movq (%1), %%mm0\n"
31417+ " movq 8(%1), %%mm1\n"
31418+ " movq 16(%1), %%mm2\n"
31419+ " movq 24(%1), %%mm3\n"
31420+ " movq %%mm0, (%2)\n"
31421+ " movq %%mm1, 8(%2)\n"
31422+ " movq %%mm2, 16(%2)\n"
31423+ " movq %%mm3, 24(%2)\n"
31424+ " movq 32(%1), %%mm0\n"
31425+ " movq 40(%1), %%mm1\n"
31426+ " movq 48(%1), %%mm2\n"
31427+ " movq 56(%1), %%mm3\n"
31428+ " movq %%mm0, 32(%2)\n"
31429+ " movq %%mm1, 40(%2)\n"
31430+ " movq %%mm2, 48(%2)\n"
31431+ " movq %%mm3, 56(%2)\n"
31432 ".section .fixup, \"ax\"\n"
31433- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31434+ "3:\n"
31435+
31436+#ifdef CONFIG_PAX_KERNEXEC
31437+ " movl %%cr0, %0\n"
31438+ " movl %0, %%eax\n"
31439+ " andl $0xFFFEFFFF, %%eax\n"
31440+ " movl %%eax, %%cr0\n"
31441+#endif
31442+
31443+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31444+
31445+#ifdef CONFIG_PAX_KERNEXEC
31446+ " movl %0, %%cr0\n"
31447+#endif
31448+
31449 " jmp 2b\n"
31450 ".previous\n"
31451 _ASM_EXTABLE(1b, 3b)
31452- : : "r" (from), "r" (to) : "memory");
31453+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
31454
31455 from += 64;
31456 to += 64;
31457diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
31458index f6d13ee..d789440 100644
31459--- a/arch/x86/lib/msr-reg.S
31460+++ b/arch/x86/lib/msr-reg.S
31461@@ -3,6 +3,7 @@
31462 #include <asm/dwarf2.h>
31463 #include <asm/asm.h>
31464 #include <asm/msr.h>
31465+#include <asm/alternative-asm.h>
31466
31467 #ifdef CONFIG_X86_64
31468 /*
31469@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
31470 movl %edi, 28(%r10)
31471 popq_cfi %rbp
31472 popq_cfi %rbx
31473+ pax_force_retaddr
31474 ret
31475 3:
31476 CFI_RESTORE_STATE
31477diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
31478index fc6ba17..d4d989d 100644
31479--- a/arch/x86/lib/putuser.S
31480+++ b/arch/x86/lib/putuser.S
31481@@ -16,7 +16,9 @@
31482 #include <asm/errno.h>
31483 #include <asm/asm.h>
31484 #include <asm/smap.h>
31485-
31486+#include <asm/segment.h>
31487+#include <asm/pgtable.h>
31488+#include <asm/alternative-asm.h>
31489
31490 /*
31491 * __put_user_X
31492@@ -30,57 +32,125 @@
31493 * as they get called from within inline assembly.
31494 */
31495
31496-#define ENTER CFI_STARTPROC ; \
31497- GET_THREAD_INFO(%_ASM_BX)
31498-#define EXIT ASM_CLAC ; \
31499- ret ; \
31500+#define ENTER CFI_STARTPROC
31501+#define EXIT ASM_CLAC ; \
31502+ pax_force_retaddr ; \
31503+ ret ; \
31504 CFI_ENDPROC
31505
31506+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31507+#define _DEST %_ASM_CX,%_ASM_BX
31508+#else
31509+#define _DEST %_ASM_CX
31510+#endif
31511+
31512+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
31513+#define __copyuser_seg gs;
31514+#else
31515+#define __copyuser_seg
31516+#endif
31517+
31518 .text
31519 ENTRY(__put_user_1)
31520 ENTER
31521+
31522+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31523+ GET_THREAD_INFO(%_ASM_BX)
31524 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
31525 jae bad_put_user
31526 ASM_STAC
31527-1: movb %al,(%_ASM_CX)
31528+
31529+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31530+ mov pax_user_shadow_base,%_ASM_BX
31531+ cmp %_ASM_BX,%_ASM_CX
31532+ jb 1234f
31533+ xor %ebx,%ebx
31534+1234:
31535+#endif
31536+
31537+#endif
31538+
31539+1: __copyuser_seg movb %al,(_DEST)
31540 xor %eax,%eax
31541 EXIT
31542 ENDPROC(__put_user_1)
31543
31544 ENTRY(__put_user_2)
31545 ENTER
31546+
31547+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31548+ GET_THREAD_INFO(%_ASM_BX)
31549 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31550 sub $1,%_ASM_BX
31551 cmp %_ASM_BX,%_ASM_CX
31552 jae bad_put_user
31553 ASM_STAC
31554-2: movw %ax,(%_ASM_CX)
31555+
31556+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31557+ mov pax_user_shadow_base,%_ASM_BX
31558+ cmp %_ASM_BX,%_ASM_CX
31559+ jb 1234f
31560+ xor %ebx,%ebx
31561+1234:
31562+#endif
31563+
31564+#endif
31565+
31566+2: __copyuser_seg movw %ax,(_DEST)
31567 xor %eax,%eax
31568 EXIT
31569 ENDPROC(__put_user_2)
31570
31571 ENTRY(__put_user_4)
31572 ENTER
31573+
31574+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31575+ GET_THREAD_INFO(%_ASM_BX)
31576 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31577 sub $3,%_ASM_BX
31578 cmp %_ASM_BX,%_ASM_CX
31579 jae bad_put_user
31580 ASM_STAC
31581-3: movl %eax,(%_ASM_CX)
31582+
31583+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31584+ mov pax_user_shadow_base,%_ASM_BX
31585+ cmp %_ASM_BX,%_ASM_CX
31586+ jb 1234f
31587+ xor %ebx,%ebx
31588+1234:
31589+#endif
31590+
31591+#endif
31592+
31593+3: __copyuser_seg movl %eax,(_DEST)
31594 xor %eax,%eax
31595 EXIT
31596 ENDPROC(__put_user_4)
31597
31598 ENTRY(__put_user_8)
31599 ENTER
31600+
31601+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31602+ GET_THREAD_INFO(%_ASM_BX)
31603 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31604 sub $7,%_ASM_BX
31605 cmp %_ASM_BX,%_ASM_CX
31606 jae bad_put_user
31607 ASM_STAC
31608-4: mov %_ASM_AX,(%_ASM_CX)
31609+
31610+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31611+ mov pax_user_shadow_base,%_ASM_BX
31612+ cmp %_ASM_BX,%_ASM_CX
31613+ jb 1234f
31614+ xor %ebx,%ebx
31615+1234:
31616+#endif
31617+
31618+#endif
31619+
31620+4: __copyuser_seg mov %_ASM_AX,(_DEST)
31621 #ifdef CONFIG_X86_32
31622-5: movl %edx,4(%_ASM_CX)
31623+5: __copyuser_seg movl %edx,4(_DEST)
31624 #endif
31625 xor %eax,%eax
31626 EXIT
31627diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
31628index 1cad221..de671ee 100644
31629--- a/arch/x86/lib/rwlock.S
31630+++ b/arch/x86/lib/rwlock.S
31631@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
31632 FRAME
31633 0: LOCK_PREFIX
31634 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
31635+
31636+#ifdef CONFIG_PAX_REFCOUNT
31637+ jno 1234f
31638+ LOCK_PREFIX
31639+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
31640+ int $4
31641+1234:
31642+ _ASM_EXTABLE(1234b, 1234b)
31643+#endif
31644+
31645 1: rep; nop
31646 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
31647 jne 1b
31648 LOCK_PREFIX
31649 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
31650+
31651+#ifdef CONFIG_PAX_REFCOUNT
31652+ jno 1234f
31653+ LOCK_PREFIX
31654+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
31655+ int $4
31656+1234:
31657+ _ASM_EXTABLE(1234b, 1234b)
31658+#endif
31659+
31660 jnz 0b
31661 ENDFRAME
31662+ pax_force_retaddr
31663 ret
31664 CFI_ENDPROC
31665 END(__write_lock_failed)
31666@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
31667 FRAME
31668 0: LOCK_PREFIX
31669 READ_LOCK_SIZE(inc) (%__lock_ptr)
31670+
31671+#ifdef CONFIG_PAX_REFCOUNT
31672+ jno 1234f
31673+ LOCK_PREFIX
31674+ READ_LOCK_SIZE(dec) (%__lock_ptr)
31675+ int $4
31676+1234:
31677+ _ASM_EXTABLE(1234b, 1234b)
31678+#endif
31679+
31680 1: rep; nop
31681 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
31682 js 1b
31683 LOCK_PREFIX
31684 READ_LOCK_SIZE(dec) (%__lock_ptr)
31685+
31686+#ifdef CONFIG_PAX_REFCOUNT
31687+ jno 1234f
31688+ LOCK_PREFIX
31689+ READ_LOCK_SIZE(inc) (%__lock_ptr)
31690+ int $4
31691+1234:
31692+ _ASM_EXTABLE(1234b, 1234b)
31693+#endif
31694+
31695 js 0b
31696 ENDFRAME
31697+ pax_force_retaddr
31698 ret
31699 CFI_ENDPROC
31700 END(__read_lock_failed)
31701diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
31702index 5dff5f0..cadebf4 100644
31703--- a/arch/x86/lib/rwsem.S
31704+++ b/arch/x86/lib/rwsem.S
31705@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
31706 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31707 CFI_RESTORE __ASM_REG(dx)
31708 restore_common_regs
31709+ pax_force_retaddr
31710 ret
31711 CFI_ENDPROC
31712 ENDPROC(call_rwsem_down_read_failed)
31713@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
31714 movq %rax,%rdi
31715 call rwsem_down_write_failed
31716 restore_common_regs
31717+ pax_force_retaddr
31718 ret
31719 CFI_ENDPROC
31720 ENDPROC(call_rwsem_down_write_failed)
31721@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
31722 movq %rax,%rdi
31723 call rwsem_wake
31724 restore_common_regs
31725-1: ret
31726+1: pax_force_retaddr
31727+ ret
31728 CFI_ENDPROC
31729 ENDPROC(call_rwsem_wake)
31730
31731@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
31732 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31733 CFI_RESTORE __ASM_REG(dx)
31734 restore_common_regs
31735+ pax_force_retaddr
31736 ret
31737 CFI_ENDPROC
31738 ENDPROC(call_rwsem_downgrade_wake)
31739diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
31740index 92d9fea..b2762c8 100644
31741--- a/arch/x86/lib/thunk_64.S
31742+++ b/arch/x86/lib/thunk_64.S
31743@@ -9,6 +9,7 @@
31744 #include <asm/dwarf2.h>
31745 #include <asm/calling.h>
31746 #include <asm/asm.h>
31747+#include <asm/alternative-asm.h>
31748
31749 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
31750 .macro THUNK name, func, put_ret_addr_in_rdi=0
31751@@ -16,11 +17,11 @@
31752 \name:
31753 CFI_STARTPROC
31754
31755- /* this one pushes 9 elems, the next one would be %rIP */
31756- SAVE_ARGS
31757+ /* this one pushes 15+1 elems, the next one would be %rIP */
31758+ SAVE_ARGS 8
31759
31760 .if \put_ret_addr_in_rdi
31761- movq_cfi_restore 9*8, rdi
31762+ movq_cfi_restore RIP, rdi
31763 .endif
31764
31765 call \func
31766@@ -40,9 +41,10 @@
31767
31768 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
31769 CFI_STARTPROC
31770- SAVE_ARGS
31771+ SAVE_ARGS 8
31772 restore:
31773- RESTORE_ARGS
31774+ RESTORE_ARGS 1,8
31775+ pax_force_retaddr
31776 ret
31777 CFI_ENDPROC
31778 _ASM_NOKPROBE(restore)
31779diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
31780index e2f5e21..4b22130 100644
31781--- a/arch/x86/lib/usercopy_32.c
31782+++ b/arch/x86/lib/usercopy_32.c
31783@@ -42,11 +42,13 @@ do { \
31784 int __d0; \
31785 might_fault(); \
31786 __asm__ __volatile__( \
31787+ __COPYUSER_SET_ES \
31788 ASM_STAC "\n" \
31789 "0: rep; stosl\n" \
31790 " movl %2,%0\n" \
31791 "1: rep; stosb\n" \
31792 "2: " ASM_CLAC "\n" \
31793+ __COPYUSER_RESTORE_ES \
31794 ".section .fixup,\"ax\"\n" \
31795 "3: lea 0(%2,%0,4),%0\n" \
31796 " jmp 2b\n" \
31797@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
31798
31799 #ifdef CONFIG_X86_INTEL_USERCOPY
31800 static unsigned long
31801-__copy_user_intel(void __user *to, const void *from, unsigned long size)
31802+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
31803 {
31804 int d0, d1;
31805 __asm__ __volatile__(
31806@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31807 " .align 2,0x90\n"
31808 "3: movl 0(%4), %%eax\n"
31809 "4: movl 4(%4), %%edx\n"
31810- "5: movl %%eax, 0(%3)\n"
31811- "6: movl %%edx, 4(%3)\n"
31812+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
31813+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
31814 "7: movl 8(%4), %%eax\n"
31815 "8: movl 12(%4),%%edx\n"
31816- "9: movl %%eax, 8(%3)\n"
31817- "10: movl %%edx, 12(%3)\n"
31818+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
31819+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
31820 "11: movl 16(%4), %%eax\n"
31821 "12: movl 20(%4), %%edx\n"
31822- "13: movl %%eax, 16(%3)\n"
31823- "14: movl %%edx, 20(%3)\n"
31824+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
31825+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
31826 "15: movl 24(%4), %%eax\n"
31827 "16: movl 28(%4), %%edx\n"
31828- "17: movl %%eax, 24(%3)\n"
31829- "18: movl %%edx, 28(%3)\n"
31830+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
31831+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
31832 "19: movl 32(%4), %%eax\n"
31833 "20: movl 36(%4), %%edx\n"
31834- "21: movl %%eax, 32(%3)\n"
31835- "22: movl %%edx, 36(%3)\n"
31836+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
31837+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
31838 "23: movl 40(%4), %%eax\n"
31839 "24: movl 44(%4), %%edx\n"
31840- "25: movl %%eax, 40(%3)\n"
31841- "26: movl %%edx, 44(%3)\n"
31842+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
31843+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
31844 "27: movl 48(%4), %%eax\n"
31845 "28: movl 52(%4), %%edx\n"
31846- "29: movl %%eax, 48(%3)\n"
31847- "30: movl %%edx, 52(%3)\n"
31848+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
31849+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
31850 "31: movl 56(%4), %%eax\n"
31851 "32: movl 60(%4), %%edx\n"
31852- "33: movl %%eax, 56(%3)\n"
31853- "34: movl %%edx, 60(%3)\n"
31854+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
31855+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
31856 " addl $-64, %0\n"
31857 " addl $64, %4\n"
31858 " addl $64, %3\n"
31859@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31860 " shrl $2, %0\n"
31861 " andl $3, %%eax\n"
31862 " cld\n"
31863+ __COPYUSER_SET_ES
31864 "99: rep; movsl\n"
31865 "36: movl %%eax, %0\n"
31866 "37: rep; movsb\n"
31867 "100:\n"
31868+ __COPYUSER_RESTORE_ES
31869+ ".section .fixup,\"ax\"\n"
31870+ "101: lea 0(%%eax,%0,4),%0\n"
31871+ " jmp 100b\n"
31872+ ".previous\n"
31873+ _ASM_EXTABLE(1b,100b)
31874+ _ASM_EXTABLE(2b,100b)
31875+ _ASM_EXTABLE(3b,100b)
31876+ _ASM_EXTABLE(4b,100b)
31877+ _ASM_EXTABLE(5b,100b)
31878+ _ASM_EXTABLE(6b,100b)
31879+ _ASM_EXTABLE(7b,100b)
31880+ _ASM_EXTABLE(8b,100b)
31881+ _ASM_EXTABLE(9b,100b)
31882+ _ASM_EXTABLE(10b,100b)
31883+ _ASM_EXTABLE(11b,100b)
31884+ _ASM_EXTABLE(12b,100b)
31885+ _ASM_EXTABLE(13b,100b)
31886+ _ASM_EXTABLE(14b,100b)
31887+ _ASM_EXTABLE(15b,100b)
31888+ _ASM_EXTABLE(16b,100b)
31889+ _ASM_EXTABLE(17b,100b)
31890+ _ASM_EXTABLE(18b,100b)
31891+ _ASM_EXTABLE(19b,100b)
31892+ _ASM_EXTABLE(20b,100b)
31893+ _ASM_EXTABLE(21b,100b)
31894+ _ASM_EXTABLE(22b,100b)
31895+ _ASM_EXTABLE(23b,100b)
31896+ _ASM_EXTABLE(24b,100b)
31897+ _ASM_EXTABLE(25b,100b)
31898+ _ASM_EXTABLE(26b,100b)
31899+ _ASM_EXTABLE(27b,100b)
31900+ _ASM_EXTABLE(28b,100b)
31901+ _ASM_EXTABLE(29b,100b)
31902+ _ASM_EXTABLE(30b,100b)
31903+ _ASM_EXTABLE(31b,100b)
31904+ _ASM_EXTABLE(32b,100b)
31905+ _ASM_EXTABLE(33b,100b)
31906+ _ASM_EXTABLE(34b,100b)
31907+ _ASM_EXTABLE(35b,100b)
31908+ _ASM_EXTABLE(36b,100b)
31909+ _ASM_EXTABLE(37b,100b)
31910+ _ASM_EXTABLE(99b,101b)
31911+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
31912+ : "1"(to), "2"(from), "0"(size)
31913+ : "eax", "edx", "memory");
31914+ return size;
31915+}
31916+
31917+static unsigned long
31918+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
31919+{
31920+ int d0, d1;
31921+ __asm__ __volatile__(
31922+ " .align 2,0x90\n"
31923+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
31924+ " cmpl $67, %0\n"
31925+ " jbe 3f\n"
31926+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
31927+ " .align 2,0x90\n"
31928+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
31929+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
31930+ "5: movl %%eax, 0(%3)\n"
31931+ "6: movl %%edx, 4(%3)\n"
31932+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
31933+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
31934+ "9: movl %%eax, 8(%3)\n"
31935+ "10: movl %%edx, 12(%3)\n"
31936+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
31937+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
31938+ "13: movl %%eax, 16(%3)\n"
31939+ "14: movl %%edx, 20(%3)\n"
31940+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
31941+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
31942+ "17: movl %%eax, 24(%3)\n"
31943+ "18: movl %%edx, 28(%3)\n"
31944+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
31945+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
31946+ "21: movl %%eax, 32(%3)\n"
31947+ "22: movl %%edx, 36(%3)\n"
31948+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
31949+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
31950+ "25: movl %%eax, 40(%3)\n"
31951+ "26: movl %%edx, 44(%3)\n"
31952+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
31953+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
31954+ "29: movl %%eax, 48(%3)\n"
31955+ "30: movl %%edx, 52(%3)\n"
31956+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
31957+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
31958+ "33: movl %%eax, 56(%3)\n"
31959+ "34: movl %%edx, 60(%3)\n"
31960+ " addl $-64, %0\n"
31961+ " addl $64, %4\n"
31962+ " addl $64, %3\n"
31963+ " cmpl $63, %0\n"
31964+ " ja 1b\n"
31965+ "35: movl %0, %%eax\n"
31966+ " shrl $2, %0\n"
31967+ " andl $3, %%eax\n"
31968+ " cld\n"
31969+ "99: rep; "__copyuser_seg" movsl\n"
31970+ "36: movl %%eax, %0\n"
31971+ "37: rep; "__copyuser_seg" movsb\n"
31972+ "100:\n"
31973 ".section .fixup,\"ax\"\n"
31974 "101: lea 0(%%eax,%0,4),%0\n"
31975 " jmp 100b\n"
31976@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31977 int d0, d1;
31978 __asm__ __volatile__(
31979 " .align 2,0x90\n"
31980- "0: movl 32(%4), %%eax\n"
31981+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31982 " cmpl $67, %0\n"
31983 " jbe 2f\n"
31984- "1: movl 64(%4), %%eax\n"
31985+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31986 " .align 2,0x90\n"
31987- "2: movl 0(%4), %%eax\n"
31988- "21: movl 4(%4), %%edx\n"
31989+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31990+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31991 " movl %%eax, 0(%3)\n"
31992 " movl %%edx, 4(%3)\n"
31993- "3: movl 8(%4), %%eax\n"
31994- "31: movl 12(%4),%%edx\n"
31995+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31996+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31997 " movl %%eax, 8(%3)\n"
31998 " movl %%edx, 12(%3)\n"
31999- "4: movl 16(%4), %%eax\n"
32000- "41: movl 20(%4), %%edx\n"
32001+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
32002+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
32003 " movl %%eax, 16(%3)\n"
32004 " movl %%edx, 20(%3)\n"
32005- "10: movl 24(%4), %%eax\n"
32006- "51: movl 28(%4), %%edx\n"
32007+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
32008+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
32009 " movl %%eax, 24(%3)\n"
32010 " movl %%edx, 28(%3)\n"
32011- "11: movl 32(%4), %%eax\n"
32012- "61: movl 36(%4), %%edx\n"
32013+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
32014+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
32015 " movl %%eax, 32(%3)\n"
32016 " movl %%edx, 36(%3)\n"
32017- "12: movl 40(%4), %%eax\n"
32018- "71: movl 44(%4), %%edx\n"
32019+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
32020+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
32021 " movl %%eax, 40(%3)\n"
32022 " movl %%edx, 44(%3)\n"
32023- "13: movl 48(%4), %%eax\n"
32024- "81: movl 52(%4), %%edx\n"
32025+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
32026+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
32027 " movl %%eax, 48(%3)\n"
32028 " movl %%edx, 52(%3)\n"
32029- "14: movl 56(%4), %%eax\n"
32030- "91: movl 60(%4), %%edx\n"
32031+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
32032+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
32033 " movl %%eax, 56(%3)\n"
32034 " movl %%edx, 60(%3)\n"
32035 " addl $-64, %0\n"
32036@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
32037 " shrl $2, %0\n"
32038 " andl $3, %%eax\n"
32039 " cld\n"
32040- "6: rep; movsl\n"
32041+ "6: rep; "__copyuser_seg" movsl\n"
32042 " movl %%eax,%0\n"
32043- "7: rep; movsb\n"
32044+ "7: rep; "__copyuser_seg" movsb\n"
32045 "8:\n"
32046 ".section .fixup,\"ax\"\n"
32047 "9: lea 0(%%eax,%0,4),%0\n"
32048@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
32049
32050 __asm__ __volatile__(
32051 " .align 2,0x90\n"
32052- "0: movl 32(%4), %%eax\n"
32053+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
32054 " cmpl $67, %0\n"
32055 " jbe 2f\n"
32056- "1: movl 64(%4), %%eax\n"
32057+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
32058 " .align 2,0x90\n"
32059- "2: movl 0(%4), %%eax\n"
32060- "21: movl 4(%4), %%edx\n"
32061+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
32062+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
32063 " movnti %%eax, 0(%3)\n"
32064 " movnti %%edx, 4(%3)\n"
32065- "3: movl 8(%4), %%eax\n"
32066- "31: movl 12(%4),%%edx\n"
32067+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
32068+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
32069 " movnti %%eax, 8(%3)\n"
32070 " movnti %%edx, 12(%3)\n"
32071- "4: movl 16(%4), %%eax\n"
32072- "41: movl 20(%4), %%edx\n"
32073+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
32074+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
32075 " movnti %%eax, 16(%3)\n"
32076 " movnti %%edx, 20(%3)\n"
32077- "10: movl 24(%4), %%eax\n"
32078- "51: movl 28(%4), %%edx\n"
32079+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
32080+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
32081 " movnti %%eax, 24(%3)\n"
32082 " movnti %%edx, 28(%3)\n"
32083- "11: movl 32(%4), %%eax\n"
32084- "61: movl 36(%4), %%edx\n"
32085+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
32086+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
32087 " movnti %%eax, 32(%3)\n"
32088 " movnti %%edx, 36(%3)\n"
32089- "12: movl 40(%4), %%eax\n"
32090- "71: movl 44(%4), %%edx\n"
32091+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
32092+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
32093 " movnti %%eax, 40(%3)\n"
32094 " movnti %%edx, 44(%3)\n"
32095- "13: movl 48(%4), %%eax\n"
32096- "81: movl 52(%4), %%edx\n"
32097+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
32098+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
32099 " movnti %%eax, 48(%3)\n"
32100 " movnti %%edx, 52(%3)\n"
32101- "14: movl 56(%4), %%eax\n"
32102- "91: movl 60(%4), %%edx\n"
32103+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
32104+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
32105 " movnti %%eax, 56(%3)\n"
32106 " movnti %%edx, 60(%3)\n"
32107 " addl $-64, %0\n"
32108@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
32109 " shrl $2, %0\n"
32110 " andl $3, %%eax\n"
32111 " cld\n"
32112- "6: rep; movsl\n"
32113+ "6: rep; "__copyuser_seg" movsl\n"
32114 " movl %%eax,%0\n"
32115- "7: rep; movsb\n"
32116+ "7: rep; "__copyuser_seg" movsb\n"
32117 "8:\n"
32118 ".section .fixup,\"ax\"\n"
32119 "9: lea 0(%%eax,%0,4),%0\n"
32120@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
32121
32122 __asm__ __volatile__(
32123 " .align 2,0x90\n"
32124- "0: movl 32(%4), %%eax\n"
32125+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
32126 " cmpl $67, %0\n"
32127 " jbe 2f\n"
32128- "1: movl 64(%4), %%eax\n"
32129+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
32130 " .align 2,0x90\n"
32131- "2: movl 0(%4), %%eax\n"
32132- "21: movl 4(%4), %%edx\n"
32133+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
32134+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
32135 " movnti %%eax, 0(%3)\n"
32136 " movnti %%edx, 4(%3)\n"
32137- "3: movl 8(%4), %%eax\n"
32138- "31: movl 12(%4),%%edx\n"
32139+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
32140+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
32141 " movnti %%eax, 8(%3)\n"
32142 " movnti %%edx, 12(%3)\n"
32143- "4: movl 16(%4), %%eax\n"
32144- "41: movl 20(%4), %%edx\n"
32145+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
32146+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
32147 " movnti %%eax, 16(%3)\n"
32148 " movnti %%edx, 20(%3)\n"
32149- "10: movl 24(%4), %%eax\n"
32150- "51: movl 28(%4), %%edx\n"
32151+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
32152+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
32153 " movnti %%eax, 24(%3)\n"
32154 " movnti %%edx, 28(%3)\n"
32155- "11: movl 32(%4), %%eax\n"
32156- "61: movl 36(%4), %%edx\n"
32157+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
32158+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
32159 " movnti %%eax, 32(%3)\n"
32160 " movnti %%edx, 36(%3)\n"
32161- "12: movl 40(%4), %%eax\n"
32162- "71: movl 44(%4), %%edx\n"
32163+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
32164+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
32165 " movnti %%eax, 40(%3)\n"
32166 " movnti %%edx, 44(%3)\n"
32167- "13: movl 48(%4), %%eax\n"
32168- "81: movl 52(%4), %%edx\n"
32169+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
32170+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
32171 " movnti %%eax, 48(%3)\n"
32172 " movnti %%edx, 52(%3)\n"
32173- "14: movl 56(%4), %%eax\n"
32174- "91: movl 60(%4), %%edx\n"
32175+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
32176+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
32177 " movnti %%eax, 56(%3)\n"
32178 " movnti %%edx, 60(%3)\n"
32179 " addl $-64, %0\n"
32180@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
32181 " shrl $2, %0\n"
32182 " andl $3, %%eax\n"
32183 " cld\n"
32184- "6: rep; movsl\n"
32185+ "6: rep; "__copyuser_seg" movsl\n"
32186 " movl %%eax,%0\n"
32187- "7: rep; movsb\n"
32188+ "7: rep; "__copyuser_seg" movsb\n"
32189 "8:\n"
32190 ".section .fixup,\"ax\"\n"
32191 "9: lea 0(%%eax,%0,4),%0\n"
32192@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
32193 */
32194 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
32195 unsigned long size);
32196-unsigned long __copy_user_intel(void __user *to, const void *from,
32197+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
32198+ unsigned long size);
32199+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
32200 unsigned long size);
32201 unsigned long __copy_user_zeroing_intel_nocache(void *to,
32202 const void __user *from, unsigned long size);
32203 #endif /* CONFIG_X86_INTEL_USERCOPY */
32204
32205 /* Generic arbitrary sized copy. */
32206-#define __copy_user(to, from, size) \
32207+#define __copy_user(to, from, size, prefix, set, restore) \
32208 do { \
32209 int __d0, __d1, __d2; \
32210 __asm__ __volatile__( \
32211+ set \
32212 " cmp $7,%0\n" \
32213 " jbe 1f\n" \
32214 " movl %1,%0\n" \
32215 " negl %0\n" \
32216 " andl $7,%0\n" \
32217 " subl %0,%3\n" \
32218- "4: rep; movsb\n" \
32219+ "4: rep; "prefix"movsb\n" \
32220 " movl %3,%0\n" \
32221 " shrl $2,%0\n" \
32222 " andl $3,%3\n" \
32223 " .align 2,0x90\n" \
32224- "0: rep; movsl\n" \
32225+ "0: rep; "prefix"movsl\n" \
32226 " movl %3,%0\n" \
32227- "1: rep; movsb\n" \
32228+ "1: rep; "prefix"movsb\n" \
32229 "2:\n" \
32230+ restore \
32231 ".section .fixup,\"ax\"\n" \
32232 "5: addl %3,%0\n" \
32233 " jmp 2b\n" \
32234@@ -538,14 +650,14 @@ do { \
32235 " negl %0\n" \
32236 " andl $7,%0\n" \
32237 " subl %0,%3\n" \
32238- "4: rep; movsb\n" \
32239+ "4: rep; "__copyuser_seg"movsb\n" \
32240 " movl %3,%0\n" \
32241 " shrl $2,%0\n" \
32242 " andl $3,%3\n" \
32243 " .align 2,0x90\n" \
32244- "0: rep; movsl\n" \
32245+ "0: rep; "__copyuser_seg"movsl\n" \
32246 " movl %3,%0\n" \
32247- "1: rep; movsb\n" \
32248+ "1: rep; "__copyuser_seg"movsb\n" \
32249 "2:\n" \
32250 ".section .fixup,\"ax\"\n" \
32251 "5: addl %3,%0\n" \
32252@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
32253 {
32254 stac();
32255 if (movsl_is_ok(to, from, n))
32256- __copy_user(to, from, n);
32257+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
32258 else
32259- n = __copy_user_intel(to, from, n);
32260+ n = __generic_copy_to_user_intel(to, from, n);
32261 clac();
32262 return n;
32263 }
32264@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
32265 {
32266 stac();
32267 if (movsl_is_ok(to, from, n))
32268- __copy_user(to, from, n);
32269+ __copy_user(to, from, n, __copyuser_seg, "", "");
32270 else
32271- n = __copy_user_intel((void __user *)to,
32272- (const void *)from, n);
32273+ n = __generic_copy_from_user_intel(to, from, n);
32274 clac();
32275 return n;
32276 }
32277@@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
32278 if (n > 64 && cpu_has_xmm2)
32279 n = __copy_user_intel_nocache(to, from, n);
32280 else
32281- __copy_user(to, from, n);
32282+ __copy_user(to, from, n, __copyuser_seg, "", "");
32283 #else
32284- __copy_user(to, from, n);
32285+ __copy_user(to, from, n, __copyuser_seg, "", "");
32286 #endif
32287 clac();
32288 return n;
32289 }
32290 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
32291
32292-/**
32293- * copy_to_user: - Copy a block of data into user space.
32294- * @to: Destination address, in user space.
32295- * @from: Source address, in kernel space.
32296- * @n: Number of bytes to copy.
32297- *
32298- * Context: User context only. This function may sleep.
32299- *
32300- * Copy data from kernel space to user space.
32301- *
32302- * Returns number of bytes that could not be copied.
32303- * On success, this will be zero.
32304- */
32305-unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
32306+#ifdef CONFIG_PAX_MEMORY_UDEREF
32307+void __set_fs(mm_segment_t x)
32308 {
32309- if (access_ok(VERIFY_WRITE, to, n))
32310- n = __copy_to_user(to, from, n);
32311- return n;
32312+ switch (x.seg) {
32313+ case 0:
32314+ loadsegment(gs, 0);
32315+ break;
32316+ case TASK_SIZE_MAX:
32317+ loadsegment(gs, __USER_DS);
32318+ break;
32319+ case -1UL:
32320+ loadsegment(gs, __KERNEL_DS);
32321+ break;
32322+ default:
32323+ BUG();
32324+ }
32325 }
32326-EXPORT_SYMBOL(_copy_to_user);
32327+EXPORT_SYMBOL(__set_fs);
32328
32329-/**
32330- * copy_from_user: - Copy a block of data from user space.
32331- * @to: Destination address, in kernel space.
32332- * @from: Source address, in user space.
32333- * @n: Number of bytes to copy.
32334- *
32335- * Context: User context only. This function may sleep.
32336- *
32337- * Copy data from user space to kernel space.
32338- *
32339- * Returns number of bytes that could not be copied.
32340- * On success, this will be zero.
32341- *
32342- * If some data could not be copied, this function will pad the copied
32343- * data to the requested size using zero bytes.
32344- */
32345-unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
32346+void set_fs(mm_segment_t x)
32347 {
32348- if (access_ok(VERIFY_READ, from, n))
32349- n = __copy_from_user(to, from, n);
32350- else
32351- memset(to, 0, n);
32352- return n;
32353+ current_thread_info()->addr_limit = x;
32354+ __set_fs(x);
32355 }
32356-EXPORT_SYMBOL(_copy_from_user);
32357+EXPORT_SYMBOL(set_fs);
32358+#endif
32359diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
32360index c905e89..01ab928 100644
32361--- a/arch/x86/lib/usercopy_64.c
32362+++ b/arch/x86/lib/usercopy_64.c
32363@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
32364 might_fault();
32365 /* no memory constraint because it doesn't change any memory gcc knows
32366 about */
32367+ pax_open_userland();
32368 stac();
32369 asm volatile(
32370 " testq %[size8],%[size8]\n"
32371@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
32372 _ASM_EXTABLE(0b,3b)
32373 _ASM_EXTABLE(1b,2b)
32374 : [size8] "=&c"(size), [dst] "=&D" (__d0)
32375- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
32376+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
32377 [zero] "r" (0UL), [eight] "r" (8UL));
32378 clac();
32379+ pax_close_userland();
32380 return size;
32381 }
32382 EXPORT_SYMBOL(__clear_user);
32383@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
32384 }
32385 EXPORT_SYMBOL(clear_user);
32386
32387-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
32388+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
32389 {
32390- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
32391- return copy_user_generic((__force void *)to, (__force void *)from, len);
32392- }
32393- return len;
32394+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
32395+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
32396+ return len;
32397 }
32398 EXPORT_SYMBOL(copy_in_user);
32399
32400@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
32401 * it is not necessary to optimize tail handling.
32402 */
32403 __visible unsigned long
32404-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
32405+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
32406 {
32407 char c;
32408 unsigned zero_len;
32409
32410+ clac();
32411+ pax_close_userland();
32412 for (; len; --len, to++) {
32413 if (__get_user_nocheck(c, from++, sizeof(char)))
32414 break;
32415@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
32416 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
32417 if (__put_user_nocheck(c, to++, sizeof(char)))
32418 break;
32419- clac();
32420 return len;
32421 }
32422diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
32423index 6a19ad9..1c48f9a 100644
32424--- a/arch/x86/mm/Makefile
32425+++ b/arch/x86/mm/Makefile
32426@@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
32427 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
32428
32429 obj-$(CONFIG_MEMTEST) += memtest.o
32430+
32431+quote:="
32432+obj-$(CONFIG_X86_64) += uderef_64.o
32433+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
32434diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
32435index 903ec1e..c4166b2 100644
32436--- a/arch/x86/mm/extable.c
32437+++ b/arch/x86/mm/extable.c
32438@@ -6,12 +6,24 @@
32439 static inline unsigned long
32440 ex_insn_addr(const struct exception_table_entry *x)
32441 {
32442- return (unsigned long)&x->insn + x->insn;
32443+ unsigned long reloc = 0;
32444+
32445+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32446+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32447+#endif
32448+
32449+ return (unsigned long)&x->insn + x->insn + reloc;
32450 }
32451 static inline unsigned long
32452 ex_fixup_addr(const struct exception_table_entry *x)
32453 {
32454- return (unsigned long)&x->fixup + x->fixup;
32455+ unsigned long reloc = 0;
32456+
32457+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32458+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32459+#endif
32460+
32461+ return (unsigned long)&x->fixup + x->fixup + reloc;
32462 }
32463
32464 int fixup_exception(struct pt_regs *regs)
32465@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
32466 unsigned long new_ip;
32467
32468 #ifdef CONFIG_PNPBIOS
32469- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
32470+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
32471 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
32472 extern u32 pnp_bios_is_utter_crap;
32473 pnp_bios_is_utter_crap = 1;
32474@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
32475 i += 4;
32476 p->fixup -= i;
32477 i += 4;
32478+
32479+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32480+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
32481+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32482+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32483+#endif
32484+
32485 }
32486 }
32487
32488diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
32489index a241946..d7a04cf 100644
32490--- a/arch/x86/mm/fault.c
32491+++ b/arch/x86/mm/fault.c
32492@@ -14,12 +14,19 @@
32493 #include <linux/hugetlb.h> /* hstate_index_to_shift */
32494 #include <linux/prefetch.h> /* prefetchw */
32495 #include <linux/context_tracking.h> /* exception_enter(), ... */
32496+#include <linux/unistd.h>
32497+#include <linux/compiler.h>
32498
32499 #include <asm/traps.h> /* dotraplinkage, ... */
32500 #include <asm/pgalloc.h> /* pgd_*(), ... */
32501 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
32502 #include <asm/fixmap.h> /* VSYSCALL_ADDR */
32503 #include <asm/vsyscall.h> /* emulate_vsyscall */
32504+#include <asm/tlbflush.h>
32505+
32506+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32507+#include <asm/stacktrace.h>
32508+#endif
32509
32510 #define CREATE_TRACE_POINTS
32511 #include <asm/trace/exceptions.h>
32512@@ -60,7 +67,7 @@ static nokprobe_inline int kprobes_fault(struct pt_regs *regs)
32513 int ret = 0;
32514
32515 /* kprobe_running() needs smp_processor_id() */
32516- if (kprobes_built_in() && !user_mode_vm(regs)) {
32517+ if (kprobes_built_in() && !user_mode(regs)) {
32518 preempt_disable();
32519 if (kprobe_running() && kprobe_fault_handler(regs, 14))
32520 ret = 1;
32521@@ -121,7 +128,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
32522 return !instr_lo || (instr_lo>>1) == 1;
32523 case 0x00:
32524 /* Prefetch instruction is 0x0F0D or 0x0F18 */
32525- if (probe_kernel_address(instr, opcode))
32526+ if (user_mode(regs)) {
32527+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
32528+ return 0;
32529+ } else if (probe_kernel_address(instr, opcode))
32530 return 0;
32531
32532 *prefetch = (instr_lo == 0xF) &&
32533@@ -155,7 +165,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
32534 while (instr < max_instr) {
32535 unsigned char opcode;
32536
32537- if (probe_kernel_address(instr, opcode))
32538+ if (user_mode(regs)) {
32539+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
32540+ break;
32541+ } else if (probe_kernel_address(instr, opcode))
32542 break;
32543
32544 instr++;
32545@@ -186,6 +199,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
32546 force_sig_info(si_signo, &info, tsk);
32547 }
32548
32549+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32550+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
32551+#endif
32552+
32553+#ifdef CONFIG_PAX_EMUTRAMP
32554+static int pax_handle_fetch_fault(struct pt_regs *regs);
32555+#endif
32556+
32557+#ifdef CONFIG_PAX_PAGEEXEC
32558+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
32559+{
32560+ pgd_t *pgd;
32561+ pud_t *pud;
32562+ pmd_t *pmd;
32563+
32564+ pgd = pgd_offset(mm, address);
32565+ if (!pgd_present(*pgd))
32566+ return NULL;
32567+ pud = pud_offset(pgd, address);
32568+ if (!pud_present(*pud))
32569+ return NULL;
32570+ pmd = pmd_offset(pud, address);
32571+ if (!pmd_present(*pmd))
32572+ return NULL;
32573+ return pmd;
32574+}
32575+#endif
32576+
32577 DEFINE_SPINLOCK(pgd_lock);
32578 LIST_HEAD(pgd_list);
32579
32580@@ -236,10 +277,27 @@ void vmalloc_sync_all(void)
32581 for (address = VMALLOC_START & PMD_MASK;
32582 address >= TASK_SIZE && address < FIXADDR_TOP;
32583 address += PMD_SIZE) {
32584+
32585+#ifdef CONFIG_PAX_PER_CPU_PGD
32586+ unsigned long cpu;
32587+#else
32588 struct page *page;
32589+#endif
32590
32591 spin_lock(&pgd_lock);
32592+
32593+#ifdef CONFIG_PAX_PER_CPU_PGD
32594+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32595+ pgd_t *pgd = get_cpu_pgd(cpu, user);
32596+ pmd_t *ret;
32597+
32598+ ret = vmalloc_sync_one(pgd, address);
32599+ if (!ret)
32600+ break;
32601+ pgd = get_cpu_pgd(cpu, kernel);
32602+#else
32603 list_for_each_entry(page, &pgd_list, lru) {
32604+ pgd_t *pgd;
32605 spinlock_t *pgt_lock;
32606 pmd_t *ret;
32607
32608@@ -247,8 +305,14 @@ void vmalloc_sync_all(void)
32609 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32610
32611 spin_lock(pgt_lock);
32612- ret = vmalloc_sync_one(page_address(page), address);
32613+ pgd = page_address(page);
32614+#endif
32615+
32616+ ret = vmalloc_sync_one(pgd, address);
32617+
32618+#ifndef CONFIG_PAX_PER_CPU_PGD
32619 spin_unlock(pgt_lock);
32620+#endif
32621
32622 if (!ret)
32623 break;
32624@@ -282,6 +346,12 @@ static noinline int vmalloc_fault(unsigned long address)
32625 * an interrupt in the middle of a task switch..
32626 */
32627 pgd_paddr = read_cr3();
32628+
32629+#ifdef CONFIG_PAX_PER_CPU_PGD
32630+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
32631+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
32632+#endif
32633+
32634 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
32635 if (!pmd_k)
32636 return -1;
32637@@ -378,11 +448,25 @@ static noinline int vmalloc_fault(unsigned long address)
32638 * happen within a race in page table update. In the later
32639 * case just flush:
32640 */
32641- pgd = pgd_offset(current->active_mm, address);
32642+
32643 pgd_ref = pgd_offset_k(address);
32644 if (pgd_none(*pgd_ref))
32645 return -1;
32646
32647+#ifdef CONFIG_PAX_PER_CPU_PGD
32648+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
32649+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
32650+ if (pgd_none(*pgd)) {
32651+ set_pgd(pgd, *pgd_ref);
32652+ arch_flush_lazy_mmu_mode();
32653+ } else {
32654+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
32655+ }
32656+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
32657+#else
32658+ pgd = pgd_offset(current->active_mm, address);
32659+#endif
32660+
32661 if (pgd_none(*pgd)) {
32662 set_pgd(pgd, *pgd_ref);
32663 arch_flush_lazy_mmu_mode();
32664@@ -549,7 +633,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
32665 static int is_errata100(struct pt_regs *regs, unsigned long address)
32666 {
32667 #ifdef CONFIG_X86_64
32668- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
32669+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
32670 return 1;
32671 #endif
32672 return 0;
32673@@ -576,9 +660,9 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
32674 }
32675
32676 static const char nx_warning[] = KERN_CRIT
32677-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
32678+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
32679 static const char smep_warning[] = KERN_CRIT
32680-"unable to execute userspace code (SMEP?) (uid: %d)\n";
32681+"unable to execute userspace code (SMEP?) (uid: %d, task: %s, pid: %d)\n";
32682
32683 static void
32684 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32685@@ -587,7 +671,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32686 if (!oops_may_print())
32687 return;
32688
32689- if (error_code & PF_INSTR) {
32690+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
32691 unsigned int level;
32692 pgd_t *pgd;
32693 pte_t *pte;
32694@@ -598,13 +682,25 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32695 pte = lookup_address_in_pgd(pgd, address, &level);
32696
32697 if (pte && pte_present(*pte) && !pte_exec(*pte))
32698- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
32699+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
32700 if (pte && pte_present(*pte) && pte_exec(*pte) &&
32701 (pgd_flags(*pgd) & _PAGE_USER) &&
32702 (read_cr4() & X86_CR4_SMEP))
32703- printk(smep_warning, from_kuid(&init_user_ns, current_uid()));
32704+ printk(smep_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
32705 }
32706
32707+#ifdef CONFIG_PAX_KERNEXEC
32708+ if (init_mm.start_code <= address && address < init_mm.end_code) {
32709+ if (current->signal->curr_ip)
32710+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
32711+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
32712+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32713+ else
32714+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
32715+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32716+ }
32717+#endif
32718+
32719 printk(KERN_ALERT "BUG: unable to handle kernel ");
32720 if (address < PAGE_SIZE)
32721 printk(KERN_CONT "NULL pointer dereference");
32722@@ -785,6 +881,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
32723 return;
32724 }
32725 #endif
32726+
32727+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32728+ if (pax_is_fetch_fault(regs, error_code, address)) {
32729+
32730+#ifdef CONFIG_PAX_EMUTRAMP
32731+ switch (pax_handle_fetch_fault(regs)) {
32732+ case 2:
32733+ return;
32734+ }
32735+#endif
32736+
32737+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32738+ do_group_exit(SIGKILL);
32739+ }
32740+#endif
32741+
32742 /* Kernel addresses are always protection faults: */
32743 if (address >= TASK_SIZE)
32744 error_code |= PF_PROT;
32745@@ -870,7 +982,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
32746 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
32747 printk(KERN_ERR
32748 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
32749- tsk->comm, tsk->pid, address);
32750+ tsk->comm, task_pid_nr(tsk), address);
32751 code = BUS_MCEERR_AR;
32752 }
32753 #endif
32754@@ -924,6 +1036,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
32755 return 1;
32756 }
32757
32758+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32759+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
32760+{
32761+ pte_t *pte;
32762+ pmd_t *pmd;
32763+ spinlock_t *ptl;
32764+ unsigned char pte_mask;
32765+
32766+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
32767+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
32768+ return 0;
32769+
32770+ /* PaX: it's our fault, let's handle it if we can */
32771+
32772+ /* PaX: take a look at read faults before acquiring any locks */
32773+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
32774+ /* instruction fetch attempt from a protected page in user mode */
32775+ up_read(&mm->mmap_sem);
32776+
32777+#ifdef CONFIG_PAX_EMUTRAMP
32778+ switch (pax_handle_fetch_fault(regs)) {
32779+ case 2:
32780+ return 1;
32781+ }
32782+#endif
32783+
32784+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32785+ do_group_exit(SIGKILL);
32786+ }
32787+
32788+ pmd = pax_get_pmd(mm, address);
32789+ if (unlikely(!pmd))
32790+ return 0;
32791+
32792+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
32793+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
32794+ pte_unmap_unlock(pte, ptl);
32795+ return 0;
32796+ }
32797+
32798+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
32799+ /* write attempt to a protected page in user mode */
32800+ pte_unmap_unlock(pte, ptl);
32801+ return 0;
32802+ }
32803+
32804+#ifdef CONFIG_SMP
32805+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
32806+#else
32807+ if (likely(address > get_limit(regs->cs)))
32808+#endif
32809+ {
32810+ set_pte(pte, pte_mkread(*pte));
32811+ __flush_tlb_one(address);
32812+ pte_unmap_unlock(pte, ptl);
32813+ up_read(&mm->mmap_sem);
32814+ return 1;
32815+ }
32816+
32817+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
32818+
32819+ /*
32820+ * PaX: fill DTLB with user rights and retry
32821+ */
32822+ __asm__ __volatile__ (
32823+ "orb %2,(%1)\n"
32824+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
32825+/*
32826+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
32827+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
32828+ * page fault when examined during a TLB load attempt. this is true not only
32829+ * for PTEs holding a non-present entry but also present entries that will
32830+ * raise a page fault (such as those set up by PaX, or the copy-on-write
32831+ * mechanism). in effect it means that we do *not* need to flush the TLBs
32832+ * for our target pages since their PTEs are simply not in the TLBs at all.
32833+
32834+ * the best thing in omitting it is that we gain around 15-20% speed in the
32835+ * fast path of the page fault handler and can get rid of tracing since we
32836+ * can no longer flush unintended entries.
32837+ */
32838+ "invlpg (%0)\n"
32839+#endif
32840+ __copyuser_seg"testb $0,(%0)\n"
32841+ "xorb %3,(%1)\n"
32842+ :
32843+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
32844+ : "memory", "cc");
32845+ pte_unmap_unlock(pte, ptl);
32846+ up_read(&mm->mmap_sem);
32847+ return 1;
32848+}
32849+#endif
32850+
32851 /*
32852 * Handle a spurious fault caused by a stale TLB entry.
32853 *
32854@@ -991,6 +1196,9 @@ int show_unhandled_signals = 1;
32855 static inline int
32856 access_error(unsigned long error_code, struct vm_area_struct *vma)
32857 {
32858+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
32859+ return 1;
32860+
32861 if (error_code & PF_WRITE) {
32862 /* write, present and write, not present: */
32863 if (unlikely(!(vma->vm_flags & VM_WRITE)))
32864@@ -1025,7 +1233,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
32865 if (error_code & PF_USER)
32866 return false;
32867
32868- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
32869+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
32870 return false;
32871
32872 return true;
32873@@ -1053,6 +1261,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32874 tsk = current;
32875 mm = tsk->mm;
32876
32877+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32878+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
32879+ if (!search_exception_tables(regs->ip)) {
32880+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32881+ bad_area_nosemaphore(regs, error_code, address);
32882+ return;
32883+ }
32884+ if (address < pax_user_shadow_base) {
32885+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32886+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
32887+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
32888+ } else
32889+ address -= pax_user_shadow_base;
32890+ }
32891+#endif
32892+
32893 /*
32894 * Detect and handle instructions that would cause a page fault for
32895 * both a tracked kernel page and a userspace page.
32896@@ -1130,7 +1354,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32897 * User-mode registers count as a user access even for any
32898 * potential system fault or CPU buglet:
32899 */
32900- if (user_mode_vm(regs)) {
32901+ if (user_mode(regs)) {
32902 local_irq_enable();
32903 error_code |= PF_USER;
32904 flags |= FAULT_FLAG_USER;
32905@@ -1177,6 +1401,11 @@ retry:
32906 might_sleep();
32907 }
32908
32909+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32910+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
32911+ return;
32912+#endif
32913+
32914 vma = find_vma(mm, address);
32915 if (unlikely(!vma)) {
32916 bad_area(regs, error_code, address);
32917@@ -1188,18 +1417,24 @@ retry:
32918 bad_area(regs, error_code, address);
32919 return;
32920 }
32921- if (error_code & PF_USER) {
32922- /*
32923- * Accessing the stack below %sp is always a bug.
32924- * The large cushion allows instructions like enter
32925- * and pusha to work. ("enter $65535, $31" pushes
32926- * 32 pointers and then decrements %sp by 65535.)
32927- */
32928- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
32929- bad_area(regs, error_code, address);
32930- return;
32931- }
32932+ /*
32933+ * Accessing the stack below %sp is always a bug.
32934+ * The large cushion allows instructions like enter
32935+ * and pusha to work. ("enter $65535, $31" pushes
32936+ * 32 pointers and then decrements %sp by 65535.)
32937+ */
32938+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
32939+ bad_area(regs, error_code, address);
32940+ return;
32941 }
32942+
32943+#ifdef CONFIG_PAX_SEGMEXEC
32944+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
32945+ bad_area(regs, error_code, address);
32946+ return;
32947+ }
32948+#endif
32949+
32950 if (unlikely(expand_stack(vma, address))) {
32951 bad_area(regs, error_code, address);
32952 return;
32953@@ -1316,3 +1551,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
32954 }
32955 NOKPROBE_SYMBOL(trace_do_page_fault);
32956 #endif /* CONFIG_TRACING */
32957+
32958+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32959+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
32960+{
32961+ struct mm_struct *mm = current->mm;
32962+ unsigned long ip = regs->ip;
32963+
32964+ if (v8086_mode(regs))
32965+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
32966+
32967+#ifdef CONFIG_PAX_PAGEEXEC
32968+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
32969+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
32970+ return true;
32971+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
32972+ return true;
32973+ return false;
32974+ }
32975+#endif
32976+
32977+#ifdef CONFIG_PAX_SEGMEXEC
32978+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
32979+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
32980+ return true;
32981+ return false;
32982+ }
32983+#endif
32984+
32985+ return false;
32986+}
32987+#endif
32988+
32989+#ifdef CONFIG_PAX_EMUTRAMP
32990+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
32991+{
32992+ int err;
32993+
32994+ do { /* PaX: libffi trampoline emulation */
32995+ unsigned char mov, jmp;
32996+ unsigned int addr1, addr2;
32997+
32998+#ifdef CONFIG_X86_64
32999+ if ((regs->ip + 9) >> 32)
33000+ break;
33001+#endif
33002+
33003+ err = get_user(mov, (unsigned char __user *)regs->ip);
33004+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
33005+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
33006+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
33007+
33008+ if (err)
33009+ break;
33010+
33011+ if (mov == 0xB8 && jmp == 0xE9) {
33012+ regs->ax = addr1;
33013+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
33014+ return 2;
33015+ }
33016+ } while (0);
33017+
33018+ do { /* PaX: gcc trampoline emulation #1 */
33019+ unsigned char mov1, mov2;
33020+ unsigned short jmp;
33021+ unsigned int addr1, addr2;
33022+
33023+#ifdef CONFIG_X86_64
33024+ if ((regs->ip + 11) >> 32)
33025+ break;
33026+#endif
33027+
33028+ err = get_user(mov1, (unsigned char __user *)regs->ip);
33029+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
33030+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
33031+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
33032+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
33033+
33034+ if (err)
33035+ break;
33036+
33037+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
33038+ regs->cx = addr1;
33039+ regs->ax = addr2;
33040+ regs->ip = addr2;
33041+ return 2;
33042+ }
33043+ } while (0);
33044+
33045+ do { /* PaX: gcc trampoline emulation #2 */
33046+ unsigned char mov, jmp;
33047+ unsigned int addr1, addr2;
33048+
33049+#ifdef CONFIG_X86_64
33050+ if ((regs->ip + 9) >> 32)
33051+ break;
33052+#endif
33053+
33054+ err = get_user(mov, (unsigned char __user *)regs->ip);
33055+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
33056+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
33057+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
33058+
33059+ if (err)
33060+ break;
33061+
33062+ if (mov == 0xB9 && jmp == 0xE9) {
33063+ regs->cx = addr1;
33064+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
33065+ return 2;
33066+ }
33067+ } while (0);
33068+
33069+ return 1; /* PaX in action */
33070+}
33071+
33072+#ifdef CONFIG_X86_64
33073+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
33074+{
33075+ int err;
33076+
33077+ do { /* PaX: libffi trampoline emulation */
33078+ unsigned short mov1, mov2, jmp1;
33079+ unsigned char stcclc, jmp2;
33080+ unsigned long addr1, addr2;
33081+
33082+ err = get_user(mov1, (unsigned short __user *)regs->ip);
33083+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
33084+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
33085+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
33086+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
33087+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
33088+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
33089+
33090+ if (err)
33091+ break;
33092+
33093+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
33094+ regs->r11 = addr1;
33095+ regs->r10 = addr2;
33096+ if (stcclc == 0xF8)
33097+ regs->flags &= ~X86_EFLAGS_CF;
33098+ else
33099+ regs->flags |= X86_EFLAGS_CF;
33100+ regs->ip = addr1;
33101+ return 2;
33102+ }
33103+ } while (0);
33104+
33105+ do { /* PaX: gcc trampoline emulation #1 */
33106+ unsigned short mov1, mov2, jmp1;
33107+ unsigned char jmp2;
33108+ unsigned int addr1;
33109+ unsigned long addr2;
33110+
33111+ err = get_user(mov1, (unsigned short __user *)regs->ip);
33112+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
33113+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
33114+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
33115+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
33116+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
33117+
33118+ if (err)
33119+ break;
33120+
33121+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
33122+ regs->r11 = addr1;
33123+ regs->r10 = addr2;
33124+ regs->ip = addr1;
33125+ return 2;
33126+ }
33127+ } while (0);
33128+
33129+ do { /* PaX: gcc trampoline emulation #2 */
33130+ unsigned short mov1, mov2, jmp1;
33131+ unsigned char jmp2;
33132+ unsigned long addr1, addr2;
33133+
33134+ err = get_user(mov1, (unsigned short __user *)regs->ip);
33135+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
33136+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
33137+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
33138+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
33139+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
33140+
33141+ if (err)
33142+ break;
33143+
33144+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
33145+ regs->r11 = addr1;
33146+ regs->r10 = addr2;
33147+ regs->ip = addr1;
33148+ return 2;
33149+ }
33150+ } while (0);
33151+
33152+ return 1; /* PaX in action */
33153+}
33154+#endif
33155+
33156+/*
33157+ * PaX: decide what to do with offenders (regs->ip = fault address)
33158+ *
33159+ * returns 1 when task should be killed
33160+ * 2 when gcc trampoline was detected
33161+ */
33162+static int pax_handle_fetch_fault(struct pt_regs *regs)
33163+{
33164+ if (v8086_mode(regs))
33165+ return 1;
33166+
33167+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
33168+ return 1;
33169+
33170+#ifdef CONFIG_X86_32
33171+ return pax_handle_fetch_fault_32(regs);
33172+#else
33173+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
33174+ return pax_handle_fetch_fault_32(regs);
33175+ else
33176+ return pax_handle_fetch_fault_64(regs);
33177+#endif
33178+}
33179+#endif
33180+
33181+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
33182+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
33183+{
33184+ long i;
33185+
33186+ printk(KERN_ERR "PAX: bytes at PC: ");
33187+ for (i = 0; i < 20; i++) {
33188+ unsigned char c;
33189+ if (get_user(c, (unsigned char __force_user *)pc+i))
33190+ printk(KERN_CONT "?? ");
33191+ else
33192+ printk(KERN_CONT "%02x ", c);
33193+ }
33194+ printk("\n");
33195+
33196+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
33197+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
33198+ unsigned long c;
33199+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
33200+#ifdef CONFIG_X86_32
33201+ printk(KERN_CONT "???????? ");
33202+#else
33203+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
33204+ printk(KERN_CONT "???????? ???????? ");
33205+ else
33206+ printk(KERN_CONT "???????????????? ");
33207+#endif
33208+ } else {
33209+#ifdef CONFIG_X86_64
33210+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
33211+ printk(KERN_CONT "%08x ", (unsigned int)c);
33212+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
33213+ } else
33214+#endif
33215+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
33216+ }
33217+ }
33218+ printk("\n");
33219+}
33220+#endif
33221+
33222+/**
33223+ * probe_kernel_write(): safely attempt to write to a location
33224+ * @dst: address to write to
33225+ * @src: pointer to the data that shall be written
33226+ * @size: size of the data chunk
33227+ *
33228+ * Safely write to address @dst from the buffer at @src. If a kernel fault
33229+ * happens, handle that and return -EFAULT.
33230+ */
33231+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
33232+{
33233+ long ret;
33234+ mm_segment_t old_fs = get_fs();
33235+
33236+ set_fs(KERNEL_DS);
33237+ pagefault_disable();
33238+ pax_open_kernel();
33239+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
33240+ pax_close_kernel();
33241+ pagefault_enable();
33242+ set_fs(old_fs);
33243+
33244+ return ret ? -EFAULT : 0;
33245+}
33246diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
33247index 207d9aef..69030980 100644
33248--- a/arch/x86/mm/gup.c
33249+++ b/arch/x86/mm/gup.c
33250@@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
33251 addr = start;
33252 len = (unsigned long) nr_pages << PAGE_SHIFT;
33253 end = start + len;
33254- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
33255+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
33256 (void __user *)start, len)))
33257 return 0;
33258
33259@@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
33260 goto slow_irqon;
33261 #endif
33262
33263+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
33264+ (void __user *)start, len)))
33265+ return 0;
33266+
33267 /*
33268 * XXX: batch / limit 'nr', to avoid large irq off latency
33269 * needs some instrumenting to determine the common sizes used by
33270diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
33271index 4500142..53a363c 100644
33272--- a/arch/x86/mm/highmem_32.c
33273+++ b/arch/x86/mm/highmem_32.c
33274@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
33275 idx = type + KM_TYPE_NR*smp_processor_id();
33276 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33277 BUG_ON(!pte_none(*(kmap_pte-idx)));
33278+
33279+ pax_open_kernel();
33280 set_pte(kmap_pte-idx, mk_pte(page, prot));
33281+ pax_close_kernel();
33282+
33283 arch_flush_lazy_mmu_mode();
33284
33285 return (void *)vaddr;
33286diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
33287index 8b977eb..4732c33 100644
33288--- a/arch/x86/mm/hugetlbpage.c
33289+++ b/arch/x86/mm/hugetlbpage.c
33290@@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
33291 #ifdef CONFIG_HUGETLB_PAGE
33292 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
33293 unsigned long addr, unsigned long len,
33294- unsigned long pgoff, unsigned long flags)
33295+ unsigned long pgoff, unsigned long flags, unsigned long offset)
33296 {
33297 struct hstate *h = hstate_file(file);
33298 struct vm_unmapped_area_info info;
33299-
33300+
33301 info.flags = 0;
33302 info.length = len;
33303 info.low_limit = current->mm->mmap_legacy_base;
33304 info.high_limit = TASK_SIZE;
33305 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
33306 info.align_offset = 0;
33307+ info.threadstack_offset = offset;
33308 return vm_unmapped_area(&info);
33309 }
33310
33311 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
33312 unsigned long addr0, unsigned long len,
33313- unsigned long pgoff, unsigned long flags)
33314+ unsigned long pgoff, unsigned long flags, unsigned long offset)
33315 {
33316 struct hstate *h = hstate_file(file);
33317 struct vm_unmapped_area_info info;
33318@@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
33319 info.high_limit = current->mm->mmap_base;
33320 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
33321 info.align_offset = 0;
33322+ info.threadstack_offset = offset;
33323 addr = vm_unmapped_area(&info);
33324
33325 /*
33326@@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
33327 VM_BUG_ON(addr != -ENOMEM);
33328 info.flags = 0;
33329 info.low_limit = TASK_UNMAPPED_BASE;
33330+
33331+#ifdef CONFIG_PAX_RANDMMAP
33332+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
33333+ info.low_limit += current->mm->delta_mmap;
33334+#endif
33335+
33336 info.high_limit = TASK_SIZE;
33337 addr = vm_unmapped_area(&info);
33338 }
33339@@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
33340 struct hstate *h = hstate_file(file);
33341 struct mm_struct *mm = current->mm;
33342 struct vm_area_struct *vma;
33343+ unsigned long pax_task_size = TASK_SIZE;
33344+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
33345
33346 if (len & ~huge_page_mask(h))
33347 return -EINVAL;
33348- if (len > TASK_SIZE)
33349+
33350+#ifdef CONFIG_PAX_SEGMEXEC
33351+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
33352+ pax_task_size = SEGMEXEC_TASK_SIZE;
33353+#endif
33354+
33355+ pax_task_size -= PAGE_SIZE;
33356+
33357+ if (len > pax_task_size)
33358 return -ENOMEM;
33359
33360 if (flags & MAP_FIXED) {
33361@@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
33362 return addr;
33363 }
33364
33365+#ifdef CONFIG_PAX_RANDMMAP
33366+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
33367+#endif
33368+
33369 if (addr) {
33370 addr = ALIGN(addr, huge_page_size(h));
33371 vma = find_vma(mm, addr);
33372- if (TASK_SIZE - len >= addr &&
33373- (!vma || addr + len <= vma->vm_start))
33374+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
33375 return addr;
33376 }
33377 if (mm->get_unmapped_area == arch_get_unmapped_area)
33378 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
33379- pgoff, flags);
33380+ pgoff, flags, offset);
33381 else
33382 return hugetlb_get_unmapped_area_topdown(file, addr, len,
33383- pgoff, flags);
33384+ pgoff, flags, offset);
33385 }
33386 #endif /* CONFIG_HUGETLB_PAGE */
33387
33388diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
33389index 66dba36..f8082ec 100644
33390--- a/arch/x86/mm/init.c
33391+++ b/arch/x86/mm/init.c
33392@@ -4,6 +4,7 @@
33393 #include <linux/swap.h>
33394 #include <linux/memblock.h>
33395 #include <linux/bootmem.h> /* for max_low_pfn */
33396+#include <linux/tboot.h>
33397
33398 #include <asm/cacheflush.h>
33399 #include <asm/e820.h>
33400@@ -17,6 +18,8 @@
33401 #include <asm/proto.h>
33402 #include <asm/dma.h> /* for MAX_DMA_PFN */
33403 #include <asm/microcode.h>
33404+#include <asm/desc.h>
33405+#include <asm/bios_ebda.h>
33406
33407 /*
33408 * We need to define the tracepoints somewhere, and tlb.c
33409@@ -570,7 +573,18 @@ void __init init_mem_mapping(void)
33410 early_ioremap_page_table_range_init();
33411 #endif
33412
33413+#ifdef CONFIG_PAX_PER_CPU_PGD
33414+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
33415+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
33416+ KERNEL_PGD_PTRS);
33417+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
33418+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
33419+ KERNEL_PGD_PTRS);
33420+ load_cr3(get_cpu_pgd(0, kernel));
33421+#else
33422 load_cr3(swapper_pg_dir);
33423+#endif
33424+
33425 __flush_tlb_all();
33426
33427 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
33428@@ -586,10 +600,40 @@ void __init init_mem_mapping(void)
33429 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
33430 * mmio resources as well as potential bios/acpi data regions.
33431 */
33432+
33433+#ifdef CONFIG_GRKERNSEC_KMEM
33434+static unsigned int ebda_start __read_only;
33435+static unsigned int ebda_end __read_only;
33436+#endif
33437+
33438 int devmem_is_allowed(unsigned long pagenr)
33439 {
33440- if (pagenr < 256)
33441+#ifdef CONFIG_GRKERNSEC_KMEM
33442+ /* allow BDA */
33443+ if (!pagenr)
33444 return 1;
33445+ /* allow EBDA */
33446+ if (pagenr >= ebda_start && pagenr < ebda_end)
33447+ return 1;
33448+ /* if tboot is in use, allow access to its hardcoded serial log range */
33449+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
33450+ return 1;
33451+#else
33452+ if (!pagenr)
33453+ return 1;
33454+#ifdef CONFIG_VM86
33455+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
33456+ return 1;
33457+#endif
33458+#endif
33459+
33460+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
33461+ return 1;
33462+#ifdef CONFIG_GRKERNSEC_KMEM
33463+ /* throw out everything else below 1MB */
33464+ if (pagenr <= 256)
33465+ return 0;
33466+#endif
33467 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
33468 return 0;
33469 if (!page_is_ram(pagenr))
33470@@ -635,8 +679,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
33471 #endif
33472 }
33473
33474+#ifdef CONFIG_GRKERNSEC_KMEM
33475+static inline void gr_init_ebda(void)
33476+{
33477+ unsigned int ebda_addr;
33478+ unsigned int ebda_size = 0;
33479+
33480+ ebda_addr = get_bios_ebda();
33481+ if (ebda_addr) {
33482+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
33483+ ebda_size <<= 10;
33484+ }
33485+ if (ebda_addr && ebda_size) {
33486+ ebda_start = ebda_addr >> PAGE_SHIFT;
33487+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
33488+ } else {
33489+ ebda_start = 0x9f000 >> PAGE_SHIFT;
33490+ ebda_end = 0xa0000 >> PAGE_SHIFT;
33491+ }
33492+}
33493+#else
33494+static inline void gr_init_ebda(void) { }
33495+#endif
33496+
33497 void free_initmem(void)
33498 {
33499+#ifdef CONFIG_PAX_KERNEXEC
33500+#ifdef CONFIG_X86_32
33501+ /* PaX: limit KERNEL_CS to actual size */
33502+ unsigned long addr, limit;
33503+ struct desc_struct d;
33504+ int cpu;
33505+#else
33506+ pgd_t *pgd;
33507+ pud_t *pud;
33508+ pmd_t *pmd;
33509+ unsigned long addr, end;
33510+#endif
33511+#endif
33512+
33513+ gr_init_ebda();
33514+
33515+#ifdef CONFIG_PAX_KERNEXEC
33516+#ifdef CONFIG_X86_32
33517+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
33518+ limit = (limit - 1UL) >> PAGE_SHIFT;
33519+
33520+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
33521+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
33522+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
33523+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
33524+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
33525+ }
33526+
33527+ /* PaX: make KERNEL_CS read-only */
33528+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
33529+ if (!paravirt_enabled())
33530+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
33531+/*
33532+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
33533+ pgd = pgd_offset_k(addr);
33534+ pud = pud_offset(pgd, addr);
33535+ pmd = pmd_offset(pud, addr);
33536+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
33537+ }
33538+*/
33539+#ifdef CONFIG_X86_PAE
33540+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
33541+/*
33542+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
33543+ pgd = pgd_offset_k(addr);
33544+ pud = pud_offset(pgd, addr);
33545+ pmd = pmd_offset(pud, addr);
33546+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
33547+ }
33548+*/
33549+#endif
33550+
33551+#ifdef CONFIG_MODULES
33552+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
33553+#endif
33554+
33555+#else
33556+ /* PaX: make kernel code/rodata read-only, rest non-executable */
33557+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
33558+ pgd = pgd_offset_k(addr);
33559+ pud = pud_offset(pgd, addr);
33560+ pmd = pmd_offset(pud, addr);
33561+ if (!pmd_present(*pmd))
33562+ continue;
33563+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
33564+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
33565+ else
33566+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
33567+ }
33568+
33569+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
33570+ end = addr + KERNEL_IMAGE_SIZE;
33571+ for (; addr < end; addr += PMD_SIZE) {
33572+ pgd = pgd_offset_k(addr);
33573+ pud = pud_offset(pgd, addr);
33574+ pmd = pmd_offset(pud, addr);
33575+ if (!pmd_present(*pmd))
33576+ continue;
33577+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
33578+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
33579+ }
33580+#endif
33581+
33582+ flush_tlb_all();
33583+#endif
33584+
33585 free_init_pages("unused kernel",
33586 (unsigned long)(&__init_begin),
33587 (unsigned long)(&__init_end));
33588diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
33589index 7d05565..bfc5338 100644
33590--- a/arch/x86/mm/init_32.c
33591+++ b/arch/x86/mm/init_32.c
33592@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
33593 bool __read_mostly __vmalloc_start_set = false;
33594
33595 /*
33596- * Creates a middle page table and puts a pointer to it in the
33597- * given global directory entry. This only returns the gd entry
33598- * in non-PAE compilation mode, since the middle layer is folded.
33599- */
33600-static pmd_t * __init one_md_table_init(pgd_t *pgd)
33601-{
33602- pud_t *pud;
33603- pmd_t *pmd_table;
33604-
33605-#ifdef CONFIG_X86_PAE
33606- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
33607- pmd_table = (pmd_t *)alloc_low_page();
33608- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
33609- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
33610- pud = pud_offset(pgd, 0);
33611- BUG_ON(pmd_table != pmd_offset(pud, 0));
33612-
33613- return pmd_table;
33614- }
33615-#endif
33616- pud = pud_offset(pgd, 0);
33617- pmd_table = pmd_offset(pud, 0);
33618-
33619- return pmd_table;
33620-}
33621-
33622-/*
33623 * Create a page table and place a pointer to it in a middle page
33624 * directory entry:
33625 */
33626@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
33627 pte_t *page_table = (pte_t *)alloc_low_page();
33628
33629 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
33630+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
33631+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
33632+#else
33633 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
33634+#endif
33635 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
33636 }
33637
33638 return pte_offset_kernel(pmd, 0);
33639 }
33640
33641+static pmd_t * __init one_md_table_init(pgd_t *pgd)
33642+{
33643+ pud_t *pud;
33644+ pmd_t *pmd_table;
33645+
33646+ pud = pud_offset(pgd, 0);
33647+ pmd_table = pmd_offset(pud, 0);
33648+
33649+ return pmd_table;
33650+}
33651+
33652 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
33653 {
33654 int pgd_idx = pgd_index(vaddr);
33655@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33656 int pgd_idx, pmd_idx;
33657 unsigned long vaddr;
33658 pgd_t *pgd;
33659+ pud_t *pud;
33660 pmd_t *pmd;
33661 pte_t *pte = NULL;
33662 unsigned long count = page_table_range_init_count(start, end);
33663@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33664 pgd = pgd_base + pgd_idx;
33665
33666 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
33667- pmd = one_md_table_init(pgd);
33668- pmd = pmd + pmd_index(vaddr);
33669+ pud = pud_offset(pgd, vaddr);
33670+ pmd = pmd_offset(pud, vaddr);
33671+
33672+#ifdef CONFIG_X86_PAE
33673+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33674+#endif
33675+
33676 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
33677 pmd++, pmd_idx++) {
33678 pte = page_table_kmap_check(one_page_table_init(pmd),
33679@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33680 }
33681 }
33682
33683-static inline int is_kernel_text(unsigned long addr)
33684+static inline int is_kernel_text(unsigned long start, unsigned long end)
33685 {
33686- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
33687- return 1;
33688- return 0;
33689+ if ((start >= ktla_ktva((unsigned long)_etext) ||
33690+ end <= ktla_ktva((unsigned long)_stext)) &&
33691+ (start >= ktla_ktva((unsigned long)_einittext) ||
33692+ end <= ktla_ktva((unsigned long)_sinittext)) &&
33693+
33694+#ifdef CONFIG_ACPI_SLEEP
33695+ (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
33696+#endif
33697+
33698+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
33699+ return 0;
33700+ return 1;
33701 }
33702
33703 /*
33704@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
33705 unsigned long last_map_addr = end;
33706 unsigned long start_pfn, end_pfn;
33707 pgd_t *pgd_base = swapper_pg_dir;
33708- int pgd_idx, pmd_idx, pte_ofs;
33709+ unsigned int pgd_idx, pmd_idx, pte_ofs;
33710 unsigned long pfn;
33711 pgd_t *pgd;
33712+ pud_t *pud;
33713 pmd_t *pmd;
33714 pte_t *pte;
33715 unsigned pages_2m, pages_4k;
33716@@ -291,8 +295,13 @@ repeat:
33717 pfn = start_pfn;
33718 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33719 pgd = pgd_base + pgd_idx;
33720- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
33721- pmd = one_md_table_init(pgd);
33722+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
33723+ pud = pud_offset(pgd, 0);
33724+ pmd = pmd_offset(pud, 0);
33725+
33726+#ifdef CONFIG_X86_PAE
33727+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33728+#endif
33729
33730 if (pfn >= end_pfn)
33731 continue;
33732@@ -304,14 +313,13 @@ repeat:
33733 #endif
33734 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
33735 pmd++, pmd_idx++) {
33736- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
33737+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
33738
33739 /*
33740 * Map with big pages if possible, otherwise
33741 * create normal page tables:
33742 */
33743 if (use_pse) {
33744- unsigned int addr2;
33745 pgprot_t prot = PAGE_KERNEL_LARGE;
33746 /*
33747 * first pass will use the same initial
33748@@ -322,11 +330,7 @@ repeat:
33749 _PAGE_PSE);
33750
33751 pfn &= PMD_MASK >> PAGE_SHIFT;
33752- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
33753- PAGE_OFFSET + PAGE_SIZE-1;
33754-
33755- if (is_kernel_text(addr) ||
33756- is_kernel_text(addr2))
33757+ if (is_kernel_text(address, address + PMD_SIZE))
33758 prot = PAGE_KERNEL_LARGE_EXEC;
33759
33760 pages_2m++;
33761@@ -343,7 +347,7 @@ repeat:
33762 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33763 pte += pte_ofs;
33764 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
33765- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
33766+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
33767 pgprot_t prot = PAGE_KERNEL;
33768 /*
33769 * first pass will use the same initial
33770@@ -351,7 +355,7 @@ repeat:
33771 */
33772 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
33773
33774- if (is_kernel_text(addr))
33775+ if (is_kernel_text(address, address + PAGE_SIZE))
33776 prot = PAGE_KERNEL_EXEC;
33777
33778 pages_4k++;
33779@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
33780
33781 pud = pud_offset(pgd, va);
33782 pmd = pmd_offset(pud, va);
33783- if (!pmd_present(*pmd))
33784+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
33785 break;
33786
33787 /* should not be large page here */
33788@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
33789
33790 static void __init pagetable_init(void)
33791 {
33792- pgd_t *pgd_base = swapper_pg_dir;
33793-
33794- permanent_kmaps_init(pgd_base);
33795+ permanent_kmaps_init(swapper_pg_dir);
33796 }
33797
33798-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
33799+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
33800 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33801
33802 /* user-defined highmem size */
33803@@ -787,10 +789,10 @@ void __init mem_init(void)
33804 ((unsigned long)&__init_end -
33805 (unsigned long)&__init_begin) >> 10,
33806
33807- (unsigned long)&_etext, (unsigned long)&_edata,
33808- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
33809+ (unsigned long)&_sdata, (unsigned long)&_edata,
33810+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
33811
33812- (unsigned long)&_text, (unsigned long)&_etext,
33813+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
33814 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
33815
33816 /*
33817@@ -884,6 +886,7 @@ void set_kernel_text_rw(void)
33818 if (!kernel_set_to_readonly)
33819 return;
33820
33821+ start = ktla_ktva(start);
33822 pr_debug("Set kernel text: %lx - %lx for read write\n",
33823 start, start+size);
33824
33825@@ -898,6 +901,7 @@ void set_kernel_text_ro(void)
33826 if (!kernel_set_to_readonly)
33827 return;
33828
33829+ start = ktla_ktva(start);
33830 pr_debug("Set kernel text: %lx - %lx for read only\n",
33831 start, start+size);
33832
33833@@ -926,6 +930,7 @@ void mark_rodata_ro(void)
33834 unsigned long start = PFN_ALIGN(_text);
33835 unsigned long size = PFN_ALIGN(_etext) - start;
33836
33837+ start = ktla_ktva(start);
33838 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
33839 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
33840 size >> 10);
33841diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
33842index ac7de5f..ceb56df 100644
33843--- a/arch/x86/mm/init_64.c
33844+++ b/arch/x86/mm/init_64.c
33845@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
33846 * around without checking the pgd every time.
33847 */
33848
33849-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
33850+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
33851 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33852
33853 int force_personality32;
33854@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33855
33856 for (address = start; address <= end; address += PGDIR_SIZE) {
33857 const pgd_t *pgd_ref = pgd_offset_k(address);
33858+
33859+#ifdef CONFIG_PAX_PER_CPU_PGD
33860+ unsigned long cpu;
33861+#else
33862 struct page *page;
33863+#endif
33864
33865 if (pgd_none(*pgd_ref))
33866 continue;
33867
33868 spin_lock(&pgd_lock);
33869+
33870+#ifdef CONFIG_PAX_PER_CPU_PGD
33871+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33872+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
33873+
33874+ if (pgd_none(*pgd))
33875+ set_pgd(pgd, *pgd_ref);
33876+ else
33877+ BUG_ON(pgd_page_vaddr(*pgd)
33878+ != pgd_page_vaddr(*pgd_ref));
33879+ pgd = pgd_offset_cpu(cpu, kernel, address);
33880+#else
33881 list_for_each_entry(page, &pgd_list, lru) {
33882 pgd_t *pgd;
33883 spinlock_t *pgt_lock;
33884@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33885 /* the pgt_lock only for Xen */
33886 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
33887 spin_lock(pgt_lock);
33888+#endif
33889
33890 if (pgd_none(*pgd))
33891 set_pgd(pgd, *pgd_ref);
33892@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33893 BUG_ON(pgd_page_vaddr(*pgd)
33894 != pgd_page_vaddr(*pgd_ref));
33895
33896+#ifndef CONFIG_PAX_PER_CPU_PGD
33897 spin_unlock(pgt_lock);
33898+#endif
33899+
33900 }
33901 spin_unlock(&pgd_lock);
33902 }
33903@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
33904 {
33905 if (pgd_none(*pgd)) {
33906 pud_t *pud = (pud_t *)spp_getpage();
33907- pgd_populate(&init_mm, pgd, pud);
33908+ pgd_populate_kernel(&init_mm, pgd, pud);
33909 if (pud != pud_offset(pgd, 0))
33910 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
33911 pud, pud_offset(pgd, 0));
33912@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
33913 {
33914 if (pud_none(*pud)) {
33915 pmd_t *pmd = (pmd_t *) spp_getpage();
33916- pud_populate(&init_mm, pud, pmd);
33917+ pud_populate_kernel(&init_mm, pud, pmd);
33918 if (pmd != pmd_offset(pud, 0))
33919 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
33920 pmd, pmd_offset(pud, 0));
33921@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
33922 pmd = fill_pmd(pud, vaddr);
33923 pte = fill_pte(pmd, vaddr);
33924
33925+ pax_open_kernel();
33926 set_pte(pte, new_pte);
33927+ pax_close_kernel();
33928
33929 /*
33930 * It's enough to flush this one mapping.
33931@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
33932 pgd = pgd_offset_k((unsigned long)__va(phys));
33933 if (pgd_none(*pgd)) {
33934 pud = (pud_t *) spp_getpage();
33935- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
33936- _PAGE_USER));
33937+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
33938 }
33939 pud = pud_offset(pgd, (unsigned long)__va(phys));
33940 if (pud_none(*pud)) {
33941 pmd = (pmd_t *) spp_getpage();
33942- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
33943- _PAGE_USER));
33944+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
33945 }
33946 pmd = pmd_offset(pud, phys);
33947 BUG_ON(!pmd_none(*pmd));
33948@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
33949 prot);
33950
33951 spin_lock(&init_mm.page_table_lock);
33952- pud_populate(&init_mm, pud, pmd);
33953+ pud_populate_kernel(&init_mm, pud, pmd);
33954 spin_unlock(&init_mm.page_table_lock);
33955 }
33956 __flush_tlb_all();
33957@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
33958 page_size_mask);
33959
33960 spin_lock(&init_mm.page_table_lock);
33961- pgd_populate(&init_mm, pgd, pud);
33962+ pgd_populate_kernel(&init_mm, pgd, pud);
33963 spin_unlock(&init_mm.page_table_lock);
33964 pgd_changed = true;
33965 }
33966@@ -1205,8 +1226,8 @@ static struct vm_operations_struct gate_vma_ops = {
33967 static struct vm_area_struct gate_vma = {
33968 .vm_start = VSYSCALL_ADDR,
33969 .vm_end = VSYSCALL_ADDR + PAGE_SIZE,
33970- .vm_page_prot = PAGE_READONLY_EXEC,
33971- .vm_flags = VM_READ | VM_EXEC,
33972+ .vm_page_prot = PAGE_READONLY,
33973+ .vm_flags = VM_READ,
33974 .vm_ops = &gate_vma_ops,
33975 };
33976
33977diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
33978index 7b179b49..6bd17777 100644
33979--- a/arch/x86/mm/iomap_32.c
33980+++ b/arch/x86/mm/iomap_32.c
33981@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
33982 type = kmap_atomic_idx_push();
33983 idx = type + KM_TYPE_NR * smp_processor_id();
33984 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33985+
33986+ pax_open_kernel();
33987 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
33988+ pax_close_kernel();
33989+
33990 arch_flush_lazy_mmu_mode();
33991
33992 return (void *)vaddr;
33993diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
33994index baff1da..2816ef4 100644
33995--- a/arch/x86/mm/ioremap.c
33996+++ b/arch/x86/mm/ioremap.c
33997@@ -56,8 +56,8 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages,
33998 unsigned long i;
33999
34000 for (i = 0; i < nr_pages; ++i)
34001- if (pfn_valid(start_pfn + i) &&
34002- !PageReserved(pfn_to_page(start_pfn + i)))
34003+ if (pfn_valid(start_pfn + i) && (start_pfn + i >= 0x100 ||
34004+ !PageReserved(pfn_to_page(start_pfn + i))))
34005 return 1;
34006
34007 WARN_ONCE(1, "ioremap on RAM pfn 0x%lx\n", start_pfn);
34008@@ -268,7 +268,7 @@ EXPORT_SYMBOL(ioremap_prot);
34009 *
34010 * Caller must ensure there is only one unmapping for the same pointer.
34011 */
34012-void iounmap(volatile void __iomem *addr)
34013+void iounmap(const volatile void __iomem *addr)
34014 {
34015 struct vm_struct *p, *o;
34016
34017@@ -322,6 +322,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
34018
34019 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
34020 if (page_is_ram(start >> PAGE_SHIFT))
34021+#ifdef CONFIG_HIGHMEM
34022+ if ((start >> PAGE_SHIFT) < max_low_pfn)
34023+#endif
34024 return __va(phys);
34025
34026 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
34027@@ -334,13 +337,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
34028 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
34029 {
34030 if (page_is_ram(phys >> PAGE_SHIFT))
34031+#ifdef CONFIG_HIGHMEM
34032+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
34033+#endif
34034 return;
34035
34036 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
34037 return;
34038 }
34039
34040-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
34041+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
34042
34043 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
34044 {
34045@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
34046 early_ioremap_setup();
34047
34048 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
34049- memset(bm_pte, 0, sizeof(bm_pte));
34050- pmd_populate_kernel(&init_mm, pmd, bm_pte);
34051+ pmd_populate_user(&init_mm, pmd, bm_pte);
34052
34053 /*
34054 * The boot-ioremap range spans multiple pmds, for which
34055diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
34056index dd89a13..d77bdcc 100644
34057--- a/arch/x86/mm/kmemcheck/kmemcheck.c
34058+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
34059@@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
34060 * memory (e.g. tracked pages)? For now, we need this to avoid
34061 * invoking kmemcheck for PnP BIOS calls.
34062 */
34063- if (regs->flags & X86_VM_MASK)
34064+ if (v8086_mode(regs))
34065 return false;
34066- if (regs->cs != __KERNEL_CS)
34067+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
34068 return false;
34069
34070 pte = kmemcheck_pte_lookup(address);
34071diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
34072index 919b912..9267313 100644
34073--- a/arch/x86/mm/mmap.c
34074+++ b/arch/x86/mm/mmap.c
34075@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
34076 * Leave an at least ~128 MB hole with possible stack randomization.
34077 */
34078 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
34079-#define MAX_GAP (TASK_SIZE/6*5)
34080+#define MAX_GAP (pax_task_size/6*5)
34081
34082 static int mmap_is_legacy(void)
34083 {
34084@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
34085 return rnd << PAGE_SHIFT;
34086 }
34087
34088-static unsigned long mmap_base(void)
34089+static unsigned long mmap_base(struct mm_struct *mm)
34090 {
34091 unsigned long gap = rlimit(RLIMIT_STACK);
34092+ unsigned long pax_task_size = TASK_SIZE;
34093+
34094+#ifdef CONFIG_PAX_SEGMEXEC
34095+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
34096+ pax_task_size = SEGMEXEC_TASK_SIZE;
34097+#endif
34098
34099 if (gap < MIN_GAP)
34100 gap = MIN_GAP;
34101 else if (gap > MAX_GAP)
34102 gap = MAX_GAP;
34103
34104- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
34105+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
34106 }
34107
34108 /*
34109 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
34110 * does, but not when emulating X86_32
34111 */
34112-static unsigned long mmap_legacy_base(void)
34113+static unsigned long mmap_legacy_base(struct mm_struct *mm)
34114 {
34115- if (mmap_is_ia32())
34116+ if (mmap_is_ia32()) {
34117+
34118+#ifdef CONFIG_PAX_SEGMEXEC
34119+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
34120+ return SEGMEXEC_TASK_UNMAPPED_BASE;
34121+ else
34122+#endif
34123+
34124 return TASK_UNMAPPED_BASE;
34125- else
34126+ } else
34127 return TASK_UNMAPPED_BASE + mmap_rnd();
34128 }
34129
34130@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
34131 */
34132 void arch_pick_mmap_layout(struct mm_struct *mm)
34133 {
34134- mm->mmap_legacy_base = mmap_legacy_base();
34135- mm->mmap_base = mmap_base();
34136+ mm->mmap_legacy_base = mmap_legacy_base(mm);
34137+ mm->mmap_base = mmap_base(mm);
34138+
34139+#ifdef CONFIG_PAX_RANDMMAP
34140+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
34141+ mm->mmap_legacy_base += mm->delta_mmap;
34142+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
34143+ }
34144+#endif
34145
34146 if (mmap_is_legacy()) {
34147 mm->mmap_base = mm->mmap_legacy_base;
34148diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
34149index 0057a7a..95c7edd 100644
34150--- a/arch/x86/mm/mmio-mod.c
34151+++ b/arch/x86/mm/mmio-mod.c
34152@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
34153 break;
34154 default:
34155 {
34156- unsigned char *ip = (unsigned char *)instptr;
34157+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
34158 my_trace->opcode = MMIO_UNKNOWN_OP;
34159 my_trace->width = 0;
34160 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
34161@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
34162 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
34163 void __iomem *addr)
34164 {
34165- static atomic_t next_id;
34166+ static atomic_unchecked_t next_id;
34167 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
34168 /* These are page-unaligned. */
34169 struct mmiotrace_map map = {
34170@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
34171 .private = trace
34172 },
34173 .phys = offset,
34174- .id = atomic_inc_return(&next_id)
34175+ .id = atomic_inc_return_unchecked(&next_id)
34176 };
34177 map.map_id = trace->id;
34178
34179@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
34180 ioremap_trace_core(offset, size, addr);
34181 }
34182
34183-static void iounmap_trace_core(volatile void __iomem *addr)
34184+static void iounmap_trace_core(const volatile void __iomem *addr)
34185 {
34186 struct mmiotrace_map map = {
34187 .phys = 0,
34188@@ -328,7 +328,7 @@ not_enabled:
34189 }
34190 }
34191
34192-void mmiotrace_iounmap(volatile void __iomem *addr)
34193+void mmiotrace_iounmap(const volatile void __iomem *addr)
34194 {
34195 might_sleep();
34196 if (is_enabled()) /* recheck and proper locking in *_core() */
34197diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
34198index a32b706..efb308b 100644
34199--- a/arch/x86/mm/numa.c
34200+++ b/arch/x86/mm/numa.c
34201@@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
34202 return true;
34203 }
34204
34205-static int __init numa_register_memblks(struct numa_meminfo *mi)
34206+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
34207 {
34208 unsigned long uninitialized_var(pfn_align);
34209 int i, nid;
34210diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
34211index 36de293..b820ddc 100644
34212--- a/arch/x86/mm/pageattr.c
34213+++ b/arch/x86/mm/pageattr.c
34214@@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34215 */
34216 #ifdef CONFIG_PCI_BIOS
34217 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
34218- pgprot_val(forbidden) |= _PAGE_NX;
34219+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
34220 #endif
34221
34222 /*
34223@@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34224 * Does not cover __inittext since that is gone later on. On
34225 * 64bit we do not enforce !NX on the low mapping
34226 */
34227- if (within(address, (unsigned long)_text, (unsigned long)_etext))
34228- pgprot_val(forbidden) |= _PAGE_NX;
34229+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
34230+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
34231
34232+#ifdef CONFIG_DEBUG_RODATA
34233 /*
34234 * The .rodata section needs to be read-only. Using the pfn
34235 * catches all aliases.
34236@@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34237 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
34238 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
34239 pgprot_val(forbidden) |= _PAGE_RW;
34240+#endif
34241
34242 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
34243 /*
34244@@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34245 }
34246 #endif
34247
34248+#ifdef CONFIG_PAX_KERNEXEC
34249+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
34250+ pgprot_val(forbidden) |= _PAGE_RW;
34251+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
34252+ }
34253+#endif
34254+
34255 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
34256
34257 return prot;
34258@@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
34259 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
34260 {
34261 /* change init_mm */
34262+ pax_open_kernel();
34263 set_pte_atomic(kpte, pte);
34264+
34265 #ifdef CONFIG_X86_32
34266 if (!SHARED_KERNEL_PMD) {
34267+
34268+#ifdef CONFIG_PAX_PER_CPU_PGD
34269+ unsigned long cpu;
34270+#else
34271 struct page *page;
34272+#endif
34273
34274+#ifdef CONFIG_PAX_PER_CPU_PGD
34275+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
34276+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
34277+#else
34278 list_for_each_entry(page, &pgd_list, lru) {
34279- pgd_t *pgd;
34280+ pgd_t *pgd = (pgd_t *)page_address(page);
34281+#endif
34282+
34283 pud_t *pud;
34284 pmd_t *pmd;
34285
34286- pgd = (pgd_t *)page_address(page) + pgd_index(address);
34287+ pgd += pgd_index(address);
34288 pud = pud_offset(pgd, address);
34289 pmd = pmd_offset(pud, address);
34290 set_pte_atomic((pte_t *)pmd, pte);
34291 }
34292 }
34293 #endif
34294+ pax_close_kernel();
34295 }
34296
34297 static int
34298diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
34299index 6574388..87e9bef 100644
34300--- a/arch/x86/mm/pat.c
34301+++ b/arch/x86/mm/pat.c
34302@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
34303
34304 if (!entry) {
34305 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
34306- current->comm, current->pid, start, end - 1);
34307+ current->comm, task_pid_nr(current), start, end - 1);
34308 return -EINVAL;
34309 }
34310
34311@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34312
34313 while (cursor < to) {
34314 if (!devmem_is_allowed(pfn)) {
34315- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
34316- current->comm, from, to - 1);
34317+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
34318+ current->comm, from, to - 1, cursor);
34319 return 0;
34320 }
34321 cursor += PAGE_SIZE;
34322@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
34323 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
34324 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
34325 "for [mem %#010Lx-%#010Lx]\n",
34326- current->comm, current->pid,
34327+ current->comm, task_pid_nr(current),
34328 cattr_name(flags),
34329 base, (unsigned long long)(base + size-1));
34330 return -EINVAL;
34331@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
34332 flags = lookup_memtype(paddr);
34333 if (want_flags != flags) {
34334 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
34335- current->comm, current->pid,
34336+ current->comm, task_pid_nr(current),
34337 cattr_name(want_flags),
34338 (unsigned long long)paddr,
34339 (unsigned long long)(paddr + size - 1),
34340@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
34341 free_memtype(paddr, paddr + size);
34342 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
34343 " for [mem %#010Lx-%#010Lx], got %s\n",
34344- current->comm, current->pid,
34345+ current->comm, task_pid_nr(current),
34346 cattr_name(want_flags),
34347 (unsigned long long)paddr,
34348 (unsigned long long)(paddr + size - 1),
34349diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
34350index 415f6c4..d319983 100644
34351--- a/arch/x86/mm/pat_rbtree.c
34352+++ b/arch/x86/mm/pat_rbtree.c
34353@@ -160,7 +160,7 @@ success:
34354
34355 failure:
34356 printk(KERN_INFO "%s:%d conflicting memory types "
34357- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
34358+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
34359 end, cattr_name(found_type), cattr_name(match->type));
34360 return -EBUSY;
34361 }
34362diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
34363index 9f0614d..92ae64a 100644
34364--- a/arch/x86/mm/pf_in.c
34365+++ b/arch/x86/mm/pf_in.c
34366@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
34367 int i;
34368 enum reason_type rv = OTHERS;
34369
34370- p = (unsigned char *)ins_addr;
34371+ p = (unsigned char *)ktla_ktva(ins_addr);
34372 p += skip_prefix(p, &prf);
34373 p += get_opcode(p, &opcode);
34374
34375@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
34376 struct prefix_bits prf;
34377 int i;
34378
34379- p = (unsigned char *)ins_addr;
34380+ p = (unsigned char *)ktla_ktva(ins_addr);
34381 p += skip_prefix(p, &prf);
34382 p += get_opcode(p, &opcode);
34383
34384@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
34385 struct prefix_bits prf;
34386 int i;
34387
34388- p = (unsigned char *)ins_addr;
34389+ p = (unsigned char *)ktla_ktva(ins_addr);
34390 p += skip_prefix(p, &prf);
34391 p += get_opcode(p, &opcode);
34392
34393@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
34394 struct prefix_bits prf;
34395 int i;
34396
34397- p = (unsigned char *)ins_addr;
34398+ p = (unsigned char *)ktla_ktva(ins_addr);
34399 p += skip_prefix(p, &prf);
34400 p += get_opcode(p, &opcode);
34401 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
34402@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
34403 struct prefix_bits prf;
34404 int i;
34405
34406- p = (unsigned char *)ins_addr;
34407+ p = (unsigned char *)ktla_ktva(ins_addr);
34408 p += skip_prefix(p, &prf);
34409 p += get_opcode(p, &opcode);
34410 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
34411diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
34412index 6fb6927..4fc13c0 100644
34413--- a/arch/x86/mm/pgtable.c
34414+++ b/arch/x86/mm/pgtable.c
34415@@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
34416 list_del(&page->lru);
34417 }
34418
34419-#define UNSHARED_PTRS_PER_PGD \
34420- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
34421+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
34422+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
34423
34424+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
34425+{
34426+ unsigned int count = USER_PGD_PTRS;
34427
34428+ if (!pax_user_shadow_base)
34429+ return;
34430+
34431+ while (count--)
34432+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
34433+}
34434+#endif
34435+
34436+#ifdef CONFIG_PAX_PER_CPU_PGD
34437+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
34438+{
34439+ unsigned int count = USER_PGD_PTRS;
34440+
34441+ while (count--) {
34442+ pgd_t pgd;
34443+
34444+#ifdef CONFIG_X86_64
34445+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
34446+#else
34447+ pgd = *src++;
34448+#endif
34449+
34450+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
34451+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
34452+#endif
34453+
34454+ *dst++ = pgd;
34455+ }
34456+
34457+}
34458+#endif
34459+
34460+#ifdef CONFIG_X86_64
34461+#define pxd_t pud_t
34462+#define pyd_t pgd_t
34463+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
34464+#define pgtable_pxd_page_ctor(page) true
34465+#define pgtable_pxd_page_dtor(page)
34466+#define pxd_free(mm, pud) pud_free((mm), (pud))
34467+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
34468+#define pyd_offset(mm, address) pgd_offset((mm), (address))
34469+#define PYD_SIZE PGDIR_SIZE
34470+#else
34471+#define pxd_t pmd_t
34472+#define pyd_t pud_t
34473+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
34474+#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
34475+#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
34476+#define pxd_free(mm, pud) pmd_free((mm), (pud))
34477+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
34478+#define pyd_offset(mm, address) pud_offset((mm), (address))
34479+#define PYD_SIZE PUD_SIZE
34480+#endif
34481+
34482+#ifdef CONFIG_PAX_PER_CPU_PGD
34483+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
34484+static inline void pgd_dtor(pgd_t *pgd) {}
34485+#else
34486 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
34487 {
34488 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
34489@@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
34490 pgd_list_del(pgd);
34491 spin_unlock(&pgd_lock);
34492 }
34493+#endif
34494
34495 /*
34496 * List of all pgd's needed for non-PAE so it can invalidate entries
34497@@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
34498 * -- nyc
34499 */
34500
34501-#ifdef CONFIG_X86_PAE
34502+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
34503 /*
34504 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
34505 * updating the top-level pagetable entries to guarantee the
34506@@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
34507 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
34508 * and initialize the kernel pmds here.
34509 */
34510-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
34511+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
34512
34513 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
34514 {
34515@@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
34516 */
34517 flush_tlb_mm(mm);
34518 }
34519+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
34520+#define PREALLOCATED_PXDS USER_PGD_PTRS
34521 #else /* !CONFIG_X86_PAE */
34522
34523 /* No need to prepopulate any pagetable entries in non-PAE modes. */
34524-#define PREALLOCATED_PMDS 0
34525+#define PREALLOCATED_PXDS 0
34526
34527 #endif /* CONFIG_X86_PAE */
34528
34529-static void free_pmds(pmd_t *pmds[])
34530+static void free_pxds(pxd_t *pxds[])
34531 {
34532 int i;
34533
34534- for(i = 0; i < PREALLOCATED_PMDS; i++)
34535- if (pmds[i]) {
34536- pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
34537- free_page((unsigned long)pmds[i]);
34538+ for(i = 0; i < PREALLOCATED_PXDS; i++)
34539+ if (pxds[i]) {
34540+ pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
34541+ free_page((unsigned long)pxds[i]);
34542 }
34543 }
34544
34545-static int preallocate_pmds(pmd_t *pmds[])
34546+static int preallocate_pxds(pxd_t *pxds[])
34547 {
34548 int i;
34549 bool failed = false;
34550
34551- for(i = 0; i < PREALLOCATED_PMDS; i++) {
34552- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
34553- if (!pmd)
34554+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
34555+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
34556+ if (!pxd)
34557 failed = true;
34558- if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
34559- free_page((unsigned long)pmd);
34560- pmd = NULL;
34561+ if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
34562+ free_page((unsigned long)pxd);
34563+ pxd = NULL;
34564 failed = true;
34565 }
34566- pmds[i] = pmd;
34567+ pxds[i] = pxd;
34568 }
34569
34570 if (failed) {
34571- free_pmds(pmds);
34572+ free_pxds(pxds);
34573 return -ENOMEM;
34574 }
34575
34576@@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
34577 * preallocate which never got a corresponding vma will need to be
34578 * freed manually.
34579 */
34580-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
34581+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
34582 {
34583 int i;
34584
34585- for(i = 0; i < PREALLOCATED_PMDS; i++) {
34586+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
34587 pgd_t pgd = pgdp[i];
34588
34589 if (pgd_val(pgd) != 0) {
34590- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
34591+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
34592
34593- pgdp[i] = native_make_pgd(0);
34594+ set_pgd(pgdp + i, native_make_pgd(0));
34595
34596- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
34597- pmd_free(mm, pmd);
34598+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
34599+ pxd_free(mm, pxd);
34600 }
34601 }
34602 }
34603
34604-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
34605+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
34606 {
34607- pud_t *pud;
34608+ pyd_t *pyd;
34609 int i;
34610
34611- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
34612+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
34613 return;
34614
34615- pud = pud_offset(pgd, 0);
34616-
34617- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
34618- pmd_t *pmd = pmds[i];
34619+#ifdef CONFIG_X86_64
34620+ pyd = pyd_offset(mm, 0L);
34621+#else
34622+ pyd = pyd_offset(pgd, 0L);
34623+#endif
34624
34625+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
34626+ pxd_t *pxd = pxds[i];
34627 if (i >= KERNEL_PGD_BOUNDARY)
34628- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
34629- sizeof(pmd_t) * PTRS_PER_PMD);
34630+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
34631+ sizeof(pxd_t) * PTRS_PER_PMD);
34632
34633- pud_populate(mm, pud, pmd);
34634+ pyd_populate(mm, pyd, pxd);
34635 }
34636 }
34637
34638 pgd_t *pgd_alloc(struct mm_struct *mm)
34639 {
34640 pgd_t *pgd;
34641- pmd_t *pmds[PREALLOCATED_PMDS];
34642+ pxd_t *pxds[PREALLOCATED_PXDS];
34643
34644 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
34645
34646@@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34647
34648 mm->pgd = pgd;
34649
34650- if (preallocate_pmds(pmds) != 0)
34651+ if (preallocate_pxds(pxds) != 0)
34652 goto out_free_pgd;
34653
34654 if (paravirt_pgd_alloc(mm) != 0)
34655- goto out_free_pmds;
34656+ goto out_free_pxds;
34657
34658 /*
34659 * Make sure that pre-populating the pmds is atomic with
34660@@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34661 spin_lock(&pgd_lock);
34662
34663 pgd_ctor(mm, pgd);
34664- pgd_prepopulate_pmd(mm, pgd, pmds);
34665+ pgd_prepopulate_pxd(mm, pgd, pxds);
34666
34667 spin_unlock(&pgd_lock);
34668
34669 return pgd;
34670
34671-out_free_pmds:
34672- free_pmds(pmds);
34673+out_free_pxds:
34674+ free_pxds(pxds);
34675 out_free_pgd:
34676 free_page((unsigned long)pgd);
34677 out:
34678@@ -313,7 +380,7 @@ out:
34679
34680 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
34681 {
34682- pgd_mop_up_pmds(mm, pgd);
34683+ pgd_mop_up_pxds(mm, pgd);
34684 pgd_dtor(pgd);
34685 paravirt_pgd_free(mm, pgd);
34686 free_page((unsigned long)pgd);
34687diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
34688index 4dd8cf6..f9d143e 100644
34689--- a/arch/x86/mm/pgtable_32.c
34690+++ b/arch/x86/mm/pgtable_32.c
34691@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
34692 return;
34693 }
34694 pte = pte_offset_kernel(pmd, vaddr);
34695+
34696+ pax_open_kernel();
34697 if (pte_val(pteval))
34698 set_pte_at(&init_mm, vaddr, pte, pteval);
34699 else
34700 pte_clear(&init_mm, vaddr, pte);
34701+ pax_close_kernel();
34702
34703 /*
34704 * It's enough to flush this one mapping.
34705diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
34706index e666cbb..61788c45 100644
34707--- a/arch/x86/mm/physaddr.c
34708+++ b/arch/x86/mm/physaddr.c
34709@@ -10,7 +10,7 @@
34710 #ifdef CONFIG_X86_64
34711
34712 #ifdef CONFIG_DEBUG_VIRTUAL
34713-unsigned long __phys_addr(unsigned long x)
34714+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34715 {
34716 unsigned long y = x - __START_KERNEL_map;
34717
34718@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
34719 #else
34720
34721 #ifdef CONFIG_DEBUG_VIRTUAL
34722-unsigned long __phys_addr(unsigned long x)
34723+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34724 {
34725 unsigned long phys_addr = x - PAGE_OFFSET;
34726 /* VMALLOC_* aren't constants */
34727diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
34728index 90555bf..f5f1828 100644
34729--- a/arch/x86/mm/setup_nx.c
34730+++ b/arch/x86/mm/setup_nx.c
34731@@ -5,8 +5,10 @@
34732 #include <asm/pgtable.h>
34733 #include <asm/proto.h>
34734
34735+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34736 static int disable_nx;
34737
34738+#ifndef CONFIG_PAX_PAGEEXEC
34739 /*
34740 * noexec = on|off
34741 *
34742@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
34743 return 0;
34744 }
34745 early_param("noexec", noexec_setup);
34746+#endif
34747+
34748+#endif
34749
34750 void x86_configure_nx(void)
34751 {
34752+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34753 if (cpu_has_nx && !disable_nx)
34754 __supported_pte_mask |= _PAGE_NX;
34755 else
34756+#endif
34757 __supported_pte_mask &= ~_PAGE_NX;
34758 }
34759
34760diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
34761index ee61c36..e6fedeb 100644
34762--- a/arch/x86/mm/tlb.c
34763+++ b/arch/x86/mm/tlb.c
34764@@ -48,7 +48,11 @@ void leave_mm(int cpu)
34765 BUG();
34766 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
34767 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
34768+
34769+#ifndef CONFIG_PAX_PER_CPU_PGD
34770 load_cr3(swapper_pg_dir);
34771+#endif
34772+
34773 /*
34774 * This gets called in the idle path where RCU
34775 * functions differently. Tracing normally
34776diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
34777new file mode 100644
34778index 0000000..dace51c
34779--- /dev/null
34780+++ b/arch/x86/mm/uderef_64.c
34781@@ -0,0 +1,37 @@
34782+#include <linux/mm.h>
34783+#include <asm/pgtable.h>
34784+#include <asm/uaccess.h>
34785+
34786+#ifdef CONFIG_PAX_MEMORY_UDEREF
34787+/* PaX: due to the special call convention these functions must
34788+ * - remain leaf functions under all configurations,
34789+ * - never be called directly, only dereferenced from the wrappers.
34790+ */
34791+void __pax_open_userland(void)
34792+{
34793+ unsigned int cpu;
34794+
34795+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
34796+ return;
34797+
34798+ cpu = raw_get_cpu();
34799+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
34800+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
34801+ raw_put_cpu_no_resched();
34802+}
34803+EXPORT_SYMBOL(__pax_open_userland);
34804+
34805+void __pax_close_userland(void)
34806+{
34807+ unsigned int cpu;
34808+
34809+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
34810+ return;
34811+
34812+ cpu = raw_get_cpu();
34813+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
34814+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
34815+ raw_put_cpu_no_resched();
34816+}
34817+EXPORT_SYMBOL(__pax_close_userland);
34818+#endif
34819diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
34820index 6440221..f84b5c7 100644
34821--- a/arch/x86/net/bpf_jit.S
34822+++ b/arch/x86/net/bpf_jit.S
34823@@ -9,6 +9,7 @@
34824 */
34825 #include <linux/linkage.h>
34826 #include <asm/dwarf2.h>
34827+#include <asm/alternative-asm.h>
34828
34829 /*
34830 * Calling convention :
34831@@ -38,6 +39,7 @@ sk_load_word_positive_offset:
34832 jle bpf_slow_path_word
34833 mov (SKBDATA,%rsi),%eax
34834 bswap %eax /* ntohl() */
34835+ pax_force_retaddr
34836 ret
34837
34838 sk_load_half:
34839@@ -55,6 +57,7 @@ sk_load_half_positive_offset:
34840 jle bpf_slow_path_half
34841 movzwl (SKBDATA,%rsi),%eax
34842 rol $8,%ax # ntohs()
34843+ pax_force_retaddr
34844 ret
34845
34846 sk_load_byte:
34847@@ -69,6 +72,7 @@ sk_load_byte_positive_offset:
34848 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
34849 jle bpf_slow_path_byte
34850 movzbl (SKBDATA,%rsi),%eax
34851+ pax_force_retaddr
34852 ret
34853
34854 /* rsi contains offset and can be scratched */
34855@@ -90,6 +94,7 @@ bpf_slow_path_word:
34856 js bpf_error
34857 mov - MAX_BPF_STACK + 32(%rbp),%eax
34858 bswap %eax
34859+ pax_force_retaddr
34860 ret
34861
34862 bpf_slow_path_half:
34863@@ -98,12 +103,14 @@ bpf_slow_path_half:
34864 mov - MAX_BPF_STACK + 32(%rbp),%ax
34865 rol $8,%ax
34866 movzwl %ax,%eax
34867+ pax_force_retaddr
34868 ret
34869
34870 bpf_slow_path_byte:
34871 bpf_slow_path_common(1)
34872 js bpf_error
34873 movzbl - MAX_BPF_STACK + 32(%rbp),%eax
34874+ pax_force_retaddr
34875 ret
34876
34877 #define sk_negative_common(SIZE) \
34878@@ -126,6 +133,7 @@ sk_load_word_negative_offset:
34879 sk_negative_common(4)
34880 mov (%rax), %eax
34881 bswap %eax
34882+ pax_force_retaddr
34883 ret
34884
34885 bpf_slow_path_half_neg:
34886@@ -137,6 +145,7 @@ sk_load_half_negative_offset:
34887 mov (%rax),%ax
34888 rol $8,%ax
34889 movzwl %ax,%eax
34890+ pax_force_retaddr
34891 ret
34892
34893 bpf_slow_path_byte_neg:
34894@@ -146,6 +155,7 @@ sk_load_byte_negative_offset:
34895 .globl sk_load_byte_negative_offset
34896 sk_negative_common(1)
34897 movzbl (%rax), %eax
34898+ pax_force_retaddr
34899 ret
34900
34901 bpf_error:
34902@@ -156,4 +166,5 @@ bpf_error:
34903 mov - MAX_BPF_STACK + 16(%rbp),%r14
34904 mov - MAX_BPF_STACK + 24(%rbp),%r15
34905 leaveq
34906+ pax_force_retaddr
34907 ret
34908diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
34909index c881ba8..71aca2e 100644
34910--- a/arch/x86/net/bpf_jit_comp.c
34911+++ b/arch/x86/net/bpf_jit_comp.c
34912@@ -15,7 +15,11 @@
34913 #include <linux/if_vlan.h>
34914 #include <linux/random.h>
34915
34916+#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
34917+int bpf_jit_enable __read_only;
34918+#else
34919 int bpf_jit_enable __read_mostly;
34920+#endif
34921
34922 /*
34923 * assembly code in arch/x86/net/bpf_jit.S
34924@@ -109,36 +113,32 @@ static inline void bpf_flush_icache(void *start, void *end)
34925 #define CHOOSE_LOAD_FUNC(K, func) \
34926 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
34927
34928-struct bpf_binary_header {
34929- unsigned int pages;
34930- /* Note : for security reasons, bpf code will follow a randomly
34931- * sized amount of int3 instructions
34932- */
34933- u8 image[];
34934-};
34935-
34936-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
34937+/* Note : for security reasons, bpf code will follow a randomly
34938+ * sized amount of int3 instructions
34939+ */
34940+static u8 *bpf_alloc_binary(unsigned int proglen,
34941 u8 **image_ptr)
34942 {
34943 unsigned int sz, hole;
34944- struct bpf_binary_header *header;
34945+ u8 *header;
34946
34947 /* Most of BPF filters are really small,
34948 * but if some of them fill a page, allow at least
34949 * 128 extra bytes to insert a random section of int3
34950 */
34951- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
34952- header = module_alloc(sz);
34953+ sz = round_up(proglen + 128, PAGE_SIZE);
34954+ header = module_alloc_exec(sz);
34955 if (!header)
34956 return NULL;
34957
34958+ pax_open_kernel();
34959 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
34960+ pax_close_kernel();
34961
34962- header->pages = sz / PAGE_SIZE;
34963- hole = min(sz - (proglen + sizeof(*header)), PAGE_SIZE - sizeof(*header));
34964+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
34965
34966 /* insert a random number of int3 instructions before BPF code */
34967- *image_ptr = &header->image[prandom_u32() % hole];
34968+ *image_ptr = &header[prandom_u32() % hole];
34969 return header;
34970 }
34971
34972@@ -864,7 +864,9 @@ common_load:
34973 pr_err("bpf_jit_compile fatal error\n");
34974 return -EFAULT;
34975 }
34976+ pax_open_kernel();
34977 memcpy(image + proglen, temp, ilen);
34978+ pax_close_kernel();
34979 }
34980 proglen += ilen;
34981 addrs[i] = proglen;
34982@@ -879,7 +881,7 @@ void bpf_jit_compile(struct bpf_prog *prog)
34983
34984 void bpf_int_jit_compile(struct bpf_prog *prog)
34985 {
34986- struct bpf_binary_header *header = NULL;
34987+ u8 *header = NULL;
34988 int proglen, oldproglen = 0;
34989 struct jit_context ctx = {};
34990 u8 *image = NULL;
34991@@ -911,7 +913,7 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
34992 if (proglen <= 0) {
34993 image = NULL;
34994 if (header)
34995- module_free(NULL, header);
34996+ module_free_exec(NULL, image);
34997 goto out;
34998 }
34999 if (image) {
35000@@ -935,7 +937,6 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
35001
35002 if (image) {
35003 bpf_flush_icache(header, image + proglen);
35004- set_memory_ro((unsigned long)header, header->pages);
35005 prog->bpf_func = (void *)image;
35006 prog->jited = 1;
35007 }
35008@@ -943,23 +944,15 @@ out:
35009 kfree(addrs);
35010 }
35011
35012-static void bpf_jit_free_deferred(struct work_struct *work)
35013-{
35014- struct bpf_prog *fp = container_of(work, struct bpf_prog, work);
35015- unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
35016- struct bpf_binary_header *header = (void *)addr;
35017-
35018- set_memory_rw(addr, header->pages);
35019- module_free(NULL, header);
35020- kfree(fp);
35021-}
35022-
35023 void bpf_jit_free(struct bpf_prog *fp)
35024 {
35025- if (fp->jited) {
35026- INIT_WORK(&fp->work, bpf_jit_free_deferred);
35027- schedule_work(&fp->work);
35028- } else {
35029- kfree(fp);
35030- }
35031+ unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
35032+
35033+ if (!fp->jited)
35034+ goto free_filter;
35035+
35036+ module_free_exec(NULL, (void *)addr);
35037+
35038+free_filter:
35039+ bpf_prog_unlock_free(fp);
35040 }
35041diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
35042index 5d04be5..2beeaa2 100644
35043--- a/arch/x86/oprofile/backtrace.c
35044+++ b/arch/x86/oprofile/backtrace.c
35045@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
35046 struct stack_frame_ia32 *fp;
35047 unsigned long bytes;
35048
35049- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
35050+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
35051 if (bytes != 0)
35052 return NULL;
35053
35054- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
35055+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
35056
35057 oprofile_add_trace(bufhead[0].return_address);
35058
35059@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
35060 struct stack_frame bufhead[2];
35061 unsigned long bytes;
35062
35063- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
35064+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
35065 if (bytes != 0)
35066 return NULL;
35067
35068@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
35069 {
35070 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
35071
35072- if (!user_mode_vm(regs)) {
35073+ if (!user_mode(regs)) {
35074 unsigned long stack = kernel_stack_pointer(regs);
35075 if (depth)
35076 dump_trace(NULL, regs, (unsigned long *)stack, 0,
35077diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
35078index 379e8bd..6386e09 100644
35079--- a/arch/x86/oprofile/nmi_int.c
35080+++ b/arch/x86/oprofile/nmi_int.c
35081@@ -23,6 +23,7 @@
35082 #include <asm/nmi.h>
35083 #include <asm/msr.h>
35084 #include <asm/apic.h>
35085+#include <asm/pgtable.h>
35086
35087 #include "op_counter.h"
35088 #include "op_x86_model.h"
35089@@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
35090 if (ret)
35091 return ret;
35092
35093- if (!model->num_virt_counters)
35094- model->num_virt_counters = model->num_counters;
35095+ if (!model->num_virt_counters) {
35096+ pax_open_kernel();
35097+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
35098+ pax_close_kernel();
35099+ }
35100
35101 mux_init(ops);
35102
35103diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
35104index 50d86c0..7985318 100644
35105--- a/arch/x86/oprofile/op_model_amd.c
35106+++ b/arch/x86/oprofile/op_model_amd.c
35107@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
35108 num_counters = AMD64_NUM_COUNTERS;
35109 }
35110
35111- op_amd_spec.num_counters = num_counters;
35112- op_amd_spec.num_controls = num_counters;
35113- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
35114+ pax_open_kernel();
35115+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
35116+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
35117+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
35118+ pax_close_kernel();
35119
35120 return 0;
35121 }
35122diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
35123index d90528e..0127e2b 100644
35124--- a/arch/x86/oprofile/op_model_ppro.c
35125+++ b/arch/x86/oprofile/op_model_ppro.c
35126@@ -19,6 +19,7 @@
35127 #include <asm/msr.h>
35128 #include <asm/apic.h>
35129 #include <asm/nmi.h>
35130+#include <asm/pgtable.h>
35131
35132 #include "op_x86_model.h"
35133 #include "op_counter.h"
35134@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
35135
35136 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
35137
35138- op_arch_perfmon_spec.num_counters = num_counters;
35139- op_arch_perfmon_spec.num_controls = num_counters;
35140+ pax_open_kernel();
35141+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
35142+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
35143+ pax_close_kernel();
35144 }
35145
35146 static int arch_perfmon_init(struct oprofile_operations *ignore)
35147diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
35148index 71e8a67..6a313bb 100644
35149--- a/arch/x86/oprofile/op_x86_model.h
35150+++ b/arch/x86/oprofile/op_x86_model.h
35151@@ -52,7 +52,7 @@ struct op_x86_model_spec {
35152 void (*switch_ctrl)(struct op_x86_model_spec const *model,
35153 struct op_msrs const * const msrs);
35154 #endif
35155-};
35156+} __do_const;
35157
35158 struct op_counter_config;
35159
35160diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
35161index b9958c3..24229ab 100644
35162--- a/arch/x86/pci/intel_mid_pci.c
35163+++ b/arch/x86/pci/intel_mid_pci.c
35164@@ -250,7 +250,7 @@ int __init intel_mid_pci_init(void)
35165 pci_mmcfg_late_init();
35166 pcibios_enable_irq = intel_mid_pci_irq_enable;
35167 pcibios_disable_irq = intel_mid_pci_irq_disable;
35168- pci_root_ops = intel_mid_pci_ops;
35169+ memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
35170 pci_soc_mode = 1;
35171 /* Continue with standard init */
35172 return 1;
35173diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
35174index eb500c2..eab9e70 100644
35175--- a/arch/x86/pci/irq.c
35176+++ b/arch/x86/pci/irq.c
35177@@ -51,7 +51,7 @@ struct irq_router {
35178 struct irq_router_handler {
35179 u16 vendor;
35180 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
35181-};
35182+} __do_const;
35183
35184 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
35185 void (*pcibios_disable_irq)(struct pci_dev *dev) = pirq_disable_irq;
35186@@ -791,7 +791,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
35187 return 0;
35188 }
35189
35190-static __initdata struct irq_router_handler pirq_routers[] = {
35191+static __initconst const struct irq_router_handler pirq_routers[] = {
35192 { PCI_VENDOR_ID_INTEL, intel_router_probe },
35193 { PCI_VENDOR_ID_AL, ali_router_probe },
35194 { PCI_VENDOR_ID_ITE, ite_router_probe },
35195@@ -818,7 +818,7 @@ static struct pci_dev *pirq_router_dev;
35196 static void __init pirq_find_router(struct irq_router *r)
35197 {
35198 struct irq_routing_table *rt = pirq_table;
35199- struct irq_router_handler *h;
35200+ const struct irq_router_handler *h;
35201
35202 #ifdef CONFIG_PCI_BIOS
35203 if (!rt->signature) {
35204@@ -1091,7 +1091,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
35205 return 0;
35206 }
35207
35208-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
35209+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
35210 {
35211 .callback = fix_broken_hp_bios_irq9,
35212 .ident = "HP Pavilion N5400 Series Laptop",
35213diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
35214index c77b24a..c979855 100644
35215--- a/arch/x86/pci/pcbios.c
35216+++ b/arch/x86/pci/pcbios.c
35217@@ -79,7 +79,7 @@ union bios32 {
35218 static struct {
35219 unsigned long address;
35220 unsigned short segment;
35221-} bios32_indirect = { 0, __KERNEL_CS };
35222+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
35223
35224 /*
35225 * Returns the entry point for the given service, NULL on error
35226@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
35227 unsigned long length; /* %ecx */
35228 unsigned long entry; /* %edx */
35229 unsigned long flags;
35230+ struct desc_struct d, *gdt;
35231
35232 local_irq_save(flags);
35233- __asm__("lcall *(%%edi); cld"
35234+
35235+ gdt = get_cpu_gdt_table(smp_processor_id());
35236+
35237+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
35238+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
35239+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
35240+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
35241+
35242+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
35243 : "=a" (return_code),
35244 "=b" (address),
35245 "=c" (length),
35246 "=d" (entry)
35247 : "0" (service),
35248 "1" (0),
35249- "D" (&bios32_indirect));
35250+ "D" (&bios32_indirect),
35251+ "r"(__PCIBIOS_DS)
35252+ : "memory");
35253+
35254+ pax_open_kernel();
35255+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
35256+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
35257+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
35258+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
35259+ pax_close_kernel();
35260+
35261 local_irq_restore(flags);
35262
35263 switch (return_code) {
35264- case 0:
35265- return address + entry;
35266- case 0x80: /* Not present */
35267- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
35268- return 0;
35269- default: /* Shouldn't happen */
35270- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
35271- service, return_code);
35272+ case 0: {
35273+ int cpu;
35274+ unsigned char flags;
35275+
35276+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
35277+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
35278+ printk(KERN_WARNING "bios32_service: not valid\n");
35279 return 0;
35280+ }
35281+ address = address + PAGE_OFFSET;
35282+ length += 16UL; /* some BIOSs underreport this... */
35283+ flags = 4;
35284+ if (length >= 64*1024*1024) {
35285+ length >>= PAGE_SHIFT;
35286+ flags |= 8;
35287+ }
35288+
35289+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
35290+ gdt = get_cpu_gdt_table(cpu);
35291+ pack_descriptor(&d, address, length, 0x9b, flags);
35292+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
35293+ pack_descriptor(&d, address, length, 0x93, flags);
35294+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
35295+ }
35296+ return entry;
35297+ }
35298+ case 0x80: /* Not present */
35299+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
35300+ return 0;
35301+ default: /* Shouldn't happen */
35302+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
35303+ service, return_code);
35304+ return 0;
35305 }
35306 }
35307
35308 static struct {
35309 unsigned long address;
35310 unsigned short segment;
35311-} pci_indirect = { 0, __KERNEL_CS };
35312+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
35313
35314-static int pci_bios_present;
35315+static int pci_bios_present __read_only;
35316
35317 static int check_pcibios(void)
35318 {
35319@@ -131,11 +174,13 @@ static int check_pcibios(void)
35320 unsigned long flags, pcibios_entry;
35321
35322 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
35323- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
35324+ pci_indirect.address = pcibios_entry;
35325
35326 local_irq_save(flags);
35327- __asm__(
35328- "lcall *(%%edi); cld\n\t"
35329+ __asm__("movw %w6, %%ds\n\t"
35330+ "lcall *%%ss:(%%edi); cld\n\t"
35331+ "push %%ss\n\t"
35332+ "pop %%ds\n\t"
35333 "jc 1f\n\t"
35334 "xor %%ah, %%ah\n"
35335 "1:"
35336@@ -144,7 +189,8 @@ static int check_pcibios(void)
35337 "=b" (ebx),
35338 "=c" (ecx)
35339 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
35340- "D" (&pci_indirect)
35341+ "D" (&pci_indirect),
35342+ "r" (__PCIBIOS_DS)
35343 : "memory");
35344 local_irq_restore(flags);
35345
35346@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35347
35348 switch (len) {
35349 case 1:
35350- __asm__("lcall *(%%esi); cld\n\t"
35351+ __asm__("movw %w6, %%ds\n\t"
35352+ "lcall *%%ss:(%%esi); cld\n\t"
35353+ "push %%ss\n\t"
35354+ "pop %%ds\n\t"
35355 "jc 1f\n\t"
35356 "xor %%ah, %%ah\n"
35357 "1:"
35358@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35359 : "1" (PCIBIOS_READ_CONFIG_BYTE),
35360 "b" (bx),
35361 "D" ((long)reg),
35362- "S" (&pci_indirect));
35363+ "S" (&pci_indirect),
35364+ "r" (__PCIBIOS_DS));
35365 /*
35366 * Zero-extend the result beyond 8 bits, do not trust the
35367 * BIOS having done it:
35368@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35369 *value &= 0xff;
35370 break;
35371 case 2:
35372- __asm__("lcall *(%%esi); cld\n\t"
35373+ __asm__("movw %w6, %%ds\n\t"
35374+ "lcall *%%ss:(%%esi); cld\n\t"
35375+ "push %%ss\n\t"
35376+ "pop %%ds\n\t"
35377 "jc 1f\n\t"
35378 "xor %%ah, %%ah\n"
35379 "1:"
35380@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35381 : "1" (PCIBIOS_READ_CONFIG_WORD),
35382 "b" (bx),
35383 "D" ((long)reg),
35384- "S" (&pci_indirect));
35385+ "S" (&pci_indirect),
35386+ "r" (__PCIBIOS_DS));
35387 /*
35388 * Zero-extend the result beyond 16 bits, do not trust the
35389 * BIOS having done it:
35390@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35391 *value &= 0xffff;
35392 break;
35393 case 4:
35394- __asm__("lcall *(%%esi); cld\n\t"
35395+ __asm__("movw %w6, %%ds\n\t"
35396+ "lcall *%%ss:(%%esi); cld\n\t"
35397+ "push %%ss\n\t"
35398+ "pop %%ds\n\t"
35399 "jc 1f\n\t"
35400 "xor %%ah, %%ah\n"
35401 "1:"
35402@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35403 : "1" (PCIBIOS_READ_CONFIG_DWORD),
35404 "b" (bx),
35405 "D" ((long)reg),
35406- "S" (&pci_indirect));
35407+ "S" (&pci_indirect),
35408+ "r" (__PCIBIOS_DS));
35409 break;
35410 }
35411
35412@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35413
35414 switch (len) {
35415 case 1:
35416- __asm__("lcall *(%%esi); cld\n\t"
35417+ __asm__("movw %w6, %%ds\n\t"
35418+ "lcall *%%ss:(%%esi); cld\n\t"
35419+ "push %%ss\n\t"
35420+ "pop %%ds\n\t"
35421 "jc 1f\n\t"
35422 "xor %%ah, %%ah\n"
35423 "1:"
35424@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35425 "c" (value),
35426 "b" (bx),
35427 "D" ((long)reg),
35428- "S" (&pci_indirect));
35429+ "S" (&pci_indirect),
35430+ "r" (__PCIBIOS_DS));
35431 break;
35432 case 2:
35433- __asm__("lcall *(%%esi); cld\n\t"
35434+ __asm__("movw %w6, %%ds\n\t"
35435+ "lcall *%%ss:(%%esi); cld\n\t"
35436+ "push %%ss\n\t"
35437+ "pop %%ds\n\t"
35438 "jc 1f\n\t"
35439 "xor %%ah, %%ah\n"
35440 "1:"
35441@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35442 "c" (value),
35443 "b" (bx),
35444 "D" ((long)reg),
35445- "S" (&pci_indirect));
35446+ "S" (&pci_indirect),
35447+ "r" (__PCIBIOS_DS));
35448 break;
35449 case 4:
35450- __asm__("lcall *(%%esi); cld\n\t"
35451+ __asm__("movw %w6, %%ds\n\t"
35452+ "lcall *%%ss:(%%esi); cld\n\t"
35453+ "push %%ss\n\t"
35454+ "pop %%ds\n\t"
35455 "jc 1f\n\t"
35456 "xor %%ah, %%ah\n"
35457 "1:"
35458@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35459 "c" (value),
35460 "b" (bx),
35461 "D" ((long)reg),
35462- "S" (&pci_indirect));
35463+ "S" (&pci_indirect),
35464+ "r" (__PCIBIOS_DS));
35465 break;
35466 }
35467
35468@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
35469
35470 DBG("PCI: Fetching IRQ routing table... ");
35471 __asm__("push %%es\n\t"
35472+ "movw %w8, %%ds\n\t"
35473 "push %%ds\n\t"
35474 "pop %%es\n\t"
35475- "lcall *(%%esi); cld\n\t"
35476+ "lcall *%%ss:(%%esi); cld\n\t"
35477 "pop %%es\n\t"
35478+ "push %%ss\n\t"
35479+ "pop %%ds\n"
35480 "jc 1f\n\t"
35481 "xor %%ah, %%ah\n"
35482 "1:"
35483@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
35484 "1" (0),
35485 "D" ((long) &opt),
35486 "S" (&pci_indirect),
35487- "m" (opt)
35488+ "m" (opt),
35489+ "r" (__PCIBIOS_DS)
35490 : "memory");
35491 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
35492 if (ret & 0xff00)
35493@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
35494 {
35495 int ret;
35496
35497- __asm__("lcall *(%%esi); cld\n\t"
35498+ __asm__("movw %w5, %%ds\n\t"
35499+ "lcall *%%ss:(%%esi); cld\n\t"
35500+ "push %%ss\n\t"
35501+ "pop %%ds\n"
35502 "jc 1f\n\t"
35503 "xor %%ah, %%ah\n"
35504 "1:"
35505@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
35506 : "0" (PCIBIOS_SET_PCI_HW_INT),
35507 "b" ((dev->bus->number << 8) | dev->devfn),
35508 "c" ((irq << 8) | (pin + 10)),
35509- "S" (&pci_indirect));
35510+ "S" (&pci_indirect),
35511+ "r" (__PCIBIOS_DS));
35512 return !(ret & 0xff00);
35513 }
35514 EXPORT_SYMBOL(pcibios_set_irq_routing);
35515diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
35516index 9ee3491..872192f 100644
35517--- a/arch/x86/platform/efi/efi_32.c
35518+++ b/arch/x86/platform/efi/efi_32.c
35519@@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
35520 {
35521 struct desc_ptr gdt_descr;
35522
35523+#ifdef CONFIG_PAX_KERNEXEC
35524+ struct desc_struct d;
35525+#endif
35526+
35527 local_irq_save(efi_rt_eflags);
35528
35529 load_cr3(initial_page_table);
35530 __flush_tlb_all();
35531
35532+#ifdef CONFIG_PAX_KERNEXEC
35533+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
35534+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
35535+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
35536+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
35537+#endif
35538+
35539 gdt_descr.address = __pa(get_cpu_gdt_table(0));
35540 gdt_descr.size = GDT_SIZE - 1;
35541 load_gdt(&gdt_descr);
35542@@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
35543 {
35544 struct desc_ptr gdt_descr;
35545
35546+#ifdef CONFIG_PAX_KERNEXEC
35547+ struct desc_struct d;
35548+
35549+ memset(&d, 0, sizeof d);
35550+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
35551+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
35552+#endif
35553+
35554 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
35555 gdt_descr.size = GDT_SIZE - 1;
35556 load_gdt(&gdt_descr);
35557
35558+#ifdef CONFIG_PAX_PER_CPU_PGD
35559+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
35560+#else
35561 load_cr3(swapper_pg_dir);
35562+#endif
35563+
35564 __flush_tlb_all();
35565
35566 local_irq_restore(efi_rt_eflags);
35567diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
35568index 290d397..e09d270 100644
35569--- a/arch/x86/platform/efi/efi_64.c
35570+++ b/arch/x86/platform/efi/efi_64.c
35571@@ -99,6 +99,11 @@ void __init efi_call_phys_prelog(void)
35572 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
35573 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
35574 }
35575+
35576+#ifdef CONFIG_PAX_PER_CPU_PGD
35577+ load_cr3(swapper_pg_dir);
35578+#endif
35579+
35580 __flush_tlb_all();
35581 }
35582
35583@@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
35584 for (pgd = 0; pgd < n_pgds; pgd++)
35585 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
35586 kfree(save_pgd);
35587+
35588+#ifdef CONFIG_PAX_PER_CPU_PGD
35589+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
35590+#endif
35591+
35592 __flush_tlb_all();
35593 local_irq_restore(efi_flags);
35594 early_code_mapping_set_exec(0);
35595@@ -146,8 +156,23 @@ int efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
35596 unsigned npages;
35597 pgd_t *pgd;
35598
35599- if (efi_enabled(EFI_OLD_MEMMAP))
35600+ if (efi_enabled(EFI_OLD_MEMMAP)) {
35601+ /* PaX: We need to disable the NX bit in the PGD, otherwise we won't be
35602+ * able to execute the EFI services.
35603+ */
35604+ if (__supported_pte_mask & _PAGE_NX) {
35605+ unsigned long addr = (unsigned long) __va(0);
35606+ pgd_t pe = __pgd(pgd_val(*pgd_offset_k(addr)) & ~_PAGE_NX);
35607+
35608+ pr_alert("PAX: Disabling NX protection for low memory map. Try booting without \"efi=old_map\"\n");
35609+#ifdef CONFIG_PAX_PER_CPU_PGD
35610+ set_pgd(pgd_offset_cpu(0, kernel, addr), pe);
35611+#endif
35612+ set_pgd(pgd_offset_k(addr), pe);
35613+ }
35614+
35615 return 0;
35616+ }
35617
35618 efi_scratch.efi_pgt = (pgd_t *)(unsigned long)real_mode_header->trampoline_pgd;
35619 pgd = __va(efi_scratch.efi_pgt);
35620diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
35621index fbe66e6..eae5e38 100644
35622--- a/arch/x86/platform/efi/efi_stub_32.S
35623+++ b/arch/x86/platform/efi/efi_stub_32.S
35624@@ -6,7 +6,9 @@
35625 */
35626
35627 #include <linux/linkage.h>
35628+#include <linux/init.h>
35629 #include <asm/page_types.h>
35630+#include <asm/segment.h>
35631
35632 /*
35633 * efi_call_phys(void *, ...) is a function with variable parameters.
35634@@ -20,7 +22,7 @@
35635 * service functions will comply with gcc calling convention, too.
35636 */
35637
35638-.text
35639+__INIT
35640 ENTRY(efi_call_phys)
35641 /*
35642 * 0. The function can only be called in Linux kernel. So CS has been
35643@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
35644 * The mapping of lower virtual memory has been created in prelog and
35645 * epilog.
35646 */
35647- movl $1f, %edx
35648- subl $__PAGE_OFFSET, %edx
35649- jmp *%edx
35650+#ifdef CONFIG_PAX_KERNEXEC
35651+ movl $(__KERNEXEC_EFI_DS), %edx
35652+ mov %edx, %ds
35653+ mov %edx, %es
35654+ mov %edx, %ss
35655+ addl $2f,(1f)
35656+ ljmp *(1f)
35657+
35658+__INITDATA
35659+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
35660+.previous
35661+
35662+2:
35663+ subl $2b,(1b)
35664+#else
35665+ jmp 1f-__PAGE_OFFSET
35666 1:
35667+#endif
35668
35669 /*
35670 * 2. Now on the top of stack is the return
35671@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
35672 * parameter 2, ..., param n. To make things easy, we save the return
35673 * address of efi_call_phys in a global variable.
35674 */
35675- popl %edx
35676- movl %edx, saved_return_addr
35677- /* get the function pointer into ECX*/
35678- popl %ecx
35679- movl %ecx, efi_rt_function_ptr
35680- movl $2f, %edx
35681- subl $__PAGE_OFFSET, %edx
35682- pushl %edx
35683+ popl (saved_return_addr)
35684+ popl (efi_rt_function_ptr)
35685
35686 /*
35687 * 3. Clear PG bit in %CR0.
35688@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
35689 /*
35690 * 5. Call the physical function.
35691 */
35692- jmp *%ecx
35693+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
35694
35695-2:
35696 /*
35697 * 6. After EFI runtime service returns, control will return to
35698 * following instruction. We'd better readjust stack pointer first.
35699@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
35700 movl %cr0, %edx
35701 orl $0x80000000, %edx
35702 movl %edx, %cr0
35703- jmp 1f
35704-1:
35705+
35706 /*
35707 * 8. Now restore the virtual mode from flat mode by
35708 * adding EIP with PAGE_OFFSET.
35709 */
35710- movl $1f, %edx
35711- jmp *%edx
35712+#ifdef CONFIG_PAX_KERNEXEC
35713+ movl $(__KERNEL_DS), %edx
35714+ mov %edx, %ds
35715+ mov %edx, %es
35716+ mov %edx, %ss
35717+ ljmp $(__KERNEL_CS),$1f
35718+#else
35719+ jmp 1f+__PAGE_OFFSET
35720+#endif
35721 1:
35722
35723 /*
35724 * 9. Balance the stack. And because EAX contain the return value,
35725 * we'd better not clobber it.
35726 */
35727- leal efi_rt_function_ptr, %edx
35728- movl (%edx), %ecx
35729- pushl %ecx
35730+ pushl (efi_rt_function_ptr)
35731
35732 /*
35733- * 10. Push the saved return address onto the stack and return.
35734+ * 10. Return to the saved return address.
35735 */
35736- leal saved_return_addr, %edx
35737- movl (%edx), %ecx
35738- pushl %ecx
35739- ret
35740+ jmpl *(saved_return_addr)
35741 ENDPROC(efi_call_phys)
35742 .previous
35743
35744-.data
35745+__INITDATA
35746 saved_return_addr:
35747 .long 0
35748 efi_rt_function_ptr:
35749diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
35750index 5fcda72..cd4dc41 100644
35751--- a/arch/x86/platform/efi/efi_stub_64.S
35752+++ b/arch/x86/platform/efi/efi_stub_64.S
35753@@ -11,6 +11,7 @@
35754 #include <asm/msr.h>
35755 #include <asm/processor-flags.h>
35756 #include <asm/page_types.h>
35757+#include <asm/alternative-asm.h>
35758
35759 #define SAVE_XMM \
35760 mov %rsp, %rax; \
35761@@ -88,6 +89,7 @@ ENTRY(efi_call)
35762 RESTORE_PGT
35763 addq $48, %rsp
35764 RESTORE_XMM
35765+ pax_force_retaddr 0, 1
35766 ret
35767 ENDPROC(efi_call)
35768
35769@@ -245,8 +247,8 @@ efi_gdt64:
35770 .long 0 /* Filled out by user */
35771 .word 0
35772 .quad 0x0000000000000000 /* NULL descriptor */
35773- .quad 0x00af9a000000ffff /* __KERNEL_CS */
35774- .quad 0x00cf92000000ffff /* __KERNEL_DS */
35775+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
35776+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
35777 .quad 0x0080890000000000 /* TS descriptor */
35778 .quad 0x0000000000000000 /* TS continued */
35779 efi_gdt64_end:
35780diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
35781index 1bbedc4..eb795b5 100644
35782--- a/arch/x86/platform/intel-mid/intel-mid.c
35783+++ b/arch/x86/platform/intel-mid/intel-mid.c
35784@@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
35785 {
35786 };
35787
35788-static void intel_mid_reboot(void)
35789+static void __noreturn intel_mid_reboot(void)
35790 {
35791 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
35792+ BUG();
35793 }
35794
35795 static unsigned long __init intel_mid_calibrate_tsc(void)
35796diff --git a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35797index 46aa25c..59a68ed 100644
35798--- a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35799+++ b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35800@@ -10,10 +10,9 @@
35801 */
35802
35803
35804-/* __attribute__((weak)) makes these declarations overridable */
35805 /* For every CPU addition a new get_<cpuname>_ops interface needs
35806 * to be added.
35807 */
35808-extern void *get_penwell_ops(void) __attribute__((weak));
35809-extern void *get_cloverview_ops(void) __attribute__((weak));
35810-extern void *get_tangier_ops(void) __attribute__((weak));
35811+extern const void *get_penwell_ops(void);
35812+extern const void *get_cloverview_ops(void);
35813+extern const void *get_tangier_ops(void);
35814diff --git a/arch/x86/platform/intel-mid/mfld.c b/arch/x86/platform/intel-mid/mfld.c
35815index 23381d2..8ddc10e 100644
35816--- a/arch/x86/platform/intel-mid/mfld.c
35817+++ b/arch/x86/platform/intel-mid/mfld.c
35818@@ -64,12 +64,12 @@ static void __init penwell_arch_setup(void)
35819 pm_power_off = mfld_power_off;
35820 }
35821
35822-void *get_penwell_ops(void)
35823+const void *get_penwell_ops(void)
35824 {
35825 return &penwell_ops;
35826 }
35827
35828-void *get_cloverview_ops(void)
35829+const void *get_cloverview_ops(void)
35830 {
35831 return &penwell_ops;
35832 }
35833diff --git a/arch/x86/platform/intel-mid/mrfl.c b/arch/x86/platform/intel-mid/mrfl.c
35834index aaca917..66eadbc 100644
35835--- a/arch/x86/platform/intel-mid/mrfl.c
35836+++ b/arch/x86/platform/intel-mid/mrfl.c
35837@@ -97,7 +97,7 @@ static struct intel_mid_ops tangier_ops = {
35838 .arch_setup = tangier_arch_setup,
35839 };
35840
35841-void *get_tangier_ops(void)
35842+const void *get_tangier_ops(void)
35843 {
35844 return &tangier_ops;
35845 }
35846diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
35847index d6ee929..3637cb5 100644
35848--- a/arch/x86/platform/olpc/olpc_dt.c
35849+++ b/arch/x86/platform/olpc/olpc_dt.c
35850@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
35851 return res;
35852 }
35853
35854-static struct of_pdt_ops prom_olpc_ops __initdata = {
35855+static struct of_pdt_ops prom_olpc_ops __initconst = {
35856 .nextprop = olpc_dt_nextprop,
35857 .getproplen = olpc_dt_getproplen,
35858 .getproperty = olpc_dt_getproperty,
35859diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
35860index 6ec7910..ecdbb11 100644
35861--- a/arch/x86/power/cpu.c
35862+++ b/arch/x86/power/cpu.c
35863@@ -137,11 +137,8 @@ static void do_fpu_end(void)
35864 static void fix_processor_context(void)
35865 {
35866 int cpu = smp_processor_id();
35867- struct tss_struct *t = &per_cpu(init_tss, cpu);
35868-#ifdef CONFIG_X86_64
35869- struct desc_struct *desc = get_cpu_gdt_table(cpu);
35870- tss_desc tss;
35871-#endif
35872+ struct tss_struct *t = init_tss + cpu;
35873+
35874 set_tss_desc(cpu, t); /*
35875 * This just modifies memory; should not be
35876 * necessary. But... This is necessary, because
35877@@ -150,10 +147,6 @@ static void fix_processor_context(void)
35878 */
35879
35880 #ifdef CONFIG_X86_64
35881- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
35882- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
35883- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
35884-
35885 syscall_init(); /* This sets MSR_*STAR and related */
35886 #endif
35887 load_TR_desc(); /* This does ltr */
35888diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
35889index bad628a..a102610 100644
35890--- a/arch/x86/realmode/init.c
35891+++ b/arch/x86/realmode/init.c
35892@@ -68,7 +68,13 @@ void __init setup_real_mode(void)
35893 __va(real_mode_header->trampoline_header);
35894
35895 #ifdef CONFIG_X86_32
35896- trampoline_header->start = __pa_symbol(startup_32_smp);
35897+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
35898+
35899+#ifdef CONFIG_PAX_KERNEXEC
35900+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
35901+#endif
35902+
35903+ trampoline_header->boot_cs = __BOOT_CS;
35904 trampoline_header->gdt_limit = __BOOT_DS + 7;
35905 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
35906 #else
35907@@ -84,7 +90,7 @@ void __init setup_real_mode(void)
35908 *trampoline_cr4_features = read_cr4();
35909
35910 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
35911- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
35912+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
35913 trampoline_pgd[511] = init_level4_pgt[511].pgd;
35914 #endif
35915 }
35916diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
35917index 7c0d7be..d24dc88 100644
35918--- a/arch/x86/realmode/rm/Makefile
35919+++ b/arch/x86/realmode/rm/Makefile
35920@@ -67,5 +67,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
35921
35922 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
35923 -I$(srctree)/arch/x86/boot
35924+ifdef CONSTIFY_PLUGIN
35925+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
35926+endif
35927 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
35928 GCOV_PROFILE := n
35929diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
35930index a28221d..93c40f1 100644
35931--- a/arch/x86/realmode/rm/header.S
35932+++ b/arch/x86/realmode/rm/header.S
35933@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
35934 #endif
35935 /* APM/BIOS reboot */
35936 .long pa_machine_real_restart_asm
35937-#ifdef CONFIG_X86_64
35938+#ifdef CONFIG_X86_32
35939+ .long __KERNEL_CS
35940+#else
35941 .long __KERNEL32_CS
35942 #endif
35943 END(real_mode_header)
35944diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35945index 48ddd76..c26749f 100644
35946--- a/arch/x86/realmode/rm/trampoline_32.S
35947+++ b/arch/x86/realmode/rm/trampoline_32.S
35948@@ -24,6 +24,12 @@
35949 #include <asm/page_types.h>
35950 #include "realmode.h"
35951
35952+#ifdef CONFIG_PAX_KERNEXEC
35953+#define ta(X) (X)
35954+#else
35955+#define ta(X) (pa_ ## X)
35956+#endif
35957+
35958 .text
35959 .code16
35960
35961@@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35962
35963 cli # We should be safe anyway
35964
35965- movl tr_start, %eax # where we need to go
35966-
35967 movl $0xA5A5A5A5, trampoline_status
35968 # write marker for master knows we're running
35969
35970@@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35971 movw $1, %dx # protected mode (PE) bit
35972 lmsw %dx # into protected mode
35973
35974- ljmpl $__BOOT_CS, $pa_startup_32
35975+ ljmpl *(trampoline_header)
35976
35977 .section ".text32","ax"
35978 .code32
35979@@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35980 .balign 8
35981 GLOBAL(trampoline_header)
35982 tr_start: .space 4
35983- tr_gdt_pad: .space 2
35984+ tr_boot_cs: .space 2
35985 tr_gdt: .space 6
35986 END(trampoline_header)
35987
35988diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35989index dac7b20..72dbaca 100644
35990--- a/arch/x86/realmode/rm/trampoline_64.S
35991+++ b/arch/x86/realmode/rm/trampoline_64.S
35992@@ -93,6 +93,7 @@ ENTRY(startup_32)
35993 movl %edx, %gs
35994
35995 movl pa_tr_cr4, %eax
35996+ andl $~X86_CR4_PCIDE, %eax
35997 movl %eax, %cr4 # Enable PAE mode
35998
35999 # Setup trampoline 4 level pagetables
36000@@ -106,7 +107,7 @@ ENTRY(startup_32)
36001 wrmsr
36002
36003 # Enable paging and in turn activate Long Mode
36004- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
36005+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
36006 movl %eax, %cr0
36007
36008 /*
36009diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
36010index 9e7e147..25a4158 100644
36011--- a/arch/x86/realmode/rm/wakeup_asm.S
36012+++ b/arch/x86/realmode/rm/wakeup_asm.S
36013@@ -126,11 +126,10 @@ ENTRY(wakeup_start)
36014 lgdtl pmode_gdt
36015
36016 /* This really couldn't... */
36017- movl pmode_entry, %eax
36018 movl pmode_cr0, %ecx
36019 movl %ecx, %cr0
36020- ljmpl $__KERNEL_CS, $pa_startup_32
36021- /* -> jmp *%eax in trampoline_32.S */
36022+
36023+ ljmpl *pmode_entry
36024 #else
36025 jmp trampoline_start
36026 #endif
36027diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
36028index 604a37e..e49702a 100644
36029--- a/arch/x86/tools/Makefile
36030+++ b/arch/x86/tools/Makefile
36031@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
36032
36033 $(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
36034
36035-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
36036+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
36037 hostprogs-y += relocs
36038 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
36039 PHONY += relocs
36040diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
36041index bbb1d22..e505211 100644
36042--- a/arch/x86/tools/relocs.c
36043+++ b/arch/x86/tools/relocs.c
36044@@ -1,5 +1,7 @@
36045 /* This is included from relocs_32/64.c */
36046
36047+#include "../../../include/generated/autoconf.h"
36048+
36049 #define ElfW(type) _ElfW(ELF_BITS, type)
36050 #define _ElfW(bits, type) __ElfW(bits, type)
36051 #define __ElfW(bits, type) Elf##bits##_##type
36052@@ -11,6 +13,7 @@
36053 #define Elf_Sym ElfW(Sym)
36054
36055 static Elf_Ehdr ehdr;
36056+static Elf_Phdr *phdr;
36057
36058 struct relocs {
36059 uint32_t *offset;
36060@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
36061 }
36062 }
36063
36064+static void read_phdrs(FILE *fp)
36065+{
36066+ unsigned int i;
36067+
36068+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
36069+ if (!phdr) {
36070+ die("Unable to allocate %d program headers\n",
36071+ ehdr.e_phnum);
36072+ }
36073+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
36074+ die("Seek to %d failed: %s\n",
36075+ ehdr.e_phoff, strerror(errno));
36076+ }
36077+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
36078+ die("Cannot read ELF program headers: %s\n",
36079+ strerror(errno));
36080+ }
36081+ for(i = 0; i < ehdr.e_phnum; i++) {
36082+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
36083+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
36084+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
36085+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
36086+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
36087+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
36088+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
36089+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
36090+ }
36091+
36092+}
36093+
36094 static void read_shdrs(FILE *fp)
36095 {
36096- int i;
36097+ unsigned int i;
36098 Elf_Shdr shdr;
36099
36100 secs = calloc(ehdr.e_shnum, sizeof(struct section));
36101@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
36102
36103 static void read_strtabs(FILE *fp)
36104 {
36105- int i;
36106+ unsigned int i;
36107 for (i = 0; i < ehdr.e_shnum; i++) {
36108 struct section *sec = &secs[i];
36109 if (sec->shdr.sh_type != SHT_STRTAB) {
36110@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
36111
36112 static void read_symtabs(FILE *fp)
36113 {
36114- int i,j;
36115+ unsigned int i,j;
36116 for (i = 0; i < ehdr.e_shnum; i++) {
36117 struct section *sec = &secs[i];
36118 if (sec->shdr.sh_type != SHT_SYMTAB) {
36119@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
36120 }
36121
36122
36123-static void read_relocs(FILE *fp)
36124+static void read_relocs(FILE *fp, int use_real_mode)
36125 {
36126- int i,j;
36127+ unsigned int i,j;
36128+ uint32_t base;
36129+
36130 for (i = 0; i < ehdr.e_shnum; i++) {
36131 struct section *sec = &secs[i];
36132 if (sec->shdr.sh_type != SHT_REL_TYPE) {
36133@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
36134 die("Cannot read symbol table: %s\n",
36135 strerror(errno));
36136 }
36137+ base = 0;
36138+
36139+#ifdef CONFIG_X86_32
36140+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
36141+ if (phdr[j].p_type != PT_LOAD )
36142+ continue;
36143+ 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)
36144+ continue;
36145+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
36146+ break;
36147+ }
36148+#endif
36149+
36150 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
36151 Elf_Rel *rel = &sec->reltab[j];
36152- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
36153+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
36154 rel->r_info = elf_xword_to_cpu(rel->r_info);
36155 #if (SHT_REL_TYPE == SHT_RELA)
36156 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
36157@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
36158
36159 static void print_absolute_symbols(void)
36160 {
36161- int i;
36162+ unsigned int i;
36163 const char *format;
36164
36165 if (ELF_BITS == 64)
36166@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
36167 for (i = 0; i < ehdr.e_shnum; i++) {
36168 struct section *sec = &secs[i];
36169 char *sym_strtab;
36170- int j;
36171+ unsigned int j;
36172
36173 if (sec->shdr.sh_type != SHT_SYMTAB) {
36174 continue;
36175@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
36176
36177 static void print_absolute_relocs(void)
36178 {
36179- int i, printed = 0;
36180+ unsigned int i, printed = 0;
36181 const char *format;
36182
36183 if (ELF_BITS == 64)
36184@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
36185 struct section *sec_applies, *sec_symtab;
36186 char *sym_strtab;
36187 Elf_Sym *sh_symtab;
36188- int j;
36189+ unsigned int j;
36190 if (sec->shdr.sh_type != SHT_REL_TYPE) {
36191 continue;
36192 }
36193@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
36194 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
36195 Elf_Sym *sym, const char *symname))
36196 {
36197- int i;
36198+ unsigned int i;
36199 /* Walk through the relocations */
36200 for (i = 0; i < ehdr.e_shnum; i++) {
36201 char *sym_strtab;
36202 Elf_Sym *sh_symtab;
36203 struct section *sec_applies, *sec_symtab;
36204- int j;
36205+ unsigned int j;
36206 struct section *sec = &secs[i];
36207
36208 if (sec->shdr.sh_type != SHT_REL_TYPE) {
36209@@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
36210 {
36211 unsigned r_type = ELF32_R_TYPE(rel->r_info);
36212 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
36213+ char *sym_strtab = sec->link->link->strtab;
36214+
36215+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
36216+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
36217+ return 0;
36218+
36219+#ifdef CONFIG_PAX_KERNEXEC
36220+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
36221+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
36222+ return 0;
36223+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
36224+ return 0;
36225+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
36226+ return 0;
36227+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
36228+ return 0;
36229+#endif
36230
36231 switch (r_type) {
36232 case R_386_NONE:
36233@@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
36234
36235 static void emit_relocs(int as_text, int use_real_mode)
36236 {
36237- int i;
36238+ unsigned int i;
36239 int (*write_reloc)(uint32_t, FILE *) = write32;
36240 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
36241 const char *symname);
36242@@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
36243 {
36244 regex_init(use_real_mode);
36245 read_ehdr(fp);
36246+ read_phdrs(fp);
36247 read_shdrs(fp);
36248 read_strtabs(fp);
36249 read_symtabs(fp);
36250- read_relocs(fp);
36251+ read_relocs(fp, use_real_mode);
36252 if (ELF_BITS == 64)
36253 percpu_init();
36254 if (show_absolute_syms) {
36255diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
36256index f40281e..92728c9 100644
36257--- a/arch/x86/um/mem_32.c
36258+++ b/arch/x86/um/mem_32.c
36259@@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
36260 gate_vma.vm_start = FIXADDR_USER_START;
36261 gate_vma.vm_end = FIXADDR_USER_END;
36262 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
36263- gate_vma.vm_page_prot = __P101;
36264+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
36265
36266 return 0;
36267 }
36268diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
36269index 80ffa5b..a33bd15 100644
36270--- a/arch/x86/um/tls_32.c
36271+++ b/arch/x86/um/tls_32.c
36272@@ -260,7 +260,7 @@ out:
36273 if (unlikely(task == current &&
36274 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
36275 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
36276- "without flushed TLS.", current->pid);
36277+ "without flushed TLS.", task_pid_nr(current));
36278 }
36279
36280 return 0;
36281diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
36282index 5a4affe..9e2d522 100644
36283--- a/arch/x86/vdso/Makefile
36284+++ b/arch/x86/vdso/Makefile
36285@@ -174,7 +174,7 @@ quiet_cmd_vdso = VDSO $@
36286 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
36287 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
36288
36289-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
36290+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
36291 $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
36292 GCOV_PROFILE := n
36293
36294diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
36295index e904c27..b9eaa03 100644
36296--- a/arch/x86/vdso/vdso32-setup.c
36297+++ b/arch/x86/vdso/vdso32-setup.c
36298@@ -14,6 +14,7 @@
36299 #include <asm/cpufeature.h>
36300 #include <asm/processor.h>
36301 #include <asm/vdso.h>
36302+#include <asm/mman.h>
36303
36304 #ifdef CONFIG_COMPAT_VDSO
36305 #define VDSO_DEFAULT 0
36306diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
36307index 970463b..da82d3e 100644
36308--- a/arch/x86/vdso/vma.c
36309+++ b/arch/x86/vdso/vma.c
36310@@ -16,10 +16,9 @@
36311 #include <asm/vdso.h>
36312 #include <asm/page.h>
36313 #include <asm/hpet.h>
36314+#include <asm/mman.h>
36315
36316 #if defined(CONFIG_X86_64)
36317-unsigned int __read_mostly vdso64_enabled = 1;
36318-
36319 extern unsigned short vdso_sync_cpuid;
36320 #endif
36321
36322@@ -101,6 +100,11 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
36323 .pages = no_pages,
36324 };
36325
36326+#ifdef CONFIG_PAX_RANDMMAP
36327+ if (mm->pax_flags & MF_PAX_RANDMMAP)
36328+ calculate_addr = false;
36329+#endif
36330+
36331 if (calculate_addr) {
36332 addr = vdso_addr(current->mm->start_stack,
36333 image->size - image->sym_vvar_start);
36334@@ -111,14 +115,14 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
36335 down_write(&mm->mmap_sem);
36336
36337 addr = get_unmapped_area(NULL, addr,
36338- image->size - image->sym_vvar_start, 0, 0);
36339+ image->size - image->sym_vvar_start, 0, MAP_EXECUTABLE);
36340 if (IS_ERR_VALUE(addr)) {
36341 ret = addr;
36342 goto up_fail;
36343 }
36344
36345 text_start = addr - image->sym_vvar_start;
36346- current->mm->context.vdso = (void __user *)text_start;
36347+ mm->context.vdso = text_start;
36348
36349 /*
36350 * MAYWRITE to allow gdb to COW and set breakpoints
36351@@ -163,15 +167,12 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
36352 hpet_address >> PAGE_SHIFT,
36353 PAGE_SIZE,
36354 pgprot_noncached(PAGE_READONLY));
36355-
36356- if (ret)
36357- goto up_fail;
36358 }
36359 #endif
36360
36361 up_fail:
36362 if (ret)
36363- current->mm->context.vdso = NULL;
36364+ current->mm->context.vdso = 0;
36365
36366 up_write(&mm->mmap_sem);
36367 return ret;
36368@@ -191,8 +192,8 @@ static int load_vdso32(void)
36369
36370 if (selected_vdso32->sym_VDSO32_SYSENTER_RETURN)
36371 current_thread_info()->sysenter_return =
36372- current->mm->context.vdso +
36373- selected_vdso32->sym_VDSO32_SYSENTER_RETURN;
36374+ (void __force_user *)(current->mm->context.vdso +
36375+ selected_vdso32->sym_VDSO32_SYSENTER_RETURN);
36376
36377 return 0;
36378 }
36379@@ -201,9 +202,6 @@ static int load_vdso32(void)
36380 #ifdef CONFIG_X86_64
36381 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
36382 {
36383- if (!vdso64_enabled)
36384- return 0;
36385-
36386 return map_vdso(&vdso_image_64, true);
36387 }
36388
36389@@ -212,12 +210,8 @@ int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
36390 int uses_interp)
36391 {
36392 #ifdef CONFIG_X86_X32_ABI
36393- if (test_thread_flag(TIF_X32)) {
36394- if (!vdso64_enabled)
36395- return 0;
36396-
36397+ if (test_thread_flag(TIF_X32))
36398 return map_vdso(&vdso_image_x32, true);
36399- }
36400 #endif
36401
36402 return load_vdso32();
36403@@ -229,12 +223,3 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
36404 return load_vdso32();
36405 }
36406 #endif
36407-
36408-#ifdef CONFIG_X86_64
36409-static __init int vdso_setup(char *s)
36410-{
36411- vdso64_enabled = simple_strtoul(s, NULL, 0);
36412- return 0;
36413-}
36414-__setup("vdso=", vdso_setup);
36415-#endif
36416diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
36417index e88fda8..76ce7ce 100644
36418--- a/arch/x86/xen/Kconfig
36419+++ b/arch/x86/xen/Kconfig
36420@@ -9,6 +9,7 @@ config XEN
36421 select XEN_HAVE_PVMMU
36422 depends on X86_64 || (X86_32 && X86_PAE)
36423 depends on X86_TSC
36424+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
36425 help
36426 This is the Linux Xen port. Enabling this will allow the
36427 kernel to boot in a paravirtualized environment under the
36428diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
36429index c0cb11f..bed56ff 100644
36430--- a/arch/x86/xen/enlighten.c
36431+++ b/arch/x86/xen/enlighten.c
36432@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
36433
36434 struct shared_info xen_dummy_shared_info;
36435
36436-void *xen_initial_gdt;
36437-
36438 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
36439 __read_mostly int xen_have_vector_callback;
36440 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
36441@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
36442 {
36443 unsigned long va = dtr->address;
36444 unsigned int size = dtr->size + 1;
36445- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
36446- unsigned long frames[pages];
36447+ unsigned long frames[65536 / PAGE_SIZE];
36448 int f;
36449
36450 /*
36451@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
36452 {
36453 unsigned long va = dtr->address;
36454 unsigned int size = dtr->size + 1;
36455- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
36456- unsigned long frames[pages];
36457+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
36458 int f;
36459
36460 /*
36461@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
36462 * 8-byte entries, or 16 4k pages..
36463 */
36464
36465- BUG_ON(size > 65536);
36466+ BUG_ON(size > GDT_SIZE);
36467 BUG_ON(va & ~PAGE_MASK);
36468
36469 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
36470@@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
36471 return 0;
36472 }
36473
36474-static void set_xen_basic_apic_ops(void)
36475+static void __init set_xen_basic_apic_ops(void)
36476 {
36477 apic->read = xen_apic_read;
36478 apic->write = xen_apic_write;
36479@@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
36480 #endif
36481 };
36482
36483-static void xen_reboot(int reason)
36484+static __noreturn void xen_reboot(int reason)
36485 {
36486 struct sched_shutdown r = { .reason = reason };
36487
36488- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
36489- BUG();
36490+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
36491+ BUG();
36492 }
36493
36494-static void xen_restart(char *msg)
36495+static __noreturn void xen_restart(char *msg)
36496 {
36497 xen_reboot(SHUTDOWN_reboot);
36498 }
36499
36500-static void xen_emergency_restart(void)
36501+static __noreturn void xen_emergency_restart(void)
36502 {
36503 xen_reboot(SHUTDOWN_reboot);
36504 }
36505
36506-static void xen_machine_halt(void)
36507+static __noreturn void xen_machine_halt(void)
36508 {
36509 xen_reboot(SHUTDOWN_poweroff);
36510 }
36511
36512-static void xen_machine_power_off(void)
36513+static __noreturn void xen_machine_power_off(void)
36514 {
36515 if (pm_power_off)
36516 pm_power_off();
36517@@ -1568,7 +1564,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
36518 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
36519
36520 /* Work out if we support NX */
36521- x86_configure_nx();
36522+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
36523+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
36524+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
36525+ unsigned l, h;
36526+
36527+ __supported_pte_mask |= _PAGE_NX;
36528+ rdmsr(MSR_EFER, l, h);
36529+ l |= EFER_NX;
36530+ wrmsr(MSR_EFER, l, h);
36531+ }
36532+#endif
36533
36534 /* Get mfn list */
36535 xen_build_dynamic_phys_to_machine();
36536@@ -1596,13 +1602,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
36537
36538 machine_ops = xen_machine_ops;
36539
36540- /*
36541- * The only reliable way to retain the initial address of the
36542- * percpu gdt_page is to remember it here, so we can go and
36543- * mark it RW later, when the initial percpu area is freed.
36544- */
36545- xen_initial_gdt = &per_cpu(gdt_page, 0);
36546-
36547 xen_smp_init();
36548
36549 #ifdef CONFIG_ACPI_NUMA
36550diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
36551index 16fb009..02b7801 100644
36552--- a/arch/x86/xen/mmu.c
36553+++ b/arch/x86/xen/mmu.c
36554@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
36555 return val;
36556 }
36557
36558-static pteval_t pte_pfn_to_mfn(pteval_t val)
36559+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
36560 {
36561 if (val & _PAGE_PRESENT) {
36562 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
36563@@ -1904,7 +1904,11 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
36564 * L3_k[511] -> level2_fixmap_pgt */
36565 convert_pfn_mfn(level3_kernel_pgt);
36566
36567+ convert_pfn_mfn(level3_vmalloc_start_pgt);
36568+ convert_pfn_mfn(level3_vmalloc_end_pgt);
36569+ convert_pfn_mfn(level3_vmemmap_pgt);
36570 /* L3_k[511][506] -> level1_fixmap_pgt */
36571+ /* L3_k[511][507] -> level1_vsyscall_pgt */
36572 convert_pfn_mfn(level2_fixmap_pgt);
36573 }
36574 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
36575@@ -1929,11 +1933,16 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
36576 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
36577 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
36578 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
36579+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
36580+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
36581+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
36582 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
36583 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
36584+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
36585 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
36586 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
36587 set_page_prot(level1_fixmap_pgt, PAGE_KERNEL_RO);
36588+ set_page_prot(level1_vsyscall_pgt, PAGE_KERNEL_RO);
36589
36590 /* Pin down new L4 */
36591 pin_pagetable_pfn(MMUEXT_PIN_L4_TABLE,
36592@@ -2117,6 +2126,7 @@ static void __init xen_post_allocator_init(void)
36593 pv_mmu_ops.set_pud = xen_set_pud;
36594 #if PAGETABLE_LEVELS == 4
36595 pv_mmu_ops.set_pgd = xen_set_pgd;
36596+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
36597 #endif
36598
36599 /* This will work as long as patching hasn't happened yet
36600@@ -2195,6 +2205,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
36601 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
36602 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
36603 .set_pgd = xen_set_pgd_hyper,
36604+ .set_pgd_batched = xen_set_pgd_hyper,
36605
36606 .alloc_pud = xen_alloc_pmd_init,
36607 .release_pud = xen_release_pmd_init,
36608diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
36609index 7005974..54fb05f 100644
36610--- a/arch/x86/xen/smp.c
36611+++ b/arch/x86/xen/smp.c
36612@@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
36613
36614 if (xen_pv_domain()) {
36615 if (!xen_feature(XENFEAT_writable_page_tables))
36616- /* We've switched to the "real" per-cpu gdt, so make
36617- * sure the old memory can be recycled. */
36618- make_lowmem_page_readwrite(xen_initial_gdt);
36619-
36620 #ifdef CONFIG_X86_32
36621 /*
36622 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
36623 * expects __USER_DS
36624 */
36625- loadsegment(ds, __USER_DS);
36626- loadsegment(es, __USER_DS);
36627+ loadsegment(ds, __KERNEL_DS);
36628+ loadsegment(es, __KERNEL_DS);
36629 #endif
36630
36631 xen_filter_cpu_maps();
36632@@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
36633 #ifdef CONFIG_X86_32
36634 /* Note: PVH is not yet supported on x86_32. */
36635 ctxt->user_regs.fs = __KERNEL_PERCPU;
36636- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
36637+ savesegment(gs, ctxt->user_regs.gs);
36638 #endif
36639 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
36640
36641@@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
36642 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
36643 ctxt->flags = VGCF_IN_KERNEL;
36644 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
36645- ctxt->user_regs.ds = __USER_DS;
36646- ctxt->user_regs.es = __USER_DS;
36647+ ctxt->user_regs.ds = __KERNEL_DS;
36648+ ctxt->user_regs.es = __KERNEL_DS;
36649 ctxt->user_regs.ss = __KERNEL_DS;
36650
36651 xen_copy_trap_info(ctxt->trap_ctxt);
36652@@ -437,14 +433,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
36653 int rc;
36654
36655 per_cpu(current_task, cpu) = idle;
36656+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
36657 #ifdef CONFIG_X86_32
36658 irq_ctx_init(cpu);
36659 #else
36660 clear_tsk_thread_flag(idle, TIF_FORK);
36661 #endif
36662- per_cpu(kernel_stack, cpu) =
36663- (unsigned long)task_stack_page(idle) -
36664- KERNEL_STACK_OFFSET + THREAD_SIZE;
36665+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
36666
36667 xen_setup_runstate_info(cpu);
36668 xen_setup_timer(cpu);
36669@@ -720,7 +715,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
36670
36671 void __init xen_smp_init(void)
36672 {
36673- smp_ops = xen_smp_ops;
36674+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
36675 xen_fill_possible_map();
36676 }
36677
36678diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
36679index fd92a64..1f72641 100644
36680--- a/arch/x86/xen/xen-asm_32.S
36681+++ b/arch/x86/xen/xen-asm_32.S
36682@@ -99,7 +99,7 @@ ENTRY(xen_iret)
36683 pushw %fs
36684 movl $(__KERNEL_PERCPU), %eax
36685 movl %eax, %fs
36686- movl %fs:xen_vcpu, %eax
36687+ mov PER_CPU_VAR(xen_vcpu), %eax
36688 POP_FS
36689 #else
36690 movl %ss:xen_vcpu, %eax
36691diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
36692index 485b695..fda3e7c 100644
36693--- a/arch/x86/xen/xen-head.S
36694+++ b/arch/x86/xen/xen-head.S
36695@@ -39,6 +39,17 @@ ENTRY(startup_xen)
36696 #ifdef CONFIG_X86_32
36697 mov %esi,xen_start_info
36698 mov $init_thread_union+THREAD_SIZE,%esp
36699+#ifdef CONFIG_SMP
36700+ movl $cpu_gdt_table,%edi
36701+ movl $__per_cpu_load,%eax
36702+ movw %ax,__KERNEL_PERCPU + 2(%edi)
36703+ rorl $16,%eax
36704+ movb %al,__KERNEL_PERCPU + 4(%edi)
36705+ movb %ah,__KERNEL_PERCPU + 7(%edi)
36706+ movl $__per_cpu_end - 1,%eax
36707+ subl $__per_cpu_start,%eax
36708+ movw %ax,__KERNEL_PERCPU + 0(%edi)
36709+#endif
36710 #else
36711 mov %rsi,xen_start_info
36712 mov $init_thread_union+THREAD_SIZE,%rsp
36713diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
36714index 28c7e0b..2acfec7 100644
36715--- a/arch/x86/xen/xen-ops.h
36716+++ b/arch/x86/xen/xen-ops.h
36717@@ -10,8 +10,6 @@
36718 extern const char xen_hypervisor_callback[];
36719 extern const char xen_failsafe_callback[];
36720
36721-extern void *xen_initial_gdt;
36722-
36723 struct trap_info;
36724 void xen_copy_trap_info(struct trap_info *traps);
36725
36726diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
36727index 525bd3d..ef888b1 100644
36728--- a/arch/xtensa/variants/dc232b/include/variant/core.h
36729+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
36730@@ -119,9 +119,9 @@
36731 ----------------------------------------------------------------------*/
36732
36733 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
36734-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
36735 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
36736 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
36737+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36738
36739 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
36740 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
36741diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
36742index 2f33760..835e50a 100644
36743--- a/arch/xtensa/variants/fsf/include/variant/core.h
36744+++ b/arch/xtensa/variants/fsf/include/variant/core.h
36745@@ -11,6 +11,7 @@
36746 #ifndef _XTENSA_CORE_H
36747 #define _XTENSA_CORE_H
36748
36749+#include <linux/const.h>
36750
36751 /****************************************************************************
36752 Parameters Useful for Any Code, USER or PRIVILEGED
36753@@ -112,9 +113,9 @@
36754 ----------------------------------------------------------------------*/
36755
36756 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36757-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36758 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36759 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36760+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36761
36762 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
36763 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
36764diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
36765index af00795..2bb8105 100644
36766--- a/arch/xtensa/variants/s6000/include/variant/core.h
36767+++ b/arch/xtensa/variants/s6000/include/variant/core.h
36768@@ -11,6 +11,7 @@
36769 #ifndef _XTENSA_CORE_CONFIGURATION_H
36770 #define _XTENSA_CORE_CONFIGURATION_H
36771
36772+#include <linux/const.h>
36773
36774 /****************************************************************************
36775 Parameters Useful for Any Code, USER or PRIVILEGED
36776@@ -118,9 +119,9 @@
36777 ----------------------------------------------------------------------*/
36778
36779 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36780-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36781 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36782 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36783+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36784
36785 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
36786 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
36787diff --git a/block/bio.c b/block/bio.c
36788index 3e6331d..f970433 100644
36789--- a/block/bio.c
36790+++ b/block/bio.c
36791@@ -1160,7 +1160,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
36792 /*
36793 * Overflow, abort
36794 */
36795- if (end < start)
36796+ if (end < start || end - start > INT_MAX - nr_pages)
36797 return ERR_PTR(-EINVAL);
36798
36799 nr_pages += end - start;
36800@@ -1294,7 +1294,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
36801 /*
36802 * Overflow, abort
36803 */
36804- if (end < start)
36805+ if (end < start || end - start > INT_MAX - nr_pages)
36806 return ERR_PTR(-EINVAL);
36807
36808 nr_pages += end - start;
36809@@ -1556,7 +1556,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
36810 const int read = bio_data_dir(bio) == READ;
36811 struct bio_map_data *bmd = bio->bi_private;
36812 int i;
36813- char *p = bmd->sgvecs[0].iov_base;
36814+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
36815
36816 bio_for_each_segment_all(bvec, bio, i) {
36817 char *addr = page_address(bvec->bv_page);
36818diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
36819index e17da94..e01cce1 100644
36820--- a/block/blk-cgroup.c
36821+++ b/block/blk-cgroup.c
36822@@ -822,7 +822,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
36823 static struct cgroup_subsys_state *
36824 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
36825 {
36826- static atomic64_t id_seq = ATOMIC64_INIT(0);
36827+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
36828 struct blkcg *blkcg;
36829
36830 if (!parent_css) {
36831@@ -836,7 +836,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
36832
36833 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
36834 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
36835- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
36836+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
36837 done:
36838 spin_lock_init(&blkcg->lock);
36839 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
36840diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
36841index 0736729..2ec3b48 100644
36842--- a/block/blk-iopoll.c
36843+++ b/block/blk-iopoll.c
36844@@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iop)
36845 }
36846 EXPORT_SYMBOL(blk_iopoll_complete);
36847
36848-static void blk_iopoll_softirq(struct softirq_action *h)
36849+static __latent_entropy void blk_iopoll_softirq(void)
36850 {
36851 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
36852 int rearm = 0, budget = blk_iopoll_budget;
36853diff --git a/block/blk-map.c b/block/blk-map.c
36854index f890d43..97b0482 100644
36855--- a/block/blk-map.c
36856+++ b/block/blk-map.c
36857@@ -300,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
36858 if (!len || !kbuf)
36859 return -EINVAL;
36860
36861- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
36862+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
36863 if (do_copy)
36864 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
36865 else
36866diff --git a/block/blk-softirq.c b/block/blk-softirq.c
36867index 53b1737..08177d2e 100644
36868--- a/block/blk-softirq.c
36869+++ b/block/blk-softirq.c
36870@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
36871 * Softirq action handler - move entries to local list and loop over them
36872 * while passing them to the queue registered handler.
36873 */
36874-static void blk_done_softirq(struct softirq_action *h)
36875+static __latent_entropy void blk_done_softirq(void)
36876 {
36877 struct list_head *cpu_list, local_list;
36878
36879diff --git a/block/bsg.c b/block/bsg.c
36880index ff46add..c4ba8ee 100644
36881--- a/block/bsg.c
36882+++ b/block/bsg.c
36883@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
36884 struct sg_io_v4 *hdr, struct bsg_device *bd,
36885 fmode_t has_write_perm)
36886 {
36887+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36888+ unsigned char *cmdptr;
36889+
36890 if (hdr->request_len > BLK_MAX_CDB) {
36891 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
36892 if (!rq->cmd)
36893 return -ENOMEM;
36894- }
36895+ cmdptr = rq->cmd;
36896+ } else
36897+ cmdptr = tmpcmd;
36898
36899- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
36900+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
36901 hdr->request_len))
36902 return -EFAULT;
36903
36904+ if (cmdptr != rq->cmd)
36905+ memcpy(rq->cmd, cmdptr, hdr->request_len);
36906+
36907 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
36908 if (blk_verify_command(rq->cmd, has_write_perm))
36909 return -EPERM;
36910diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
36911index 18b282c..050dbe5 100644
36912--- a/block/compat_ioctl.c
36913+++ b/block/compat_ioctl.c
36914@@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
36915 cgc = compat_alloc_user_space(sizeof(*cgc));
36916 cgc32 = compat_ptr(arg);
36917
36918- if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
36919+ if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
36920 get_user(data, &cgc32->buffer) ||
36921 put_user(compat_ptr(data), &cgc->buffer) ||
36922 copy_in_user(&cgc->buflen, &cgc32->buflen,
36923@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
36924 err |= __get_user(f->spec1, &uf->spec1);
36925 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
36926 err |= __get_user(name, &uf->name);
36927- f->name = compat_ptr(name);
36928+ f->name = (void __force_kernel *)compat_ptr(name);
36929 if (err) {
36930 err = -EFAULT;
36931 goto out;
36932diff --git a/block/genhd.c b/block/genhd.c
36933index e6723bd..703e4ac 100644
36934--- a/block/genhd.c
36935+++ b/block/genhd.c
36936@@ -469,21 +469,24 @@ static char *bdevt_str(dev_t devt, char *buf)
36937
36938 /*
36939 * Register device numbers dev..(dev+range-1)
36940- * range must be nonzero
36941+ * Noop if @range is zero.
36942 * The hash chain is sorted on range, so that subranges can override.
36943 */
36944 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
36945 struct kobject *(*probe)(dev_t, int *, void *),
36946 int (*lock)(dev_t, void *), void *data)
36947 {
36948- kobj_map(bdev_map, devt, range, module, probe, lock, data);
36949+ if (range)
36950+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
36951 }
36952
36953 EXPORT_SYMBOL(blk_register_region);
36954
36955+/* undo blk_register_region(), noop if @range is zero */
36956 void blk_unregister_region(dev_t devt, unsigned long range)
36957 {
36958- kobj_unmap(bdev_map, devt, range);
36959+ if (range)
36960+ kobj_unmap(bdev_map, devt, range);
36961 }
36962
36963 EXPORT_SYMBOL(blk_unregister_region);
36964diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36965index 56d08fd..2e07090 100644
36966--- a/block/partitions/efi.c
36967+++ b/block/partitions/efi.c
36968@@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36969 if (!gpt)
36970 return NULL;
36971
36972+ if (!le32_to_cpu(gpt->num_partition_entries))
36973+ return NULL;
36974+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36975+ if (!pte)
36976+ return NULL;
36977+
36978 count = le32_to_cpu(gpt->num_partition_entries) *
36979 le32_to_cpu(gpt->sizeof_partition_entry);
36980- if (!count)
36981- return NULL;
36982- pte = kmalloc(count, GFP_KERNEL);
36983- if (!pte)
36984- return NULL;
36985-
36986 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36987 (u8 *) pte, count) < count) {
36988 kfree(pte);
36989diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36990index a6d6270..c4bb72f 100644
36991--- a/block/scsi_ioctl.c
36992+++ b/block/scsi_ioctl.c
36993@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36994 return put_user(0, p);
36995 }
36996
36997-static int sg_get_timeout(struct request_queue *q)
36998+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36999 {
37000 return jiffies_to_clock_t(q->sg_timeout);
37001 }
37002@@ -227,8 +227,20 @@ EXPORT_SYMBOL(blk_verify_command);
37003 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
37004 struct sg_io_hdr *hdr, fmode_t mode)
37005 {
37006- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
37007+ unsigned char tmpcmd[sizeof(rq->__cmd)];
37008+ unsigned char *cmdptr;
37009+
37010+ if (rq->cmd != rq->__cmd)
37011+ cmdptr = rq->cmd;
37012+ else
37013+ cmdptr = tmpcmd;
37014+
37015+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
37016 return -EFAULT;
37017+
37018+ if (cmdptr != rq->cmd)
37019+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
37020+
37021 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
37022 return -EPERM;
37023
37024@@ -432,6 +444,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
37025 int err;
37026 unsigned int in_len, out_len, bytes, opcode, cmdlen;
37027 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
37028+ unsigned char tmpcmd[sizeof(rq->__cmd)];
37029+ unsigned char *cmdptr;
37030
37031 if (!sic)
37032 return -EINVAL;
37033@@ -470,9 +484,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
37034 */
37035 err = -EFAULT;
37036 rq->cmd_len = cmdlen;
37037- if (copy_from_user(rq->cmd, sic->data, cmdlen))
37038+
37039+ if (rq->cmd != rq->__cmd)
37040+ cmdptr = rq->cmd;
37041+ else
37042+ cmdptr = tmpcmd;
37043+
37044+ if (copy_from_user(cmdptr, sic->data, cmdlen))
37045 goto error;
37046
37047+ if (rq->cmd != cmdptr)
37048+ memcpy(rq->cmd, cmdptr, cmdlen);
37049+
37050 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
37051 goto error;
37052
37053diff --git a/crypto/cryptd.c b/crypto/cryptd.c
37054index e592c90..c566114 100644
37055--- a/crypto/cryptd.c
37056+++ b/crypto/cryptd.c
37057@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
37058
37059 struct cryptd_blkcipher_request_ctx {
37060 crypto_completion_t complete;
37061-};
37062+} __no_const;
37063
37064 struct cryptd_hash_ctx {
37065 struct crypto_shash *child;
37066@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
37067
37068 struct cryptd_aead_request_ctx {
37069 crypto_completion_t complete;
37070-};
37071+} __no_const;
37072
37073 static void cryptd_queue_worker(struct work_struct *work);
37074
37075diff --git a/crypto/cts.c b/crypto/cts.c
37076index 042223f..133f087 100644
37077--- a/crypto/cts.c
37078+++ b/crypto/cts.c
37079@@ -202,7 +202,8 @@ static int cts_cbc_decrypt(struct crypto_cts_ctx *ctx,
37080 /* 5. Append the tail (BB - Ln) bytes of Xn (tmp) to Cn to create En */
37081 memcpy(s + bsize + lastn, tmp + lastn, bsize - lastn);
37082 /* 6. Decrypt En to create Pn-1 */
37083- memset(iv, 0, sizeof(iv));
37084+ memzero_explicit(iv, sizeof(iv));
37085+
37086 sg_set_buf(&sgsrc[0], s + bsize, bsize);
37087 sg_set_buf(&sgdst[0], d, bsize);
37088 err = crypto_blkcipher_decrypt_iv(&lcldesc, sgdst, sgsrc, bsize);
37089diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
37090index 309d345..1632720 100644
37091--- a/crypto/pcrypt.c
37092+++ b/crypto/pcrypt.c
37093@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
37094 int ret;
37095
37096 pinst->kobj.kset = pcrypt_kset;
37097- ret = kobject_add(&pinst->kobj, NULL, name);
37098+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
37099 if (!ret)
37100 kobject_uevent(&pinst->kobj, KOBJ_ADD);
37101
37102diff --git a/crypto/sha1_generic.c b/crypto/sha1_generic.c
37103index 4279480..7bb0474 100644
37104--- a/crypto/sha1_generic.c
37105+++ b/crypto/sha1_generic.c
37106@@ -64,7 +64,7 @@ int crypto_sha1_update(struct shash_desc *desc, const u8 *data,
37107 src = data + done;
37108 } while (done + SHA1_BLOCK_SIZE <= len);
37109
37110- memset(temp, 0, sizeof(temp));
37111+ memzero_explicit(temp, sizeof(temp));
37112 partial = 0;
37113 }
37114 memcpy(sctx->buffer + partial, src, len - done);
37115diff --git a/crypto/sha256_generic.c b/crypto/sha256_generic.c
37116index 5433667..32c5e5e 100644
37117--- a/crypto/sha256_generic.c
37118+++ b/crypto/sha256_generic.c
37119@@ -210,10 +210,9 @@ static void sha256_transform(u32 *state, const u8 *input)
37120
37121 /* clear any sensitive info... */
37122 a = b = c = d = e = f = g = h = t1 = t2 = 0;
37123- memset(W, 0, 64 * sizeof(u32));
37124+ memzero_explicit(W, 64 * sizeof(u32));
37125 }
37126
37127-
37128 static int sha224_init(struct shash_desc *desc)
37129 {
37130 struct sha256_state *sctx = shash_desc_ctx(desc);
37131@@ -316,7 +315,7 @@ static int sha224_final(struct shash_desc *desc, u8 *hash)
37132 sha256_final(desc, D);
37133
37134 memcpy(hash, D, SHA224_DIGEST_SIZE);
37135- memset(D, 0, SHA256_DIGEST_SIZE);
37136+ memzero_explicit(D, SHA256_DIGEST_SIZE);
37137
37138 return 0;
37139 }
37140diff --git a/crypto/sha512_generic.c b/crypto/sha512_generic.c
37141index 6ed124f..04d295a 100644
37142--- a/crypto/sha512_generic.c
37143+++ b/crypto/sha512_generic.c
37144@@ -238,7 +238,7 @@ static int sha384_final(struct shash_desc *desc, u8 *hash)
37145 sha512_final(desc, D);
37146
37147 memcpy(hash, D, 48);
37148- memset(D, 0, 64);
37149+ memzero_explicit(D, 64);
37150
37151 return 0;
37152 }
37153diff --git a/crypto/tgr192.c b/crypto/tgr192.c
37154index 8740355..3c7af0d 100644
37155--- a/crypto/tgr192.c
37156+++ b/crypto/tgr192.c
37157@@ -612,7 +612,7 @@ static int tgr160_final(struct shash_desc *desc, u8 * out)
37158
37159 tgr192_final(desc, D);
37160 memcpy(out, D, TGR160_DIGEST_SIZE);
37161- memset(D, 0, TGR192_DIGEST_SIZE);
37162+ memzero_explicit(D, TGR192_DIGEST_SIZE);
37163
37164 return 0;
37165 }
37166@@ -623,7 +623,7 @@ static int tgr128_final(struct shash_desc *desc, u8 * out)
37167
37168 tgr192_final(desc, D);
37169 memcpy(out, D, TGR128_DIGEST_SIZE);
37170- memset(D, 0, TGR192_DIGEST_SIZE);
37171+ memzero_explicit(D, TGR192_DIGEST_SIZE);
37172
37173 return 0;
37174 }
37175diff --git a/crypto/vmac.c b/crypto/vmac.c
37176index 2eb11a3..d84c24b 100644
37177--- a/crypto/vmac.c
37178+++ b/crypto/vmac.c
37179@@ -613,7 +613,7 @@ static int vmac_final(struct shash_desc *pdesc, u8 *out)
37180 }
37181 mac = vmac(ctx->partial, ctx->partial_size, nonce, NULL, ctx);
37182 memcpy(out, &mac, sizeof(vmac_t));
37183- memset(&mac, 0, sizeof(vmac_t));
37184+ memzero_explicit(&mac, sizeof(vmac_t));
37185 memset(&ctx->__vmac_ctx, 0, sizeof(struct vmac_ctx));
37186 ctx->partial_size = 0;
37187 return 0;
37188diff --git a/crypto/wp512.c b/crypto/wp512.c
37189index 180f1d6..ec64e77 100644
37190--- a/crypto/wp512.c
37191+++ b/crypto/wp512.c
37192@@ -1102,8 +1102,8 @@ static int wp384_final(struct shash_desc *desc, u8 *out)
37193 u8 D[64];
37194
37195 wp512_final(desc, D);
37196- memcpy (out, D, WP384_DIGEST_SIZE);
37197- memset (D, 0, WP512_DIGEST_SIZE);
37198+ memcpy(out, D, WP384_DIGEST_SIZE);
37199+ memzero_explicit(D, WP512_DIGEST_SIZE);
37200
37201 return 0;
37202 }
37203@@ -1113,8 +1113,8 @@ static int wp256_final(struct shash_desc *desc, u8 *out)
37204 u8 D[64];
37205
37206 wp512_final(desc, D);
37207- memcpy (out, D, WP256_DIGEST_SIZE);
37208- memset (D, 0, WP512_DIGEST_SIZE);
37209+ memcpy(out, D, WP256_DIGEST_SIZE);
37210+ memzero_explicit(D, WP512_DIGEST_SIZE);
37211
37212 return 0;
37213 }
37214diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
37215index 6921c7f..78e1af7 100644
37216--- a/drivers/acpi/acpica/hwxfsleep.c
37217+++ b/drivers/acpi/acpica/hwxfsleep.c
37218@@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
37219 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
37220
37221 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
37222- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
37223- acpi_hw_extended_sleep},
37224- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
37225- acpi_hw_extended_wake_prep},
37226- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
37227+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
37228+ .extended_function = acpi_hw_extended_sleep},
37229+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
37230+ .extended_function = acpi_hw_extended_wake_prep},
37231+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
37232+ .extended_function = acpi_hw_extended_wake}
37233 };
37234
37235 /*
37236diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
37237index 16129c7..8b675cd 100644
37238--- a/drivers/acpi/apei/apei-internal.h
37239+++ b/drivers/acpi/apei/apei-internal.h
37240@@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
37241 struct apei_exec_ins_type {
37242 u32 flags;
37243 apei_exec_ins_func_t run;
37244-};
37245+} __do_const;
37246
37247 struct apei_exec_context {
37248 u32 ip;
37249diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
37250index fc5f780..e5ac91a 100644
37251--- a/drivers/acpi/apei/ghes.c
37252+++ b/drivers/acpi/apei/ghes.c
37253@@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
37254 const struct acpi_hest_generic *generic,
37255 const struct acpi_hest_generic_status *estatus)
37256 {
37257- static atomic_t seqno;
37258+ static atomic_unchecked_t seqno;
37259 unsigned int curr_seqno;
37260 char pfx_seq[64];
37261
37262@@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
37263 else
37264 pfx = KERN_ERR;
37265 }
37266- curr_seqno = atomic_inc_return(&seqno);
37267+ curr_seqno = atomic_inc_return_unchecked(&seqno);
37268 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
37269 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
37270 pfx_seq, generic->header.source_id);
37271diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
37272index a83e3c6..c3d617f 100644
37273--- a/drivers/acpi/bgrt.c
37274+++ b/drivers/acpi/bgrt.c
37275@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
37276 if (!bgrt_image)
37277 return -ENODEV;
37278
37279- bin_attr_image.private = bgrt_image;
37280- bin_attr_image.size = bgrt_image_size;
37281+ pax_open_kernel();
37282+ *(void **)&bin_attr_image.private = bgrt_image;
37283+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
37284+ pax_close_kernel();
37285
37286 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
37287 if (!bgrt_kobj)
37288diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
37289index 36eb42e..3b2f47e 100644
37290--- a/drivers/acpi/blacklist.c
37291+++ b/drivers/acpi/blacklist.c
37292@@ -51,7 +51,7 @@ struct acpi_blacklist_item {
37293 u32 is_critical_error;
37294 };
37295
37296-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
37297+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
37298
37299 /*
37300 * POLICY: If *anything* doesn't work, put it on the blacklist.
37301@@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
37302 return 0;
37303 }
37304
37305-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
37306+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
37307 {
37308 .callback = dmi_disable_osi_vista,
37309 .ident = "Fujitsu Siemens",
37310diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
37311index c68e724..e863008 100644
37312--- a/drivers/acpi/custom_method.c
37313+++ b/drivers/acpi/custom_method.c
37314@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
37315 struct acpi_table_header table;
37316 acpi_status status;
37317
37318+#ifdef CONFIG_GRKERNSEC_KMEM
37319+ return -EPERM;
37320+#endif
37321+
37322 if (!(*ppos)) {
37323 /* parse the table header to get the table length */
37324 if (count <= sizeof(struct acpi_table_header))
37325diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
37326index 17f9ec5..d9a455e 100644
37327--- a/drivers/acpi/processor_idle.c
37328+++ b/drivers/acpi/processor_idle.c
37329@@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
37330 {
37331 int i, count = CPUIDLE_DRIVER_STATE_START;
37332 struct acpi_processor_cx *cx;
37333- struct cpuidle_state *state;
37334+ cpuidle_state_no_const *state;
37335 struct cpuidle_driver *drv = &acpi_idle_driver;
37336
37337 if (!pr->flags.power_setup_done)
37338diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
37339index 38cb978..352c761 100644
37340--- a/drivers/acpi/sysfs.c
37341+++ b/drivers/acpi/sysfs.c
37342@@ -423,11 +423,11 @@ static u32 num_counters;
37343 static struct attribute **all_attrs;
37344 static u32 acpi_gpe_count;
37345
37346-static struct attribute_group interrupt_stats_attr_group = {
37347+static attribute_group_no_const interrupt_stats_attr_group = {
37348 .name = "interrupts",
37349 };
37350
37351-static struct kobj_attribute *counter_attrs;
37352+static kobj_attribute_no_const *counter_attrs;
37353
37354 static void delete_gpe_attr_array(void)
37355 {
37356diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
37357index b784e9d..a69a049 100644
37358--- a/drivers/ata/libahci.c
37359+++ b/drivers/ata/libahci.c
37360@@ -1252,7 +1252,7 @@ int ahci_kick_engine(struct ata_port *ap)
37361 }
37362 EXPORT_SYMBOL_GPL(ahci_kick_engine);
37363
37364-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
37365+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
37366 struct ata_taskfile *tf, int is_cmd, u16 flags,
37367 unsigned long timeout_msec)
37368 {
37369diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
37370index 6f67490..f951ead 100644
37371--- a/drivers/ata/libata-core.c
37372+++ b/drivers/ata/libata-core.c
37373@@ -99,7 +99,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
37374 static void ata_dev_xfermask(struct ata_device *dev);
37375 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
37376
37377-atomic_t ata_print_id = ATOMIC_INIT(0);
37378+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
37379
37380 struct ata_force_param {
37381 const char *name;
37382@@ -4797,7 +4797,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
37383 struct ata_port *ap;
37384 unsigned int tag;
37385
37386- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37387+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37388 ap = qc->ap;
37389
37390 qc->flags = 0;
37391@@ -4813,7 +4813,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
37392 struct ata_port *ap;
37393 struct ata_link *link;
37394
37395- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37396+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37397 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
37398 ap = qc->ap;
37399 link = qc->dev->link;
37400@@ -5917,6 +5917,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
37401 return;
37402
37403 spin_lock(&lock);
37404+ pax_open_kernel();
37405
37406 for (cur = ops->inherits; cur; cur = cur->inherits) {
37407 void **inherit = (void **)cur;
37408@@ -5930,8 +5931,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
37409 if (IS_ERR(*pp))
37410 *pp = NULL;
37411
37412- ops->inherits = NULL;
37413+ *(struct ata_port_operations **)&ops->inherits = NULL;
37414
37415+ pax_close_kernel();
37416 spin_unlock(&lock);
37417 }
37418
37419@@ -6127,7 +6129,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
37420
37421 /* give ports names and add SCSI hosts */
37422 for (i = 0; i < host->n_ports; i++) {
37423- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
37424+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
37425 host->ports[i]->local_port_no = i + 1;
37426 }
37427
37428diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
37429index 0586f66..1a8f74a 100644
37430--- a/drivers/ata/libata-scsi.c
37431+++ b/drivers/ata/libata-scsi.c
37432@@ -4151,7 +4151,7 @@ int ata_sas_port_init(struct ata_port *ap)
37433
37434 if (rc)
37435 return rc;
37436- ap->print_id = atomic_inc_return(&ata_print_id);
37437+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
37438 return 0;
37439 }
37440 EXPORT_SYMBOL_GPL(ata_sas_port_init);
37441diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
37442index 5f4e0cc..ff2c347 100644
37443--- a/drivers/ata/libata.h
37444+++ b/drivers/ata/libata.h
37445@@ -53,7 +53,7 @@ enum {
37446 ATA_DNXFER_QUIET = (1 << 31),
37447 };
37448
37449-extern atomic_t ata_print_id;
37450+extern atomic_unchecked_t ata_print_id;
37451 extern int atapi_passthru16;
37452 extern int libata_fua;
37453 extern int libata_noacpi;
37454diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
37455index 4edb1a8..84e1658 100644
37456--- a/drivers/ata/pata_arasan_cf.c
37457+++ b/drivers/ata/pata_arasan_cf.c
37458@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
37459 /* Handle platform specific quirks */
37460 if (quirk) {
37461 if (quirk & CF_BROKEN_PIO) {
37462- ap->ops->set_piomode = NULL;
37463+ pax_open_kernel();
37464+ *(void **)&ap->ops->set_piomode = NULL;
37465+ pax_close_kernel();
37466 ap->pio_mask = 0;
37467 }
37468 if (quirk & CF_BROKEN_MWDMA)
37469diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
37470index f9b983a..887b9d8 100644
37471--- a/drivers/atm/adummy.c
37472+++ b/drivers/atm/adummy.c
37473@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
37474 vcc->pop(vcc, skb);
37475 else
37476 dev_kfree_skb_any(skb);
37477- atomic_inc(&vcc->stats->tx);
37478+ atomic_inc_unchecked(&vcc->stats->tx);
37479
37480 return 0;
37481 }
37482diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
37483index f1a9198..f466a4a 100644
37484--- a/drivers/atm/ambassador.c
37485+++ b/drivers/atm/ambassador.c
37486@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
37487 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
37488
37489 // VC layer stats
37490- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37491+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37492
37493 // free the descriptor
37494 kfree (tx_descr);
37495@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
37496 dump_skb ("<<<", vc, skb);
37497
37498 // VC layer stats
37499- atomic_inc(&atm_vcc->stats->rx);
37500+ atomic_inc_unchecked(&atm_vcc->stats->rx);
37501 __net_timestamp(skb);
37502 // end of our responsibility
37503 atm_vcc->push (atm_vcc, skb);
37504@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
37505 } else {
37506 PRINTK (KERN_INFO, "dropped over-size frame");
37507 // should we count this?
37508- atomic_inc(&atm_vcc->stats->rx_drop);
37509+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
37510 }
37511
37512 } else {
37513@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
37514 }
37515
37516 if (check_area (skb->data, skb->len)) {
37517- atomic_inc(&atm_vcc->stats->tx_err);
37518+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
37519 return -ENOMEM; // ?
37520 }
37521
37522diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
37523index 480fa6f..947067c 100644
37524--- a/drivers/atm/atmtcp.c
37525+++ b/drivers/atm/atmtcp.c
37526@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
37527 if (vcc->pop) vcc->pop(vcc,skb);
37528 else dev_kfree_skb(skb);
37529 if (dev_data) return 0;
37530- atomic_inc(&vcc->stats->tx_err);
37531+ atomic_inc_unchecked(&vcc->stats->tx_err);
37532 return -ENOLINK;
37533 }
37534 size = skb->len+sizeof(struct atmtcp_hdr);
37535@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
37536 if (!new_skb) {
37537 if (vcc->pop) vcc->pop(vcc,skb);
37538 else dev_kfree_skb(skb);
37539- atomic_inc(&vcc->stats->tx_err);
37540+ atomic_inc_unchecked(&vcc->stats->tx_err);
37541 return -ENOBUFS;
37542 }
37543 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
37544@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
37545 if (vcc->pop) vcc->pop(vcc,skb);
37546 else dev_kfree_skb(skb);
37547 out_vcc->push(out_vcc,new_skb);
37548- atomic_inc(&vcc->stats->tx);
37549- atomic_inc(&out_vcc->stats->rx);
37550+ atomic_inc_unchecked(&vcc->stats->tx);
37551+ atomic_inc_unchecked(&out_vcc->stats->rx);
37552 return 0;
37553 }
37554
37555@@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
37556 read_unlock(&vcc_sklist_lock);
37557 if (!out_vcc) {
37558 result = -EUNATCH;
37559- atomic_inc(&vcc->stats->tx_err);
37560+ atomic_inc_unchecked(&vcc->stats->tx_err);
37561 goto done;
37562 }
37563 skb_pull(skb,sizeof(struct atmtcp_hdr));
37564@@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
37565 __net_timestamp(new_skb);
37566 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
37567 out_vcc->push(out_vcc,new_skb);
37568- atomic_inc(&vcc->stats->tx);
37569- atomic_inc(&out_vcc->stats->rx);
37570+ atomic_inc_unchecked(&vcc->stats->tx);
37571+ atomic_inc_unchecked(&out_vcc->stats->rx);
37572 done:
37573 if (vcc->pop) vcc->pop(vcc,skb);
37574 else dev_kfree_skb(skb);
37575diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
37576index d65975a..0b87e20 100644
37577--- a/drivers/atm/eni.c
37578+++ b/drivers/atm/eni.c
37579@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
37580 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
37581 vcc->dev->number);
37582 length = 0;
37583- atomic_inc(&vcc->stats->rx_err);
37584+ atomic_inc_unchecked(&vcc->stats->rx_err);
37585 }
37586 else {
37587 length = ATM_CELL_SIZE-1; /* no HEC */
37588@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
37589 size);
37590 }
37591 eff = length = 0;
37592- atomic_inc(&vcc->stats->rx_err);
37593+ atomic_inc_unchecked(&vcc->stats->rx_err);
37594 }
37595 else {
37596 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
37597@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
37598 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
37599 vcc->dev->number,vcc->vci,length,size << 2,descr);
37600 length = eff = 0;
37601- atomic_inc(&vcc->stats->rx_err);
37602+ atomic_inc_unchecked(&vcc->stats->rx_err);
37603 }
37604 }
37605 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
37606@@ -767,7 +767,7 @@ rx_dequeued++;
37607 vcc->push(vcc,skb);
37608 pushed++;
37609 }
37610- atomic_inc(&vcc->stats->rx);
37611+ atomic_inc_unchecked(&vcc->stats->rx);
37612 }
37613 wake_up(&eni_dev->rx_wait);
37614 }
37615@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
37616 PCI_DMA_TODEVICE);
37617 if (vcc->pop) vcc->pop(vcc,skb);
37618 else dev_kfree_skb_irq(skb);
37619- atomic_inc(&vcc->stats->tx);
37620+ atomic_inc_unchecked(&vcc->stats->tx);
37621 wake_up(&eni_dev->tx_wait);
37622 dma_complete++;
37623 }
37624diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
37625index 82f2ae0..f205c02 100644
37626--- a/drivers/atm/firestream.c
37627+++ b/drivers/atm/firestream.c
37628@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
37629 }
37630 }
37631
37632- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37633+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37634
37635 fs_dprintk (FS_DEBUG_TXMEM, "i");
37636 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
37637@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
37638 #endif
37639 skb_put (skb, qe->p1 & 0xffff);
37640 ATM_SKB(skb)->vcc = atm_vcc;
37641- atomic_inc(&atm_vcc->stats->rx);
37642+ atomic_inc_unchecked(&atm_vcc->stats->rx);
37643 __net_timestamp(skb);
37644 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
37645 atm_vcc->push (atm_vcc, skb);
37646@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
37647 kfree (pe);
37648 }
37649 if (atm_vcc)
37650- atomic_inc(&atm_vcc->stats->rx_drop);
37651+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
37652 break;
37653 case 0x1f: /* Reassembly abort: no buffers. */
37654 /* Silently increment error counter. */
37655 if (atm_vcc)
37656- atomic_inc(&atm_vcc->stats->rx_drop);
37657+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
37658 break;
37659 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
37660 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
37661diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
37662index d4725fc..2d4ea65 100644
37663--- a/drivers/atm/fore200e.c
37664+++ b/drivers/atm/fore200e.c
37665@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
37666 #endif
37667 /* check error condition */
37668 if (*entry->status & STATUS_ERROR)
37669- atomic_inc(&vcc->stats->tx_err);
37670+ atomic_inc_unchecked(&vcc->stats->tx_err);
37671 else
37672- atomic_inc(&vcc->stats->tx);
37673+ atomic_inc_unchecked(&vcc->stats->tx);
37674 }
37675 }
37676
37677@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
37678 if (skb == NULL) {
37679 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
37680
37681- atomic_inc(&vcc->stats->rx_drop);
37682+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37683 return -ENOMEM;
37684 }
37685
37686@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
37687
37688 dev_kfree_skb_any(skb);
37689
37690- atomic_inc(&vcc->stats->rx_drop);
37691+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37692 return -ENOMEM;
37693 }
37694
37695 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
37696
37697 vcc->push(vcc, skb);
37698- atomic_inc(&vcc->stats->rx);
37699+ atomic_inc_unchecked(&vcc->stats->rx);
37700
37701 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
37702
37703@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
37704 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
37705 fore200e->atm_dev->number,
37706 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
37707- atomic_inc(&vcc->stats->rx_err);
37708+ atomic_inc_unchecked(&vcc->stats->rx_err);
37709 }
37710 }
37711
37712@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
37713 goto retry_here;
37714 }
37715
37716- atomic_inc(&vcc->stats->tx_err);
37717+ atomic_inc_unchecked(&vcc->stats->tx_err);
37718
37719 fore200e->tx_sat++;
37720 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
37721diff --git a/drivers/atm/he.c b/drivers/atm/he.c
37722index c39702b..785b73b 100644
37723--- a/drivers/atm/he.c
37724+++ b/drivers/atm/he.c
37725@@ -1689,7 +1689,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
37726
37727 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
37728 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
37729- atomic_inc(&vcc->stats->rx_drop);
37730+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37731 goto return_host_buffers;
37732 }
37733
37734@@ -1716,7 +1716,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
37735 RBRQ_LEN_ERR(he_dev->rbrq_head)
37736 ? "LEN_ERR" : "",
37737 vcc->vpi, vcc->vci);
37738- atomic_inc(&vcc->stats->rx_err);
37739+ atomic_inc_unchecked(&vcc->stats->rx_err);
37740 goto return_host_buffers;
37741 }
37742
37743@@ -1768,7 +1768,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
37744 vcc->push(vcc, skb);
37745 spin_lock(&he_dev->global_lock);
37746
37747- atomic_inc(&vcc->stats->rx);
37748+ atomic_inc_unchecked(&vcc->stats->rx);
37749
37750 return_host_buffers:
37751 ++pdus_assembled;
37752@@ -2094,7 +2094,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
37753 tpd->vcc->pop(tpd->vcc, tpd->skb);
37754 else
37755 dev_kfree_skb_any(tpd->skb);
37756- atomic_inc(&tpd->vcc->stats->tx_err);
37757+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
37758 }
37759 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
37760 return;
37761@@ -2506,7 +2506,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37762 vcc->pop(vcc, skb);
37763 else
37764 dev_kfree_skb_any(skb);
37765- atomic_inc(&vcc->stats->tx_err);
37766+ atomic_inc_unchecked(&vcc->stats->tx_err);
37767 return -EINVAL;
37768 }
37769
37770@@ -2517,7 +2517,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37771 vcc->pop(vcc, skb);
37772 else
37773 dev_kfree_skb_any(skb);
37774- atomic_inc(&vcc->stats->tx_err);
37775+ atomic_inc_unchecked(&vcc->stats->tx_err);
37776 return -EINVAL;
37777 }
37778 #endif
37779@@ -2529,7 +2529,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37780 vcc->pop(vcc, skb);
37781 else
37782 dev_kfree_skb_any(skb);
37783- atomic_inc(&vcc->stats->tx_err);
37784+ atomic_inc_unchecked(&vcc->stats->tx_err);
37785 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37786 return -ENOMEM;
37787 }
37788@@ -2571,7 +2571,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37789 vcc->pop(vcc, skb);
37790 else
37791 dev_kfree_skb_any(skb);
37792- atomic_inc(&vcc->stats->tx_err);
37793+ atomic_inc_unchecked(&vcc->stats->tx_err);
37794 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37795 return -ENOMEM;
37796 }
37797@@ -2602,7 +2602,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37798 __enqueue_tpd(he_dev, tpd, cid);
37799 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37800
37801- atomic_inc(&vcc->stats->tx);
37802+ atomic_inc_unchecked(&vcc->stats->tx);
37803
37804 return 0;
37805 }
37806diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
37807index 1dc0519..1aadaf7 100644
37808--- a/drivers/atm/horizon.c
37809+++ b/drivers/atm/horizon.c
37810@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
37811 {
37812 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
37813 // VC layer stats
37814- atomic_inc(&vcc->stats->rx);
37815+ atomic_inc_unchecked(&vcc->stats->rx);
37816 __net_timestamp(skb);
37817 // end of our responsibility
37818 vcc->push (vcc, skb);
37819@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
37820 dev->tx_iovec = NULL;
37821
37822 // VC layer stats
37823- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37824+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37825
37826 // free the skb
37827 hrz_kfree_skb (skb);
37828diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
37829index 2b24ed0..b3d6acc 100644
37830--- a/drivers/atm/idt77252.c
37831+++ b/drivers/atm/idt77252.c
37832@@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
37833 else
37834 dev_kfree_skb(skb);
37835
37836- atomic_inc(&vcc->stats->tx);
37837+ atomic_inc_unchecked(&vcc->stats->tx);
37838 }
37839
37840 atomic_dec(&scq->used);
37841@@ -1072,13 +1072,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37842 if ((sb = dev_alloc_skb(64)) == NULL) {
37843 printk("%s: Can't allocate buffers for aal0.\n",
37844 card->name);
37845- atomic_add(i, &vcc->stats->rx_drop);
37846+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
37847 break;
37848 }
37849 if (!atm_charge(vcc, sb->truesize)) {
37850 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
37851 card->name);
37852- atomic_add(i - 1, &vcc->stats->rx_drop);
37853+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
37854 dev_kfree_skb(sb);
37855 break;
37856 }
37857@@ -1095,7 +1095,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37858 ATM_SKB(sb)->vcc = vcc;
37859 __net_timestamp(sb);
37860 vcc->push(vcc, sb);
37861- atomic_inc(&vcc->stats->rx);
37862+ atomic_inc_unchecked(&vcc->stats->rx);
37863
37864 cell += ATM_CELL_PAYLOAD;
37865 }
37866@@ -1132,13 +1132,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37867 "(CDC: %08x)\n",
37868 card->name, len, rpp->len, readl(SAR_REG_CDC));
37869 recycle_rx_pool_skb(card, rpp);
37870- atomic_inc(&vcc->stats->rx_err);
37871+ atomic_inc_unchecked(&vcc->stats->rx_err);
37872 return;
37873 }
37874 if (stat & SAR_RSQE_CRC) {
37875 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
37876 recycle_rx_pool_skb(card, rpp);
37877- atomic_inc(&vcc->stats->rx_err);
37878+ atomic_inc_unchecked(&vcc->stats->rx_err);
37879 return;
37880 }
37881 if (skb_queue_len(&rpp->queue) > 1) {
37882@@ -1149,7 +1149,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37883 RXPRINTK("%s: Can't alloc RX skb.\n",
37884 card->name);
37885 recycle_rx_pool_skb(card, rpp);
37886- atomic_inc(&vcc->stats->rx_err);
37887+ atomic_inc_unchecked(&vcc->stats->rx_err);
37888 return;
37889 }
37890 if (!atm_charge(vcc, skb->truesize)) {
37891@@ -1168,7 +1168,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37892 __net_timestamp(skb);
37893
37894 vcc->push(vcc, skb);
37895- atomic_inc(&vcc->stats->rx);
37896+ atomic_inc_unchecked(&vcc->stats->rx);
37897
37898 return;
37899 }
37900@@ -1190,7 +1190,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37901 __net_timestamp(skb);
37902
37903 vcc->push(vcc, skb);
37904- atomic_inc(&vcc->stats->rx);
37905+ atomic_inc_unchecked(&vcc->stats->rx);
37906
37907 if (skb->truesize > SAR_FB_SIZE_3)
37908 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
37909@@ -1301,14 +1301,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
37910 if (vcc->qos.aal != ATM_AAL0) {
37911 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
37912 card->name, vpi, vci);
37913- atomic_inc(&vcc->stats->rx_drop);
37914+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37915 goto drop;
37916 }
37917
37918 if ((sb = dev_alloc_skb(64)) == NULL) {
37919 printk("%s: Can't allocate buffers for AAL0.\n",
37920 card->name);
37921- atomic_inc(&vcc->stats->rx_err);
37922+ atomic_inc_unchecked(&vcc->stats->rx_err);
37923 goto drop;
37924 }
37925
37926@@ -1327,7 +1327,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
37927 ATM_SKB(sb)->vcc = vcc;
37928 __net_timestamp(sb);
37929 vcc->push(vcc, sb);
37930- atomic_inc(&vcc->stats->rx);
37931+ atomic_inc_unchecked(&vcc->stats->rx);
37932
37933 drop:
37934 skb_pull(queue, 64);
37935@@ -1952,13 +1952,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37936
37937 if (vc == NULL) {
37938 printk("%s: NULL connection in send().\n", card->name);
37939- atomic_inc(&vcc->stats->tx_err);
37940+ atomic_inc_unchecked(&vcc->stats->tx_err);
37941 dev_kfree_skb(skb);
37942 return -EINVAL;
37943 }
37944 if (!test_bit(VCF_TX, &vc->flags)) {
37945 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
37946- atomic_inc(&vcc->stats->tx_err);
37947+ atomic_inc_unchecked(&vcc->stats->tx_err);
37948 dev_kfree_skb(skb);
37949 return -EINVAL;
37950 }
37951@@ -1970,14 +1970,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37952 break;
37953 default:
37954 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
37955- atomic_inc(&vcc->stats->tx_err);
37956+ atomic_inc_unchecked(&vcc->stats->tx_err);
37957 dev_kfree_skb(skb);
37958 return -EINVAL;
37959 }
37960
37961 if (skb_shinfo(skb)->nr_frags != 0) {
37962 printk("%s: No scatter-gather yet.\n", card->name);
37963- atomic_inc(&vcc->stats->tx_err);
37964+ atomic_inc_unchecked(&vcc->stats->tx_err);
37965 dev_kfree_skb(skb);
37966 return -EINVAL;
37967 }
37968@@ -1985,7 +1985,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37969
37970 err = queue_skb(card, vc, skb, oam);
37971 if (err) {
37972- atomic_inc(&vcc->stats->tx_err);
37973+ atomic_inc_unchecked(&vcc->stats->tx_err);
37974 dev_kfree_skb(skb);
37975 return err;
37976 }
37977@@ -2008,7 +2008,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
37978 skb = dev_alloc_skb(64);
37979 if (!skb) {
37980 printk("%s: Out of memory in send_oam().\n", card->name);
37981- atomic_inc(&vcc->stats->tx_err);
37982+ atomic_inc_unchecked(&vcc->stats->tx_err);
37983 return -ENOMEM;
37984 }
37985 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
37986diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
37987index 4217f29..88f547a 100644
37988--- a/drivers/atm/iphase.c
37989+++ b/drivers/atm/iphase.c
37990@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
37991 status = (u_short) (buf_desc_ptr->desc_mode);
37992 if (status & (RX_CER | RX_PTE | RX_OFL))
37993 {
37994- atomic_inc(&vcc->stats->rx_err);
37995+ atomic_inc_unchecked(&vcc->stats->rx_err);
37996 IF_ERR(printk("IA: bad packet, dropping it");)
37997 if (status & RX_CER) {
37998 IF_ERR(printk(" cause: packet CRC error\n");)
37999@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
38000 len = dma_addr - buf_addr;
38001 if (len > iadev->rx_buf_sz) {
38002 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
38003- atomic_inc(&vcc->stats->rx_err);
38004+ atomic_inc_unchecked(&vcc->stats->rx_err);
38005 goto out_free_desc;
38006 }
38007
38008@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
38009 ia_vcc = INPH_IA_VCC(vcc);
38010 if (ia_vcc == NULL)
38011 {
38012- atomic_inc(&vcc->stats->rx_err);
38013+ atomic_inc_unchecked(&vcc->stats->rx_err);
38014 atm_return(vcc, skb->truesize);
38015 dev_kfree_skb_any(skb);
38016 goto INCR_DLE;
38017@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
38018 if ((length > iadev->rx_buf_sz) || (length >
38019 (skb->len - sizeof(struct cpcs_trailer))))
38020 {
38021- atomic_inc(&vcc->stats->rx_err);
38022+ atomic_inc_unchecked(&vcc->stats->rx_err);
38023 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
38024 length, skb->len);)
38025 atm_return(vcc, skb->truesize);
38026@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
38027
38028 IF_RX(printk("rx_dle_intr: skb push");)
38029 vcc->push(vcc,skb);
38030- atomic_inc(&vcc->stats->rx);
38031+ atomic_inc_unchecked(&vcc->stats->rx);
38032 iadev->rx_pkt_cnt++;
38033 }
38034 INCR_DLE:
38035@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
38036 {
38037 struct k_sonet_stats *stats;
38038 stats = &PRIV(_ia_dev[board])->sonet_stats;
38039- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
38040- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
38041- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
38042- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
38043- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
38044- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
38045- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
38046- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
38047- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
38048+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
38049+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
38050+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
38051+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
38052+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
38053+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
38054+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
38055+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
38056+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
38057 }
38058 ia_cmds.status = 0;
38059 break;
38060@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
38061 if ((desc == 0) || (desc > iadev->num_tx_desc))
38062 {
38063 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
38064- atomic_inc(&vcc->stats->tx);
38065+ atomic_inc_unchecked(&vcc->stats->tx);
38066 if (vcc->pop)
38067 vcc->pop(vcc, skb);
38068 else
38069@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
38070 ATM_DESC(skb) = vcc->vci;
38071 skb_queue_tail(&iadev->tx_dma_q, skb);
38072
38073- atomic_inc(&vcc->stats->tx);
38074+ atomic_inc_unchecked(&vcc->stats->tx);
38075 iadev->tx_pkt_cnt++;
38076 /* Increment transaction counter */
38077 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
38078
38079 #if 0
38080 /* add flow control logic */
38081- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
38082+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
38083 if (iavcc->vc_desc_cnt > 10) {
38084 vcc->tx_quota = vcc->tx_quota * 3 / 4;
38085 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
38086diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
38087index fa7d7019..1e404c7 100644
38088--- a/drivers/atm/lanai.c
38089+++ b/drivers/atm/lanai.c
38090@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
38091 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
38092 lanai_endtx(lanai, lvcc);
38093 lanai_free_skb(lvcc->tx.atmvcc, skb);
38094- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
38095+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
38096 }
38097
38098 /* Try to fill the buffer - don't call unless there is backlog */
38099@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
38100 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
38101 __net_timestamp(skb);
38102 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
38103- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
38104+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
38105 out:
38106 lvcc->rx.buf.ptr = end;
38107 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
38108@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38109 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
38110 "vcc %d\n", lanai->number, (unsigned int) s, vci);
38111 lanai->stats.service_rxnotaal5++;
38112- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38113+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38114 return 0;
38115 }
38116 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
38117@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38118 int bytes;
38119 read_unlock(&vcc_sklist_lock);
38120 DPRINTK("got trashed rx pdu on vci %d\n", vci);
38121- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38122+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38123 lvcc->stats.x.aal5.service_trash++;
38124 bytes = (SERVICE_GET_END(s) * 16) -
38125 (((unsigned long) lvcc->rx.buf.ptr) -
38126@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38127 }
38128 if (s & SERVICE_STREAM) {
38129 read_unlock(&vcc_sklist_lock);
38130- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38131+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38132 lvcc->stats.x.aal5.service_stream++;
38133 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
38134 "PDU on VCI %d!\n", lanai->number, vci);
38135@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38136 return 0;
38137 }
38138 DPRINTK("got rx crc error on vci %d\n", vci);
38139- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38140+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38141 lvcc->stats.x.aal5.service_rxcrc++;
38142 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
38143 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
38144diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
38145index 9988ac9..7c52585 100644
38146--- a/drivers/atm/nicstar.c
38147+++ b/drivers/atm/nicstar.c
38148@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38149 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
38150 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
38151 card->index);
38152- atomic_inc(&vcc->stats->tx_err);
38153+ atomic_inc_unchecked(&vcc->stats->tx_err);
38154 dev_kfree_skb_any(skb);
38155 return -EINVAL;
38156 }
38157@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38158 if (!vc->tx) {
38159 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
38160 card->index);
38161- atomic_inc(&vcc->stats->tx_err);
38162+ atomic_inc_unchecked(&vcc->stats->tx_err);
38163 dev_kfree_skb_any(skb);
38164 return -EINVAL;
38165 }
38166@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38167 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
38168 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
38169 card->index);
38170- atomic_inc(&vcc->stats->tx_err);
38171+ atomic_inc_unchecked(&vcc->stats->tx_err);
38172 dev_kfree_skb_any(skb);
38173 return -EINVAL;
38174 }
38175
38176 if (skb_shinfo(skb)->nr_frags != 0) {
38177 printk("nicstar%d: No scatter-gather yet.\n", card->index);
38178- atomic_inc(&vcc->stats->tx_err);
38179+ atomic_inc_unchecked(&vcc->stats->tx_err);
38180 dev_kfree_skb_any(skb);
38181 return -EINVAL;
38182 }
38183@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38184 }
38185
38186 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
38187- atomic_inc(&vcc->stats->tx_err);
38188+ atomic_inc_unchecked(&vcc->stats->tx_err);
38189 dev_kfree_skb_any(skb);
38190 return -EIO;
38191 }
38192- atomic_inc(&vcc->stats->tx);
38193+ atomic_inc_unchecked(&vcc->stats->tx);
38194
38195 return 0;
38196 }
38197@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38198 printk
38199 ("nicstar%d: Can't allocate buffers for aal0.\n",
38200 card->index);
38201- atomic_add(i, &vcc->stats->rx_drop);
38202+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
38203 break;
38204 }
38205 if (!atm_charge(vcc, sb->truesize)) {
38206 RXPRINTK
38207 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
38208 card->index);
38209- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
38210+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
38211 dev_kfree_skb_any(sb);
38212 break;
38213 }
38214@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38215 ATM_SKB(sb)->vcc = vcc;
38216 __net_timestamp(sb);
38217 vcc->push(vcc, sb);
38218- atomic_inc(&vcc->stats->rx);
38219+ atomic_inc_unchecked(&vcc->stats->rx);
38220 cell += ATM_CELL_PAYLOAD;
38221 }
38222
38223@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38224 if (iovb == NULL) {
38225 printk("nicstar%d: Out of iovec buffers.\n",
38226 card->index);
38227- atomic_inc(&vcc->stats->rx_drop);
38228+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38229 recycle_rx_buf(card, skb);
38230 return;
38231 }
38232@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38233 small or large buffer itself. */
38234 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
38235 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
38236- atomic_inc(&vcc->stats->rx_err);
38237+ atomic_inc_unchecked(&vcc->stats->rx_err);
38238 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
38239 NS_MAX_IOVECS);
38240 NS_PRV_IOVCNT(iovb) = 0;
38241@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38242 ("nicstar%d: Expected a small buffer, and this is not one.\n",
38243 card->index);
38244 which_list(card, skb);
38245- atomic_inc(&vcc->stats->rx_err);
38246+ atomic_inc_unchecked(&vcc->stats->rx_err);
38247 recycle_rx_buf(card, skb);
38248 vc->rx_iov = NULL;
38249 recycle_iov_buf(card, iovb);
38250@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38251 ("nicstar%d: Expected a large buffer, and this is not one.\n",
38252 card->index);
38253 which_list(card, skb);
38254- atomic_inc(&vcc->stats->rx_err);
38255+ atomic_inc_unchecked(&vcc->stats->rx_err);
38256 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
38257 NS_PRV_IOVCNT(iovb));
38258 vc->rx_iov = NULL;
38259@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38260 printk(" - PDU size mismatch.\n");
38261 else
38262 printk(".\n");
38263- atomic_inc(&vcc->stats->rx_err);
38264+ atomic_inc_unchecked(&vcc->stats->rx_err);
38265 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
38266 NS_PRV_IOVCNT(iovb));
38267 vc->rx_iov = NULL;
38268@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38269 /* skb points to a small buffer */
38270 if (!atm_charge(vcc, skb->truesize)) {
38271 push_rxbufs(card, skb);
38272- atomic_inc(&vcc->stats->rx_drop);
38273+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38274 } else {
38275 skb_put(skb, len);
38276 dequeue_sm_buf(card, skb);
38277@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38278 ATM_SKB(skb)->vcc = vcc;
38279 __net_timestamp(skb);
38280 vcc->push(vcc, skb);
38281- atomic_inc(&vcc->stats->rx);
38282+ atomic_inc_unchecked(&vcc->stats->rx);
38283 }
38284 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
38285 struct sk_buff *sb;
38286@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38287 if (len <= NS_SMBUFSIZE) {
38288 if (!atm_charge(vcc, sb->truesize)) {
38289 push_rxbufs(card, sb);
38290- atomic_inc(&vcc->stats->rx_drop);
38291+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38292 } else {
38293 skb_put(sb, len);
38294 dequeue_sm_buf(card, sb);
38295@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38296 ATM_SKB(sb)->vcc = vcc;
38297 __net_timestamp(sb);
38298 vcc->push(vcc, sb);
38299- atomic_inc(&vcc->stats->rx);
38300+ atomic_inc_unchecked(&vcc->stats->rx);
38301 }
38302
38303 push_rxbufs(card, skb);
38304@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38305
38306 if (!atm_charge(vcc, skb->truesize)) {
38307 push_rxbufs(card, skb);
38308- atomic_inc(&vcc->stats->rx_drop);
38309+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38310 } else {
38311 dequeue_lg_buf(card, skb);
38312 #ifdef NS_USE_DESTRUCTORS
38313@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38314 ATM_SKB(skb)->vcc = vcc;
38315 __net_timestamp(skb);
38316 vcc->push(vcc, skb);
38317- atomic_inc(&vcc->stats->rx);
38318+ atomic_inc_unchecked(&vcc->stats->rx);
38319 }
38320
38321 push_rxbufs(card, sb);
38322@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38323 printk
38324 ("nicstar%d: Out of huge buffers.\n",
38325 card->index);
38326- atomic_inc(&vcc->stats->rx_drop);
38327+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38328 recycle_iovec_rx_bufs(card,
38329 (struct iovec *)
38330 iovb->data,
38331@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38332 card->hbpool.count++;
38333 } else
38334 dev_kfree_skb_any(hb);
38335- atomic_inc(&vcc->stats->rx_drop);
38336+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38337 } else {
38338 /* Copy the small buffer to the huge buffer */
38339 sb = (struct sk_buff *)iov->iov_base;
38340@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38341 #endif /* NS_USE_DESTRUCTORS */
38342 __net_timestamp(hb);
38343 vcc->push(vcc, hb);
38344- atomic_inc(&vcc->stats->rx);
38345+ atomic_inc_unchecked(&vcc->stats->rx);
38346 }
38347 }
38348
38349diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
38350index 7652e8d..db45069 100644
38351--- a/drivers/atm/solos-pci.c
38352+++ b/drivers/atm/solos-pci.c
38353@@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
38354 }
38355 atm_charge(vcc, skb->truesize);
38356 vcc->push(vcc, skb);
38357- atomic_inc(&vcc->stats->rx);
38358+ atomic_inc_unchecked(&vcc->stats->rx);
38359 break;
38360
38361 case PKT_STATUS:
38362@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
38363 vcc = SKB_CB(oldskb)->vcc;
38364
38365 if (vcc) {
38366- atomic_inc(&vcc->stats->tx);
38367+ atomic_inc_unchecked(&vcc->stats->tx);
38368 solos_pop(vcc, oldskb);
38369 } else {
38370 dev_kfree_skb_irq(oldskb);
38371diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
38372index 0215934..ce9f5b1 100644
38373--- a/drivers/atm/suni.c
38374+++ b/drivers/atm/suni.c
38375@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
38376
38377
38378 #define ADD_LIMITED(s,v) \
38379- atomic_add((v),&stats->s); \
38380- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
38381+ atomic_add_unchecked((v),&stats->s); \
38382+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
38383
38384
38385 static void suni_hz(unsigned long from_timer)
38386diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
38387index 5120a96..e2572bd 100644
38388--- a/drivers/atm/uPD98402.c
38389+++ b/drivers/atm/uPD98402.c
38390@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
38391 struct sonet_stats tmp;
38392 int error = 0;
38393
38394- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
38395+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
38396 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
38397 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
38398 if (zero && !error) {
38399@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
38400
38401
38402 #define ADD_LIMITED(s,v) \
38403- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
38404- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
38405- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
38406+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
38407+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
38408+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
38409
38410
38411 static void stat_event(struct atm_dev *dev)
38412@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
38413 if (reason & uPD98402_INT_PFM) stat_event(dev);
38414 if (reason & uPD98402_INT_PCO) {
38415 (void) GET(PCOCR); /* clear interrupt cause */
38416- atomic_add(GET(HECCT),
38417+ atomic_add_unchecked(GET(HECCT),
38418 &PRIV(dev)->sonet_stats.uncorr_hcs);
38419 }
38420 if ((reason & uPD98402_INT_RFO) &&
38421@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
38422 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
38423 uPD98402_INT_LOS),PIMR); /* enable them */
38424 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
38425- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
38426- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
38427- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
38428+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
38429+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
38430+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
38431 return 0;
38432 }
38433
38434diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
38435index 969c3c2..9b72956 100644
38436--- a/drivers/atm/zatm.c
38437+++ b/drivers/atm/zatm.c
38438@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
38439 }
38440 if (!size) {
38441 dev_kfree_skb_irq(skb);
38442- if (vcc) atomic_inc(&vcc->stats->rx_err);
38443+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
38444 continue;
38445 }
38446 if (!atm_charge(vcc,skb->truesize)) {
38447@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
38448 skb->len = size;
38449 ATM_SKB(skb)->vcc = vcc;
38450 vcc->push(vcc,skb);
38451- atomic_inc(&vcc->stats->rx);
38452+ atomic_inc_unchecked(&vcc->stats->rx);
38453 }
38454 zout(pos & 0xffff,MTA(mbx));
38455 #if 0 /* probably a stupid idea */
38456@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
38457 skb_queue_head(&zatm_vcc->backlog,skb);
38458 break;
38459 }
38460- atomic_inc(&vcc->stats->tx);
38461+ atomic_inc_unchecked(&vcc->stats->tx);
38462 wake_up(&zatm_vcc->tx_wait);
38463 }
38464
38465diff --git a/drivers/base/bus.c b/drivers/base/bus.c
38466index 83e910a..b224a73 100644
38467--- a/drivers/base/bus.c
38468+++ b/drivers/base/bus.c
38469@@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
38470 return -EINVAL;
38471
38472 mutex_lock(&subsys->p->mutex);
38473- list_add_tail(&sif->node, &subsys->p->interfaces);
38474+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
38475 if (sif->add_dev) {
38476 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
38477 while ((dev = subsys_dev_iter_next(&iter)))
38478@@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
38479 subsys = sif->subsys;
38480
38481 mutex_lock(&subsys->p->mutex);
38482- list_del_init(&sif->node);
38483+ pax_list_del_init((struct list_head *)&sif->node);
38484 if (sif->remove_dev) {
38485 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
38486 while ((dev = subsys_dev_iter_next(&iter)))
38487diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
38488index 25798db..15f130e 100644
38489--- a/drivers/base/devtmpfs.c
38490+++ b/drivers/base/devtmpfs.c
38491@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
38492 if (!thread)
38493 return 0;
38494
38495- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
38496+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
38497 if (err)
38498 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
38499 else
38500@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
38501 *err = sys_unshare(CLONE_NEWNS);
38502 if (*err)
38503 goto out;
38504- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
38505+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
38506 if (*err)
38507 goto out;
38508- sys_chdir("/.."); /* will traverse into overmounted root */
38509- sys_chroot(".");
38510+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
38511+ sys_chroot((char __force_user *)".");
38512 complete(&setup_done);
38513 while (1) {
38514 spin_lock(&req_lock);
38515diff --git a/drivers/base/node.c b/drivers/base/node.c
38516index d51c49c..28908df 100644
38517--- a/drivers/base/node.c
38518+++ b/drivers/base/node.c
38519@@ -623,7 +623,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
38520 struct node_attr {
38521 struct device_attribute attr;
38522 enum node_states state;
38523-};
38524+} __do_const;
38525
38526 static ssize_t show_node_state(struct device *dev,
38527 struct device_attribute *attr, char *buf)
38528diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
38529index eee55c1..b8c9393 100644
38530--- a/drivers/base/power/domain.c
38531+++ b/drivers/base/power/domain.c
38532@@ -1821,9 +1821,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
38533
38534 if (dev->power.subsys_data->domain_data) {
38535 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
38536- gpd_data->ops = (struct gpd_dev_ops){ NULL };
38537+ memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
38538 if (clear_td)
38539- gpd_data->td = (struct gpd_timing_data){ 0 };
38540+ memset(&gpd_data->td, 0, sizeof(gpd_data->td));
38541
38542 if (--gpd_data->refcount == 0) {
38543 dev->power.subsys_data->domain_data = NULL;
38544@@ -1862,7 +1862,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
38545 {
38546 struct cpuidle_driver *cpuidle_drv;
38547 struct gpd_cpu_data *cpu_data;
38548- struct cpuidle_state *idle_state;
38549+ cpuidle_state_no_const *idle_state;
38550 int ret = 0;
38551
38552 if (IS_ERR_OR_NULL(genpd) || state < 0)
38553@@ -1930,7 +1930,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
38554 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
38555 {
38556 struct gpd_cpu_data *cpu_data;
38557- struct cpuidle_state *idle_state;
38558+ cpuidle_state_no_const *idle_state;
38559 int ret = 0;
38560
38561 if (IS_ERR_OR_NULL(genpd))
38562diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
38563index 95b181d1..c4f0e19 100644
38564--- a/drivers/base/power/sysfs.c
38565+++ b/drivers/base/power/sysfs.c
38566@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
38567 return -EIO;
38568 }
38569 }
38570- return sprintf(buf, p);
38571+ return sprintf(buf, "%s", p);
38572 }
38573
38574 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
38575diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
38576index eb1bd2e..2667d3a 100644
38577--- a/drivers/base/power/wakeup.c
38578+++ b/drivers/base/power/wakeup.c
38579@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
38580 * They need to be modified together atomically, so it's better to use one
38581 * atomic variable to hold them both.
38582 */
38583-static atomic_t combined_event_count = ATOMIC_INIT(0);
38584+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
38585
38586 #define IN_PROGRESS_BITS (sizeof(int) * 4)
38587 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
38588
38589 static void split_counters(unsigned int *cnt, unsigned int *inpr)
38590 {
38591- unsigned int comb = atomic_read(&combined_event_count);
38592+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
38593
38594 *cnt = (comb >> IN_PROGRESS_BITS);
38595 *inpr = comb & MAX_IN_PROGRESS;
38596@@ -401,7 +401,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
38597 ws->start_prevent_time = ws->last_time;
38598
38599 /* Increment the counter of events in progress. */
38600- cec = atomic_inc_return(&combined_event_count);
38601+ cec = atomic_inc_return_unchecked(&combined_event_count);
38602
38603 trace_wakeup_source_activate(ws->name, cec);
38604 }
38605@@ -527,7 +527,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
38606 * Increment the counter of registered wakeup events and decrement the
38607 * couter of wakeup events in progress simultaneously.
38608 */
38609- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
38610+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
38611 trace_wakeup_source_deactivate(ws->name, cec);
38612
38613 split_counters(&cnt, &inpr);
38614diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
38615index dbb8350..4762f4c 100644
38616--- a/drivers/base/syscore.c
38617+++ b/drivers/base/syscore.c
38618@@ -22,7 +22,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
38619 void register_syscore_ops(struct syscore_ops *ops)
38620 {
38621 mutex_lock(&syscore_ops_lock);
38622- list_add_tail(&ops->node, &syscore_ops_list);
38623+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
38624 mutex_unlock(&syscore_ops_lock);
38625 }
38626 EXPORT_SYMBOL_GPL(register_syscore_ops);
38627@@ -34,7 +34,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
38628 void unregister_syscore_ops(struct syscore_ops *ops)
38629 {
38630 mutex_lock(&syscore_ops_lock);
38631- list_del(&ops->node);
38632+ pax_list_del((struct list_head *)&ops->node);
38633 mutex_unlock(&syscore_ops_lock);
38634 }
38635 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
38636diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
38637index ff20f19..018f1da 100644
38638--- a/drivers/block/cciss.c
38639+++ b/drivers/block/cciss.c
38640@@ -3008,7 +3008,7 @@ static void start_io(ctlr_info_t *h)
38641 while (!list_empty(&h->reqQ)) {
38642 c = list_entry(h->reqQ.next, CommandList_struct, list);
38643 /* can't do anything if fifo is full */
38644- if ((h->access.fifo_full(h))) {
38645+ if ((h->access->fifo_full(h))) {
38646 dev_warn(&h->pdev->dev, "fifo full\n");
38647 break;
38648 }
38649@@ -3018,7 +3018,7 @@ static void start_io(ctlr_info_t *h)
38650 h->Qdepth--;
38651
38652 /* Tell the controller execute command */
38653- h->access.submit_command(h, c);
38654+ h->access->submit_command(h, c);
38655
38656 /* Put job onto the completed Q */
38657 addQ(&h->cmpQ, c);
38658@@ -3444,17 +3444,17 @@ startio:
38659
38660 static inline unsigned long get_next_completion(ctlr_info_t *h)
38661 {
38662- return h->access.command_completed(h);
38663+ return h->access->command_completed(h);
38664 }
38665
38666 static inline int interrupt_pending(ctlr_info_t *h)
38667 {
38668- return h->access.intr_pending(h);
38669+ return h->access->intr_pending(h);
38670 }
38671
38672 static inline long interrupt_not_for_us(ctlr_info_t *h)
38673 {
38674- return ((h->access.intr_pending(h) == 0) ||
38675+ return ((h->access->intr_pending(h) == 0) ||
38676 (h->interrupts_enabled == 0));
38677 }
38678
38679@@ -3487,7 +3487,7 @@ static inline u32 next_command(ctlr_info_t *h)
38680 u32 a;
38681
38682 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
38683- return h->access.command_completed(h);
38684+ return h->access->command_completed(h);
38685
38686 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
38687 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
38688@@ -4044,7 +4044,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
38689 trans_support & CFGTBL_Trans_use_short_tags);
38690
38691 /* Change the access methods to the performant access methods */
38692- h->access = SA5_performant_access;
38693+ h->access = &SA5_performant_access;
38694 h->transMethod = CFGTBL_Trans_Performant;
38695
38696 return;
38697@@ -4318,7 +4318,7 @@ static int cciss_pci_init(ctlr_info_t *h)
38698 if (prod_index < 0)
38699 return -ENODEV;
38700 h->product_name = products[prod_index].product_name;
38701- h->access = *(products[prod_index].access);
38702+ h->access = products[prod_index].access;
38703
38704 if (cciss_board_disabled(h)) {
38705 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
38706@@ -5050,7 +5050,7 @@ reinit_after_soft_reset:
38707 }
38708
38709 /* make sure the board interrupts are off */
38710- h->access.set_intr_mask(h, CCISS_INTR_OFF);
38711+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
38712 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
38713 if (rc)
38714 goto clean2;
38715@@ -5100,7 +5100,7 @@ reinit_after_soft_reset:
38716 * fake ones to scoop up any residual completions.
38717 */
38718 spin_lock_irqsave(&h->lock, flags);
38719- h->access.set_intr_mask(h, CCISS_INTR_OFF);
38720+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
38721 spin_unlock_irqrestore(&h->lock, flags);
38722 free_irq(h->intr[h->intr_mode], h);
38723 rc = cciss_request_irq(h, cciss_msix_discard_completions,
38724@@ -5120,9 +5120,9 @@ reinit_after_soft_reset:
38725 dev_info(&h->pdev->dev, "Board READY.\n");
38726 dev_info(&h->pdev->dev,
38727 "Waiting for stale completions to drain.\n");
38728- h->access.set_intr_mask(h, CCISS_INTR_ON);
38729+ h->access->set_intr_mask(h, CCISS_INTR_ON);
38730 msleep(10000);
38731- h->access.set_intr_mask(h, CCISS_INTR_OFF);
38732+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
38733
38734 rc = controller_reset_failed(h->cfgtable);
38735 if (rc)
38736@@ -5145,7 +5145,7 @@ reinit_after_soft_reset:
38737 cciss_scsi_setup(h);
38738
38739 /* Turn the interrupts on so we can service requests */
38740- h->access.set_intr_mask(h, CCISS_INTR_ON);
38741+ h->access->set_intr_mask(h, CCISS_INTR_ON);
38742
38743 /* Get the firmware version */
38744 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
38745@@ -5217,7 +5217,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
38746 kfree(flush_buf);
38747 if (return_code != IO_OK)
38748 dev_warn(&h->pdev->dev, "Error flushing cache\n");
38749- h->access.set_intr_mask(h, CCISS_INTR_OFF);
38750+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
38751 free_irq(h->intr[h->intr_mode], h);
38752 }
38753
38754diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
38755index 7fda30e..2f27946 100644
38756--- a/drivers/block/cciss.h
38757+++ b/drivers/block/cciss.h
38758@@ -101,7 +101,7 @@ struct ctlr_info
38759 /* information about each logical volume */
38760 drive_info_struct *drv[CISS_MAX_LUN];
38761
38762- struct access_method access;
38763+ struct access_method *access;
38764
38765 /* queue and queue Info */
38766 struct list_head reqQ;
38767@@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
38768 }
38769
38770 static struct access_method SA5_access = {
38771- SA5_submit_command,
38772- SA5_intr_mask,
38773- SA5_fifo_full,
38774- SA5_intr_pending,
38775- SA5_completed,
38776+ .submit_command = SA5_submit_command,
38777+ .set_intr_mask = SA5_intr_mask,
38778+ .fifo_full = SA5_fifo_full,
38779+ .intr_pending = SA5_intr_pending,
38780+ .command_completed = SA5_completed,
38781 };
38782
38783 static struct access_method SA5B_access = {
38784- SA5_submit_command,
38785- SA5B_intr_mask,
38786- SA5_fifo_full,
38787- SA5B_intr_pending,
38788- SA5_completed,
38789+ .submit_command = SA5_submit_command,
38790+ .set_intr_mask = SA5B_intr_mask,
38791+ .fifo_full = SA5_fifo_full,
38792+ .intr_pending = SA5B_intr_pending,
38793+ .command_completed = SA5_completed,
38794 };
38795
38796 static struct access_method SA5_performant_access = {
38797- SA5_submit_command,
38798- SA5_performant_intr_mask,
38799- SA5_fifo_full,
38800- SA5_performant_intr_pending,
38801- SA5_performant_completed,
38802+ .submit_command = SA5_submit_command,
38803+ .set_intr_mask = SA5_performant_intr_mask,
38804+ .fifo_full = SA5_fifo_full,
38805+ .intr_pending = SA5_performant_intr_pending,
38806+ .command_completed = SA5_performant_completed,
38807 };
38808
38809 struct board_type {
38810diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
38811index 2b94403..fd6ad1f 100644
38812--- a/drivers/block/cpqarray.c
38813+++ b/drivers/block/cpqarray.c
38814@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
38815 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
38816 goto Enomem4;
38817 }
38818- hba[i]->access.set_intr_mask(hba[i], 0);
38819+ hba[i]->access->set_intr_mask(hba[i], 0);
38820 if (request_irq(hba[i]->intr, do_ida_intr,
38821 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
38822 {
38823@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
38824 add_timer(&hba[i]->timer);
38825
38826 /* Enable IRQ now that spinlock and rate limit timer are set up */
38827- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
38828+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
38829
38830 for(j=0; j<NWD; j++) {
38831 struct gendisk *disk = ida_gendisk[i][j];
38832@@ -694,7 +694,7 @@ DBGINFO(
38833 for(i=0; i<NR_PRODUCTS; i++) {
38834 if (board_id == products[i].board_id) {
38835 c->product_name = products[i].product_name;
38836- c->access = *(products[i].access);
38837+ c->access = products[i].access;
38838 break;
38839 }
38840 }
38841@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
38842 hba[ctlr]->intr = intr;
38843 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
38844 hba[ctlr]->product_name = products[j].product_name;
38845- hba[ctlr]->access = *(products[j].access);
38846+ hba[ctlr]->access = products[j].access;
38847 hba[ctlr]->ctlr = ctlr;
38848 hba[ctlr]->board_id = board_id;
38849 hba[ctlr]->pci_dev = NULL; /* not PCI */
38850@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
38851
38852 while((c = h->reqQ) != NULL) {
38853 /* Can't do anything if we're busy */
38854- if (h->access.fifo_full(h) == 0)
38855+ if (h->access->fifo_full(h) == 0)
38856 return;
38857
38858 /* Get the first entry from the request Q */
38859@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
38860 h->Qdepth--;
38861
38862 /* Tell the controller to do our bidding */
38863- h->access.submit_command(h, c);
38864+ h->access->submit_command(h, c);
38865
38866 /* Get onto the completion Q */
38867 addQ(&h->cmpQ, c);
38868@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38869 unsigned long flags;
38870 __u32 a,a1;
38871
38872- istat = h->access.intr_pending(h);
38873+ istat = h->access->intr_pending(h);
38874 /* Is this interrupt for us? */
38875 if (istat == 0)
38876 return IRQ_NONE;
38877@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38878 */
38879 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
38880 if (istat & FIFO_NOT_EMPTY) {
38881- while((a = h->access.command_completed(h))) {
38882+ while((a = h->access->command_completed(h))) {
38883 a1 = a; a &= ~3;
38884 if ((c = h->cmpQ) == NULL)
38885 {
38886@@ -1448,11 +1448,11 @@ static int sendcmd(
38887 /*
38888 * Disable interrupt
38889 */
38890- info_p->access.set_intr_mask(info_p, 0);
38891+ info_p->access->set_intr_mask(info_p, 0);
38892 /* Make sure there is room in the command FIFO */
38893 /* Actually it should be completely empty at this time. */
38894 for (i = 200000; i > 0; i--) {
38895- temp = info_p->access.fifo_full(info_p);
38896+ temp = info_p->access->fifo_full(info_p);
38897 if (temp != 0) {
38898 break;
38899 }
38900@@ -1465,7 +1465,7 @@ DBG(
38901 /*
38902 * Send the cmd
38903 */
38904- info_p->access.submit_command(info_p, c);
38905+ info_p->access->submit_command(info_p, c);
38906 complete = pollcomplete(ctlr);
38907
38908 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
38909@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
38910 * we check the new geometry. Then turn interrupts back on when
38911 * we're done.
38912 */
38913- host->access.set_intr_mask(host, 0);
38914+ host->access->set_intr_mask(host, 0);
38915 getgeometry(ctlr);
38916- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
38917+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
38918
38919 for(i=0; i<NWD; i++) {
38920 struct gendisk *disk = ida_gendisk[ctlr][i];
38921@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
38922 /* Wait (up to 2 seconds) for a command to complete */
38923
38924 for (i = 200000; i > 0; i--) {
38925- done = hba[ctlr]->access.command_completed(hba[ctlr]);
38926+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
38927 if (done == 0) {
38928 udelay(10); /* a short fixed delay */
38929 } else
38930diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
38931index be73e9d..7fbf140 100644
38932--- a/drivers/block/cpqarray.h
38933+++ b/drivers/block/cpqarray.h
38934@@ -99,7 +99,7 @@ struct ctlr_info {
38935 drv_info_t drv[NWD];
38936 struct proc_dir_entry *proc;
38937
38938- struct access_method access;
38939+ struct access_method *access;
38940
38941 cmdlist_t *reqQ;
38942 cmdlist_t *cmpQ;
38943diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
38944index 426c97a..8c58607 100644
38945--- a/drivers/block/drbd/drbd_bitmap.c
38946+++ b/drivers/block/drbd/drbd_bitmap.c
38947@@ -1036,7 +1036,7 @@ static void bm_page_io_async(struct drbd_bm_aio_ctx *ctx, int page_nr) __must_ho
38948 submit_bio(rw, bio);
38949 /* this should not count as user activity and cause the
38950 * resync to throttle -- see drbd_rs_should_slow_down(). */
38951- atomic_add(len >> 9, &device->rs_sect_ev);
38952+ atomic_add_unchecked(len >> 9, &device->rs_sect_ev);
38953 }
38954 }
38955
38956diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
38957index 1a00001..c0d4253 100644
38958--- a/drivers/block/drbd/drbd_int.h
38959+++ b/drivers/block/drbd/drbd_int.h
38960@@ -387,7 +387,7 @@ struct drbd_epoch {
38961 struct drbd_connection *connection;
38962 struct list_head list;
38963 unsigned int barrier_nr;
38964- atomic_t epoch_size; /* increased on every request added. */
38965+ atomic_unchecked_t epoch_size; /* increased on every request added. */
38966 atomic_t active; /* increased on every req. added, and dec on every finished. */
38967 unsigned long flags;
38968 };
38969@@ -948,7 +948,7 @@ struct drbd_device {
38970 unsigned int al_tr_number;
38971 int al_tr_cycle;
38972 wait_queue_head_t seq_wait;
38973- atomic_t packet_seq;
38974+ atomic_unchecked_t packet_seq;
38975 unsigned int peer_seq;
38976 spinlock_t peer_seq_lock;
38977 unsigned long comm_bm_set; /* communicated number of set bits. */
38978@@ -957,8 +957,8 @@ struct drbd_device {
38979 struct mutex own_state_mutex;
38980 struct mutex *state_mutex; /* either own_state_mutex or first_peer_device(device)->connection->cstate_mutex */
38981 char congestion_reason; /* Why we where congested... */
38982- atomic_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38983- atomic_t rs_sect_ev; /* for submitted resync data rate, both */
38984+ atomic_unchecked_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38985+ atomic_unchecked_t rs_sect_ev; /* for submitted resync data rate, both */
38986 int rs_last_sect_ev; /* counter to compare with */
38987 int rs_last_events; /* counter of read or write "events" (unit sectors)
38988 * on the lower level device when we last looked. */
38989@@ -1569,7 +1569,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
38990 char __user *uoptval;
38991 int err;
38992
38993- uoptval = (char __user __force *)optval;
38994+ uoptval = (char __force_user *)optval;
38995
38996 set_fs(KERNEL_DS);
38997 if (level == SOL_SOCKET)
38998diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
38999index 04a14e0..5b8f0aa 100644
39000--- a/drivers/block/drbd/drbd_interval.c
39001+++ b/drivers/block/drbd/drbd_interval.c
39002@@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
39003 }
39004
39005 static const struct rb_augment_callbacks augment_callbacks = {
39006- augment_propagate,
39007- augment_copy,
39008- augment_rotate,
39009+ .propagate = augment_propagate,
39010+ .copy = augment_copy,
39011+ .rotate = augment_rotate,
39012 };
39013
39014 /**
39015diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
39016index 9b465bb..00034ecf 100644
39017--- a/drivers/block/drbd/drbd_main.c
39018+++ b/drivers/block/drbd/drbd_main.c
39019@@ -1328,7 +1328,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
39020 p->sector = sector;
39021 p->block_id = block_id;
39022 p->blksize = blksize;
39023- p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
39024+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
39025 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
39026 }
39027
39028@@ -1634,7 +1634,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
39029 return -EIO;
39030 p->sector = cpu_to_be64(req->i.sector);
39031 p->block_id = (unsigned long)req;
39032- p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
39033+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
39034 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
39035 if (device->state.conn >= C_SYNC_SOURCE &&
39036 device->state.conn <= C_PAUSED_SYNC_T)
39037@@ -1915,8 +1915,8 @@ void drbd_init_set_defaults(struct drbd_device *device)
39038 atomic_set(&device->unacked_cnt, 0);
39039 atomic_set(&device->local_cnt, 0);
39040 atomic_set(&device->pp_in_use_by_net, 0);
39041- atomic_set(&device->rs_sect_in, 0);
39042- atomic_set(&device->rs_sect_ev, 0);
39043+ atomic_set_unchecked(&device->rs_sect_in, 0);
39044+ atomic_set_unchecked(&device->rs_sect_ev, 0);
39045 atomic_set(&device->ap_in_flight, 0);
39046 atomic_set(&device->md_io.in_use, 0);
39047
39048@@ -2688,8 +2688,8 @@ void drbd_destroy_connection(struct kref *kref)
39049 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
39050 struct drbd_resource *resource = connection->resource;
39051
39052- if (atomic_read(&connection->current_epoch->epoch_size) != 0)
39053- drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
39054+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
39055+ drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
39056 kfree(connection->current_epoch);
39057
39058 idr_destroy(&connection->peer_devices);
39059diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
39060index 1cd47df..57c53c0 100644
39061--- a/drivers/block/drbd/drbd_nl.c
39062+++ b/drivers/block/drbd/drbd_nl.c
39063@@ -3645,13 +3645,13 @@ finish:
39064
39065 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
39066 {
39067- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
39068+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
39069 struct sk_buff *msg;
39070 struct drbd_genlmsghdr *d_out;
39071 unsigned seq;
39072 int err = -ENOMEM;
39073
39074- seq = atomic_inc_return(&drbd_genl_seq);
39075+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
39076 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
39077 if (!msg)
39078 goto failed;
39079diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
39080index 9342b8d..b6a6825 100644
39081--- a/drivers/block/drbd/drbd_receiver.c
39082+++ b/drivers/block/drbd/drbd_receiver.c
39083@@ -870,7 +870,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
39084 struct drbd_device *device = peer_device->device;
39085 int err;
39086
39087- atomic_set(&device->packet_seq, 0);
39088+ atomic_set_unchecked(&device->packet_seq, 0);
39089 device->peer_seq = 0;
39090
39091 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
39092@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
39093 do {
39094 next_epoch = NULL;
39095
39096- epoch_size = atomic_read(&epoch->epoch_size);
39097+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
39098
39099 switch (ev & ~EV_CLEANUP) {
39100 case EV_PUT:
39101@@ -1273,7 +1273,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
39102 rv = FE_DESTROYED;
39103 } else {
39104 epoch->flags = 0;
39105- atomic_set(&epoch->epoch_size, 0);
39106+ atomic_set_unchecked(&epoch->epoch_size, 0);
39107 /* atomic_set(&epoch->active, 0); is already zero */
39108 if (rv == FE_STILL_LIVE)
39109 rv = FE_RECYCLED;
39110@@ -1550,7 +1550,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
39111 conn_wait_active_ee_empty(connection);
39112 drbd_flush(connection);
39113
39114- if (atomic_read(&connection->current_epoch->epoch_size)) {
39115+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
39116 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
39117 if (epoch)
39118 break;
39119@@ -1564,11 +1564,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
39120 }
39121
39122 epoch->flags = 0;
39123- atomic_set(&epoch->epoch_size, 0);
39124+ atomic_set_unchecked(&epoch->epoch_size, 0);
39125 atomic_set(&epoch->active, 0);
39126
39127 spin_lock(&connection->epoch_lock);
39128- if (atomic_read(&connection->current_epoch->epoch_size)) {
39129+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
39130 list_add(&epoch->list, &connection->current_epoch->list);
39131 connection->current_epoch = epoch;
39132 connection->epochs++;
39133@@ -1802,7 +1802,7 @@ static int recv_resync_read(struct drbd_peer_device *peer_device, sector_t secto
39134 list_add_tail(&peer_req->w.list, &device->sync_ee);
39135 spin_unlock_irq(&device->resource->req_lock);
39136
39137- atomic_add(pi->size >> 9, &device->rs_sect_ev);
39138+ atomic_add_unchecked(pi->size >> 9, &device->rs_sect_ev);
39139 if (drbd_submit_peer_request(device, peer_req, WRITE, DRBD_FAULT_RS_WR) == 0)
39140 return 0;
39141
39142@@ -1900,7 +1900,7 @@ static int receive_RSDataReply(struct drbd_connection *connection, struct packet
39143 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
39144 }
39145
39146- atomic_add(pi->size >> 9, &device->rs_sect_in);
39147+ atomic_add_unchecked(pi->size >> 9, &device->rs_sect_in);
39148
39149 return err;
39150 }
39151@@ -2290,7 +2290,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
39152
39153 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
39154 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
39155- atomic_inc(&connection->current_epoch->epoch_size);
39156+ atomic_inc_unchecked(&connection->current_epoch->epoch_size);
39157 err2 = drbd_drain_block(peer_device, pi->size);
39158 if (!err)
39159 err = err2;
39160@@ -2334,7 +2334,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
39161
39162 spin_lock(&connection->epoch_lock);
39163 peer_req->epoch = connection->current_epoch;
39164- atomic_inc(&peer_req->epoch->epoch_size);
39165+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
39166 atomic_inc(&peer_req->epoch->active);
39167 spin_unlock(&connection->epoch_lock);
39168
39169@@ -2479,7 +2479,7 @@ bool drbd_rs_c_min_rate_throttle(struct drbd_device *device)
39170
39171 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
39172 (int)part_stat_read(&disk->part0, sectors[1]) -
39173- atomic_read(&device->rs_sect_ev);
39174+ atomic_read_unchecked(&device->rs_sect_ev);
39175
39176 if (atomic_read(&device->ap_actlog_cnt)
39177 || !device->rs_last_events || curr_events - device->rs_last_events > 64) {
39178@@ -2618,7 +2618,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
39179 device->use_csums = true;
39180 } else if (pi->cmd == P_OV_REPLY) {
39181 /* track progress, we may need to throttle */
39182- atomic_add(size >> 9, &device->rs_sect_in);
39183+ atomic_add_unchecked(size >> 9, &device->rs_sect_in);
39184 peer_req->w.cb = w_e_end_ov_reply;
39185 dec_rs_pending(device);
39186 /* drbd_rs_begin_io done when we sent this request,
39187@@ -2691,7 +2691,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
39188 goto out_free_e;
39189
39190 submit_for_resync:
39191- atomic_add(size >> 9, &device->rs_sect_ev);
39192+ atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
39193
39194 submit:
39195 update_receiver_timing_details(connection, drbd_submit_peer_request);
39196@@ -4564,7 +4564,7 @@ struct data_cmd {
39197 int expect_payload;
39198 size_t pkt_size;
39199 int (*fn)(struct drbd_connection *, struct packet_info *);
39200-};
39201+} __do_const;
39202
39203 static struct data_cmd drbd_cmd_handler[] = {
39204 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
39205@@ -4678,7 +4678,7 @@ static void conn_disconnect(struct drbd_connection *connection)
39206 if (!list_empty(&connection->current_epoch->list))
39207 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
39208 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
39209- atomic_set(&connection->current_epoch->epoch_size, 0);
39210+ atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
39211 connection->send.seen_any_write_yet = false;
39212
39213 drbd_info(connection, "Connection closed\n");
39214@@ -5182,7 +5182,7 @@ static int got_IsInSync(struct drbd_connection *connection, struct packet_info *
39215 put_ldev(device);
39216 }
39217 dec_rs_pending(device);
39218- atomic_add(blksize >> 9, &device->rs_sect_in);
39219+ atomic_add_unchecked(blksize >> 9, &device->rs_sect_in);
39220
39221 return 0;
39222 }
39223@@ -5470,7 +5470,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
39224 struct asender_cmd {
39225 size_t pkt_size;
39226 int (*fn)(struct drbd_connection *connection, struct packet_info *);
39227-};
39228+} __do_const;
39229
39230 static struct asender_cmd asender_tbl[] = {
39231 [P_PING] = { 0, got_Ping },
39232diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c
39233index 50776b3..1477c3f 100644
39234--- a/drivers/block/drbd/drbd_worker.c
39235+++ b/drivers/block/drbd/drbd_worker.c
39236@@ -408,7 +408,7 @@ static int read_for_csum(struct drbd_peer_device *peer_device, sector_t sector,
39237 list_add_tail(&peer_req->w.list, &device->read_ee);
39238 spin_unlock_irq(&device->resource->req_lock);
39239
39240- atomic_add(size >> 9, &device->rs_sect_ev);
39241+ atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
39242 if (drbd_submit_peer_request(device, peer_req, READ, DRBD_FAULT_RS_RD) == 0)
39243 return 0;
39244
39245@@ -553,7 +553,7 @@ static int drbd_rs_number_requests(struct drbd_device *device)
39246 unsigned int sect_in; /* Number of sectors that came in since the last turn */
39247 int number, mxb;
39248
39249- sect_in = atomic_xchg(&device->rs_sect_in, 0);
39250+ sect_in = atomic_xchg_unchecked(&device->rs_sect_in, 0);
39251 device->rs_in_flight -= sect_in;
39252
39253 rcu_read_lock();
39254@@ -1594,8 +1594,8 @@ void drbd_rs_controller_reset(struct drbd_device *device)
39255 {
39256 struct fifo_buffer *plan;
39257
39258- atomic_set(&device->rs_sect_in, 0);
39259- atomic_set(&device->rs_sect_ev, 0);
39260+ atomic_set_unchecked(&device->rs_sect_in, 0);
39261+ atomic_set_unchecked(&device->rs_sect_ev, 0);
39262 device->rs_in_flight = 0;
39263
39264 /* Updating the RCU protected object in place is necessary since
39265diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39266index 6cb1beb..bf490f7 100644
39267--- a/drivers/block/loop.c
39268+++ b/drivers/block/loop.c
39269@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
39270
39271 file_start_write(file);
39272 set_fs(get_ds());
39273- bw = file->f_op->write(file, buf, len, &pos);
39274+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
39275 set_fs(old_fs);
39276 file_end_write(file);
39277 if (likely(bw == len))
39278diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
39279index 02351e2..a9ea617 100644
39280--- a/drivers/block/nvme-core.c
39281+++ b/drivers/block/nvme-core.c
39282@@ -73,7 +73,6 @@ static LIST_HEAD(dev_list);
39283 static struct task_struct *nvme_thread;
39284 static struct workqueue_struct *nvme_workq;
39285 static wait_queue_head_t nvme_kthread_wait;
39286-static struct notifier_block nvme_nb;
39287
39288 static void nvme_reset_failed_dev(struct work_struct *ws);
39289
39290@@ -2925,6 +2924,10 @@ static struct pci_driver nvme_driver = {
39291 .err_handler = &nvme_err_handler,
39292 };
39293
39294+static struct notifier_block nvme_nb = {
39295+ .notifier_call = &nvme_cpu_notify,
39296+};
39297+
39298 static int __init nvme_init(void)
39299 {
39300 int result;
39301@@ -2941,7 +2944,6 @@ static int __init nvme_init(void)
39302 else if (result > 0)
39303 nvme_major = result;
39304
39305- nvme_nb.notifier_call = &nvme_cpu_notify;
39306 result = register_hotcpu_notifier(&nvme_nb);
39307 if (result)
39308 goto unregister_blkdev;
39309diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
39310index 758ac44..58087fd 100644
39311--- a/drivers/block/pktcdvd.c
39312+++ b/drivers/block/pktcdvd.c
39313@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
39314
39315 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
39316 {
39317- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
39318+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
39319 }
39320
39321 /*
39322@@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
39323 return -EROFS;
39324 }
39325 pd->settings.fp = ti.fp;
39326- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
39327+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
39328
39329 if (ti.nwa_v) {
39330 pd->nwa = be32_to_cpu(ti.next_writable);
39331diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
39332index e5565fb..71be10b4 100644
39333--- a/drivers/block/smart1,2.h
39334+++ b/drivers/block/smart1,2.h
39335@@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
39336 }
39337
39338 static struct access_method smart4_access = {
39339- smart4_submit_command,
39340- smart4_intr_mask,
39341- smart4_fifo_full,
39342- smart4_intr_pending,
39343- smart4_completed,
39344+ .submit_command = smart4_submit_command,
39345+ .set_intr_mask = smart4_intr_mask,
39346+ .fifo_full = smart4_fifo_full,
39347+ .intr_pending = smart4_intr_pending,
39348+ .command_completed = smart4_completed,
39349 };
39350
39351 /*
39352@@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
39353 }
39354
39355 static struct access_method smart2_access = {
39356- smart2_submit_command,
39357- smart2_intr_mask,
39358- smart2_fifo_full,
39359- smart2_intr_pending,
39360- smart2_completed,
39361+ .submit_command = smart2_submit_command,
39362+ .set_intr_mask = smart2_intr_mask,
39363+ .fifo_full = smart2_fifo_full,
39364+ .intr_pending = smart2_intr_pending,
39365+ .command_completed = smart2_completed,
39366 };
39367
39368 /*
39369@@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
39370 }
39371
39372 static struct access_method smart2e_access = {
39373- smart2e_submit_command,
39374- smart2e_intr_mask,
39375- smart2e_fifo_full,
39376- smart2e_intr_pending,
39377- smart2e_completed,
39378+ .submit_command = smart2e_submit_command,
39379+ .set_intr_mask = smart2e_intr_mask,
39380+ .fifo_full = smart2e_fifo_full,
39381+ .intr_pending = smart2e_intr_pending,
39382+ .command_completed = smart2e_completed,
39383 };
39384
39385 /*
39386@@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
39387 }
39388
39389 static struct access_method smart1_access = {
39390- smart1_submit_command,
39391- smart1_intr_mask,
39392- smart1_fifo_full,
39393- smart1_intr_pending,
39394- smart1_completed,
39395+ .submit_command = smart1_submit_command,
39396+ .set_intr_mask = smart1_intr_mask,
39397+ .fifo_full = smart1_fifo_full,
39398+ .intr_pending = smart1_intr_pending,
39399+ .command_completed = smart1_completed,
39400 };
39401diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
39402index f038dba..bb74c08 100644
39403--- a/drivers/bluetooth/btwilink.c
39404+++ b/drivers/bluetooth/btwilink.c
39405@@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
39406
39407 static int bt_ti_probe(struct platform_device *pdev)
39408 {
39409- static struct ti_st *hst;
39410+ struct ti_st *hst;
39411 struct hci_dev *hdev;
39412 int err;
39413
39414diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
39415index 898b84b..86f74b9 100644
39416--- a/drivers/cdrom/cdrom.c
39417+++ b/drivers/cdrom/cdrom.c
39418@@ -610,7 +610,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
39419 ENSURE(reset, CDC_RESET);
39420 ENSURE(generic_packet, CDC_GENERIC_PACKET);
39421 cdi->mc_flags = 0;
39422- cdo->n_minors = 0;
39423 cdi->options = CDO_USE_FFLAGS;
39424
39425 if (autoclose == 1 && CDROM_CAN(CDC_CLOSE_TRAY))
39426@@ -630,8 +629,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
39427 else
39428 cdi->cdda_method = CDDA_OLD;
39429
39430- if (!cdo->generic_packet)
39431- cdo->generic_packet = cdrom_dummy_generic_packet;
39432+ if (!cdo->generic_packet) {
39433+ pax_open_kernel();
39434+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
39435+ pax_close_kernel();
39436+ }
39437
39438 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
39439 mutex_lock(&cdrom_mutex);
39440@@ -652,7 +654,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
39441 if (cdi->exit)
39442 cdi->exit(cdi);
39443
39444- cdi->ops->n_minors--;
39445 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
39446 }
39447
39448@@ -2126,7 +2127,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
39449 */
39450 nr = nframes;
39451 do {
39452- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
39453+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
39454 if (cgc.buffer)
39455 break;
39456
39457@@ -3434,7 +3435,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
39458 struct cdrom_device_info *cdi;
39459 int ret;
39460
39461- ret = scnprintf(info + *pos, max_size - *pos, header);
39462+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
39463 if (!ret)
39464 return 1;
39465
39466diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
39467index 584bc31..e64a12c 100644
39468--- a/drivers/cdrom/gdrom.c
39469+++ b/drivers/cdrom/gdrom.c
39470@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
39471 .audio_ioctl = gdrom_audio_ioctl,
39472 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
39473 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
39474- .n_minors = 1,
39475 };
39476
39477 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
39478diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
39479index 6e9f74a..50c7cea 100644
39480--- a/drivers/char/Kconfig
39481+++ b/drivers/char/Kconfig
39482@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
39483
39484 config DEVKMEM
39485 bool "/dev/kmem virtual device support"
39486- default y
39487+ default n
39488+ depends on !GRKERNSEC_KMEM
39489 help
39490 Say Y here if you want to support the /dev/kmem device. The
39491 /dev/kmem device is rarely used, but can be used for certain
39492@@ -577,6 +578,7 @@ config DEVPORT
39493 bool
39494 depends on !M68K
39495 depends on ISA || PCI
39496+ depends on !GRKERNSEC_KMEM
39497 default y
39498
39499 source "drivers/s390/char/Kconfig"
39500diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
39501index a48e05b..6bac831 100644
39502--- a/drivers/char/agp/compat_ioctl.c
39503+++ b/drivers/char/agp/compat_ioctl.c
39504@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
39505 return -ENOMEM;
39506 }
39507
39508- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
39509+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
39510 sizeof(*usegment) * ureserve.seg_count)) {
39511 kfree(usegment);
39512 kfree(ksegment);
39513diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
39514index 09f17eb..8531d2f 100644
39515--- a/drivers/char/agp/frontend.c
39516+++ b/drivers/char/agp/frontend.c
39517@@ -806,7 +806,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
39518 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
39519 return -EFAULT;
39520
39521- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
39522+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
39523 return -EFAULT;
39524
39525 client = agp_find_client_by_pid(reserve.pid);
39526@@ -836,7 +836,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
39527 if (segment == NULL)
39528 return -ENOMEM;
39529
39530- if (copy_from_user(segment, (void __user *) reserve.seg_list,
39531+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
39532 sizeof(struct agp_segment) * reserve.seg_count)) {
39533 kfree(segment);
39534 return -EFAULT;
39535diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
39536index 4f94375..413694e 100644
39537--- a/drivers/char/genrtc.c
39538+++ b/drivers/char/genrtc.c
39539@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
39540 switch (cmd) {
39541
39542 case RTC_PLL_GET:
39543+ memset(&pll, 0, sizeof(pll));
39544 if (get_rtc_pll(&pll))
39545 return -EINVAL;
39546 else
39547diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
39548index d5d4cd8..22d561d 100644
39549--- a/drivers/char/hpet.c
39550+++ b/drivers/char/hpet.c
39551@@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
39552 }
39553
39554 static int
39555-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
39556+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
39557 struct hpet_info *info)
39558 {
39559 struct hpet_timer __iomem *timer;
39560diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
39561index 86fe45c..c0ea948 100644
39562--- a/drivers/char/hw_random/intel-rng.c
39563+++ b/drivers/char/hw_random/intel-rng.c
39564@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
39565
39566 if (no_fwh_detect)
39567 return -ENODEV;
39568- printk(warning);
39569+ printk("%s", warning);
39570 return -EBUSY;
39571 }
39572
39573diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
39574index e6db938..835e3a2 100644
39575--- a/drivers/char/ipmi/ipmi_msghandler.c
39576+++ b/drivers/char/ipmi/ipmi_msghandler.c
39577@@ -438,7 +438,7 @@ struct ipmi_smi {
39578 struct proc_dir_entry *proc_dir;
39579 char proc_dir_name[10];
39580
39581- atomic_t stats[IPMI_NUM_STATS];
39582+ atomic_unchecked_t stats[IPMI_NUM_STATS];
39583
39584 /*
39585 * run_to_completion duplicate of smb_info, smi_info
39586@@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
39587 static DEFINE_MUTEX(smi_watchers_mutex);
39588
39589 #define ipmi_inc_stat(intf, stat) \
39590- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
39591+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
39592 #define ipmi_get_stat(intf, stat) \
39593- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
39594+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
39595
39596 static int is_lan_addr(struct ipmi_addr *addr)
39597 {
39598@@ -2926,7 +2926,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
39599 INIT_LIST_HEAD(&intf->cmd_rcvrs);
39600 init_waitqueue_head(&intf->waitq);
39601 for (i = 0; i < IPMI_NUM_STATS; i++)
39602- atomic_set(&intf->stats[i], 0);
39603+ atomic_set_unchecked(&intf->stats[i], 0);
39604
39605 intf->proc_dir = NULL;
39606
39607diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
39608index 5d66568..c9d93c3 100644
39609--- a/drivers/char/ipmi/ipmi_si_intf.c
39610+++ b/drivers/char/ipmi/ipmi_si_intf.c
39611@@ -285,7 +285,7 @@ struct smi_info {
39612 unsigned char slave_addr;
39613
39614 /* Counters and things for the proc filesystem. */
39615- atomic_t stats[SI_NUM_STATS];
39616+ atomic_unchecked_t stats[SI_NUM_STATS];
39617
39618 struct task_struct *thread;
39619
39620@@ -294,9 +294,9 @@ struct smi_info {
39621 };
39622
39623 #define smi_inc_stat(smi, stat) \
39624- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
39625+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
39626 #define smi_get_stat(smi, stat) \
39627- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
39628+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
39629
39630 #define SI_MAX_PARMS 4
39631
39632@@ -3374,7 +3374,7 @@ static int try_smi_init(struct smi_info *new_smi)
39633 atomic_set(&new_smi->req_events, 0);
39634 new_smi->run_to_completion = false;
39635 for (i = 0; i < SI_NUM_STATS; i++)
39636- atomic_set(&new_smi->stats[i], 0);
39637+ atomic_set_unchecked(&new_smi->stats[i], 0);
39638
39639 new_smi->interrupt_disabled = true;
39640 atomic_set(&new_smi->stop_operation, 0);
39641diff --git a/drivers/char/mem.c b/drivers/char/mem.c
39642index 917403f..dddd899 100644
39643--- a/drivers/char/mem.c
39644+++ b/drivers/char/mem.c
39645@@ -18,6 +18,7 @@
39646 #include <linux/raw.h>
39647 #include <linux/tty.h>
39648 #include <linux/capability.h>
39649+#include <linux/security.h>
39650 #include <linux/ptrace.h>
39651 #include <linux/device.h>
39652 #include <linux/highmem.h>
39653@@ -36,6 +37,10 @@
39654
39655 #define DEVPORT_MINOR 4
39656
39657+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
39658+extern const struct file_operations grsec_fops;
39659+#endif
39660+
39661 static inline unsigned long size_inside_page(unsigned long start,
39662 unsigned long size)
39663 {
39664@@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39665
39666 while (cursor < to) {
39667 if (!devmem_is_allowed(pfn)) {
39668+#ifdef CONFIG_GRKERNSEC_KMEM
39669+ gr_handle_mem_readwrite(from, to);
39670+#else
39671 printk(KERN_INFO
39672 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
39673 current->comm, from, to);
39674+#endif
39675 return 0;
39676 }
39677 cursor += PAGE_SIZE;
39678@@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39679 }
39680 return 1;
39681 }
39682+#elif defined(CONFIG_GRKERNSEC_KMEM)
39683+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39684+{
39685+ return 0;
39686+}
39687 #else
39688 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39689 {
39690@@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
39691
39692 while (count > 0) {
39693 unsigned long remaining;
39694+ char *temp;
39695
39696 sz = size_inside_page(p, count);
39697
39698@@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
39699 if (!ptr)
39700 return -EFAULT;
39701
39702- remaining = copy_to_user(buf, ptr, sz);
39703+#ifdef CONFIG_PAX_USERCOPY
39704+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
39705+ if (!temp) {
39706+ unxlate_dev_mem_ptr(p, ptr);
39707+ return -ENOMEM;
39708+ }
39709+ memcpy(temp, ptr, sz);
39710+#else
39711+ temp = ptr;
39712+#endif
39713+
39714+ remaining = copy_to_user(buf, temp, sz);
39715+
39716+#ifdef CONFIG_PAX_USERCOPY
39717+ kfree(temp);
39718+#endif
39719+
39720 unxlate_dev_mem_ptr(p, ptr);
39721 if (remaining)
39722 return -EFAULT;
39723@@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
39724 size_t count, loff_t *ppos)
39725 {
39726 unsigned long p = *ppos;
39727- ssize_t low_count, read, sz;
39728+ ssize_t low_count, read, sz, err = 0;
39729 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
39730- int err = 0;
39731
39732 read = 0;
39733 if (p < (unsigned long) high_memory) {
39734@@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
39735 }
39736 #endif
39737 while (low_count > 0) {
39738+ char *temp;
39739+
39740 sz = size_inside_page(p, low_count);
39741
39742 /*
39743@@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
39744 */
39745 kbuf = xlate_dev_kmem_ptr((char *)p);
39746
39747- if (copy_to_user(buf, kbuf, sz))
39748+#ifdef CONFIG_PAX_USERCOPY
39749+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
39750+ if (!temp)
39751+ return -ENOMEM;
39752+ memcpy(temp, kbuf, sz);
39753+#else
39754+ temp = kbuf;
39755+#endif
39756+
39757+ err = copy_to_user(buf, temp, sz);
39758+
39759+#ifdef CONFIG_PAX_USERCOPY
39760+ kfree(temp);
39761+#endif
39762+
39763+ if (err)
39764 return -EFAULT;
39765 buf += sz;
39766 p += sz;
39767@@ -827,6 +874,9 @@ static const struct memdev {
39768 #ifdef CONFIG_PRINTK
39769 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
39770 #endif
39771+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
39772+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
39773+#endif
39774 };
39775
39776 static int memory_open(struct inode *inode, struct file *filp)
39777@@ -898,7 +948,7 @@ static int __init chr_dev_init(void)
39778 continue;
39779
39780 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
39781- NULL, devlist[minor].name);
39782+ NULL, "%s", devlist[minor].name);
39783 }
39784
39785 return tty_init();
39786diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
39787index 9df78e2..01ba9ae 100644
39788--- a/drivers/char/nvram.c
39789+++ b/drivers/char/nvram.c
39790@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
39791
39792 spin_unlock_irq(&rtc_lock);
39793
39794- if (copy_to_user(buf, contents, tmp - contents))
39795+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
39796 return -EFAULT;
39797
39798 *ppos = i;
39799diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
39800index 0ea9986..e7b07e4 100644
39801--- a/drivers/char/pcmcia/synclink_cs.c
39802+++ b/drivers/char/pcmcia/synclink_cs.c
39803@@ -2345,7 +2345,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
39804
39805 if (debug_level >= DEBUG_LEVEL_INFO)
39806 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
39807- __FILE__, __LINE__, info->device_name, port->count);
39808+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
39809
39810 if (tty_port_close_start(port, tty, filp) == 0)
39811 goto cleanup;
39812@@ -2363,7 +2363,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
39813 cleanup:
39814 if (debug_level >= DEBUG_LEVEL_INFO)
39815 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
39816- tty->driver->name, port->count);
39817+ tty->driver->name, atomic_read(&port->count));
39818 }
39819
39820 /* Wait until the transmitter is empty.
39821@@ -2505,7 +2505,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
39822
39823 if (debug_level >= DEBUG_LEVEL_INFO)
39824 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
39825- __FILE__, __LINE__, tty->driver->name, port->count);
39826+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
39827
39828 /* If port is closing, signal caller to try again */
39829 if (port->flags & ASYNC_CLOSING){
39830@@ -2525,11 +2525,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
39831 goto cleanup;
39832 }
39833 spin_lock(&port->lock);
39834- port->count++;
39835+ atomic_inc(&port->count);
39836 spin_unlock(&port->lock);
39837 spin_unlock_irqrestore(&info->netlock, flags);
39838
39839- if (port->count == 1) {
39840+ if (atomic_read(&port->count) == 1) {
39841 /* 1st open on this device, init hardware */
39842 retval = startup(info, tty);
39843 if (retval < 0)
39844@@ -3918,7 +3918,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
39845 unsigned short new_crctype;
39846
39847 /* return error if TTY interface open */
39848- if (info->port.count)
39849+ if (atomic_read(&info->port.count))
39850 return -EBUSY;
39851
39852 switch (encoding)
39853@@ -4022,7 +4022,7 @@ static int hdlcdev_open(struct net_device *dev)
39854
39855 /* arbitrate between network and tty opens */
39856 spin_lock_irqsave(&info->netlock, flags);
39857- if (info->port.count != 0 || info->netcount != 0) {
39858+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
39859 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
39860 spin_unlock_irqrestore(&info->netlock, flags);
39861 return -EBUSY;
39862@@ -4112,7 +4112,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39863 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
39864
39865 /* return error if TTY interface open */
39866- if (info->port.count)
39867+ if (atomic_read(&info->port.count))
39868 return -EBUSY;
39869
39870 if (cmd != SIOCWANDEV)
39871diff --git a/drivers/char/random.c b/drivers/char/random.c
39872index 8c86a95..7c499f3 100644
39873--- a/drivers/char/random.c
39874+++ b/drivers/char/random.c
39875@@ -289,9 +289,6 @@
39876 /*
39877 * To allow fractional bits to be tracked, the entropy_count field is
39878 * denominated in units of 1/8th bits.
39879- *
39880- * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
39881- * credit_entropy_bits() needs to be 64 bits wide.
39882 */
39883 #define ENTROPY_SHIFT 3
39884 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
39885@@ -439,9 +436,9 @@ struct entropy_store {
39886 };
39887
39888 static void push_to_pool(struct work_struct *work);
39889-static __u32 input_pool_data[INPUT_POOL_WORDS];
39890-static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
39891-static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
39892+static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
39893+static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39894+static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39895
39896 static struct entropy_store input_pool = {
39897 .poolinfo = &poolinfo_table[0],
39898@@ -635,7 +632,7 @@ retry:
39899 /* The +2 corresponds to the /4 in the denominator */
39900
39901 do {
39902- unsigned int anfrac = min(pnfrac, pool_size/2);
39903+ u64 anfrac = min(pnfrac, pool_size/2);
39904 unsigned int add =
39905 ((pool_size - entropy_count)*anfrac*3) >> s;
39906
39907@@ -1207,7 +1204,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
39908
39909 extract_buf(r, tmp);
39910 i = min_t(int, nbytes, EXTRACT_SIZE);
39911- if (copy_to_user(buf, tmp, i)) {
39912+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
39913 ret = -EFAULT;
39914 break;
39915 }
39916@@ -1590,7 +1587,7 @@ static char sysctl_bootid[16];
39917 static int proc_do_uuid(struct ctl_table *table, int write,
39918 void __user *buffer, size_t *lenp, loff_t *ppos)
39919 {
39920- struct ctl_table fake_table;
39921+ ctl_table_no_const fake_table;
39922 unsigned char buf[64], tmp_uuid[16], *uuid;
39923
39924 uuid = table->data;
39925@@ -1620,7 +1617,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
39926 static int proc_do_entropy(struct ctl_table *table, int write,
39927 void __user *buffer, size_t *lenp, loff_t *ppos)
39928 {
39929- struct ctl_table fake_table;
39930+ ctl_table_no_const fake_table;
39931 int entropy_count;
39932
39933 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
39934diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
39935index 7cc1fe22..b602d6b 100644
39936--- a/drivers/char/sonypi.c
39937+++ b/drivers/char/sonypi.c
39938@@ -54,6 +54,7 @@
39939
39940 #include <asm/uaccess.h>
39941 #include <asm/io.h>
39942+#include <asm/local.h>
39943
39944 #include <linux/sonypi.h>
39945
39946@@ -490,7 +491,7 @@ static struct sonypi_device {
39947 spinlock_t fifo_lock;
39948 wait_queue_head_t fifo_proc_list;
39949 struct fasync_struct *fifo_async;
39950- int open_count;
39951+ local_t open_count;
39952 int model;
39953 struct input_dev *input_jog_dev;
39954 struct input_dev *input_key_dev;
39955@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
39956 static int sonypi_misc_release(struct inode *inode, struct file *file)
39957 {
39958 mutex_lock(&sonypi_device.lock);
39959- sonypi_device.open_count--;
39960+ local_dec(&sonypi_device.open_count);
39961 mutex_unlock(&sonypi_device.lock);
39962 return 0;
39963 }
39964@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
39965 {
39966 mutex_lock(&sonypi_device.lock);
39967 /* Flush input queue on first open */
39968- if (!sonypi_device.open_count)
39969+ if (!local_read(&sonypi_device.open_count))
39970 kfifo_reset(&sonypi_device.fifo);
39971- sonypi_device.open_count++;
39972+ local_inc(&sonypi_device.open_count);
39973 mutex_unlock(&sonypi_device.lock);
39974
39975 return 0;
39976diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
39977index 565a947..dcdc06e 100644
39978--- a/drivers/char/tpm/tpm_acpi.c
39979+++ b/drivers/char/tpm/tpm_acpi.c
39980@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
39981 virt = acpi_os_map_iomem(start, len);
39982 if (!virt) {
39983 kfree(log->bios_event_log);
39984+ log->bios_event_log = NULL;
39985 printk("%s: ERROR - Unable to map memory\n", __func__);
39986 return -EIO;
39987 }
39988
39989- memcpy_fromio(log->bios_event_log, virt, len);
39990+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
39991
39992 acpi_os_unmap_iomem(virt, len);
39993 return 0;
39994diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
39995index 3a56a13..f8cbd25 100644
39996--- a/drivers/char/tpm/tpm_eventlog.c
39997+++ b/drivers/char/tpm/tpm_eventlog.c
39998@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
39999 event = addr;
40000
40001 if ((event->event_type == 0 && event->event_size == 0) ||
40002- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
40003+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
40004 return NULL;
40005
40006 return addr;
40007@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
40008 return NULL;
40009
40010 if ((event->event_type == 0 && event->event_size == 0) ||
40011- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
40012+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
40013 return NULL;
40014
40015 (*pos)++;
40016@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
40017 int i;
40018
40019 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
40020- seq_putc(m, data[i]);
40021+ if (!seq_putc(m, data[i]))
40022+ return -EFAULT;
40023
40024 return 0;
40025 }
40026diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
40027index b585b47..488f43e 100644
40028--- a/drivers/char/virtio_console.c
40029+++ b/drivers/char/virtio_console.c
40030@@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
40031 if (to_user) {
40032 ssize_t ret;
40033
40034- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
40035+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
40036 if (ret)
40037 return -EFAULT;
40038 } else {
40039@@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
40040 if (!port_has_data(port) && !port->host_connected)
40041 return 0;
40042
40043- return fill_readbuf(port, ubuf, count, true);
40044+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
40045 }
40046
40047 static int wait_port_writable(struct port *port, bool nonblock)
40048diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
40049index b9355da..9611f4e 100644
40050--- a/drivers/clk/clk-composite.c
40051+++ b/drivers/clk/clk-composite.c
40052@@ -191,7 +191,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
40053 struct clk *clk;
40054 struct clk_init_data init;
40055 struct clk_composite *composite;
40056- struct clk_ops *clk_composite_ops;
40057+ clk_ops_no_const *clk_composite_ops;
40058
40059 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
40060 if (!composite) {
40061diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
40062index dd3a78c..386d49c 100644
40063--- a/drivers/clk/socfpga/clk-gate.c
40064+++ b/drivers/clk/socfpga/clk-gate.c
40065@@ -22,6 +22,7 @@
40066 #include <linux/mfd/syscon.h>
40067 #include <linux/of.h>
40068 #include <linux/regmap.h>
40069+#include <asm/pgtable.h>
40070
40071 #include "clk.h"
40072
40073@@ -174,7 +175,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
40074 return 0;
40075 }
40076
40077-static struct clk_ops gateclk_ops = {
40078+static clk_ops_no_const gateclk_ops __read_only = {
40079 .prepare = socfpga_clk_prepare,
40080 .recalc_rate = socfpga_clk_recalc_rate,
40081 .get_parent = socfpga_clk_get_parent,
40082@@ -208,8 +209,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
40083 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
40084 socfpga_clk->hw.bit_idx = clk_gate[1];
40085
40086- gateclk_ops.enable = clk_gate_ops.enable;
40087- gateclk_ops.disable = clk_gate_ops.disable;
40088+ pax_open_kernel();
40089+ *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
40090+ *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
40091+ pax_close_kernel();
40092 }
40093
40094 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
40095diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
40096index de6da95..c98278b 100644
40097--- a/drivers/clk/socfpga/clk-pll.c
40098+++ b/drivers/clk/socfpga/clk-pll.c
40099@@ -21,6 +21,7 @@
40100 #include <linux/io.h>
40101 #include <linux/of.h>
40102 #include <linux/of_address.h>
40103+#include <asm/pgtable.h>
40104
40105 #include "clk.h"
40106
40107@@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
40108 CLK_MGR_PLL_CLK_SRC_MASK;
40109 }
40110
40111-static struct clk_ops clk_pll_ops = {
40112+static clk_ops_no_const clk_pll_ops __read_only = {
40113 .recalc_rate = clk_pll_recalc_rate,
40114 .get_parent = clk_pll_get_parent,
40115 };
40116@@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
40117 pll_clk->hw.hw.init = &init;
40118
40119 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
40120- clk_pll_ops.enable = clk_gate_ops.enable;
40121- clk_pll_ops.disable = clk_gate_ops.disable;
40122+ pax_open_kernel();
40123+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
40124+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
40125+ pax_close_kernel();
40126
40127 clk = clk_register(NULL, &pll_clk->hw.hw);
40128 if (WARN_ON(IS_ERR(clk))) {
40129diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
40130index b0c18ed..1713a80 100644
40131--- a/drivers/cpufreq/acpi-cpufreq.c
40132+++ b/drivers/cpufreq/acpi-cpufreq.c
40133@@ -675,8 +675,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
40134 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
40135 per_cpu(acfreq_data, cpu) = data;
40136
40137- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
40138- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
40139+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
40140+ pax_open_kernel();
40141+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
40142+ pax_close_kernel();
40143+ }
40144
40145 result = acpi_processor_register_performance(data->acpi_data, cpu);
40146 if (result)
40147@@ -809,7 +812,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
40148 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
40149 break;
40150 case ACPI_ADR_SPACE_FIXED_HARDWARE:
40151- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
40152+ pax_open_kernel();
40153+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
40154+ pax_close_kernel();
40155 break;
40156 default:
40157 break;
40158@@ -903,8 +908,10 @@ static void __init acpi_cpufreq_boost_init(void)
40159 if (!msrs)
40160 return;
40161
40162- acpi_cpufreq_driver.boost_supported = true;
40163- acpi_cpufreq_driver.boost_enabled = boost_state(0);
40164+ pax_open_kernel();
40165+ *(bool *)&acpi_cpufreq_driver.boost_supported = true;
40166+ *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
40167+ pax_close_kernel();
40168
40169 cpu_notifier_register_begin();
40170
40171diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
40172index 07c8276..38bd07c 100644
40173--- a/drivers/cpufreq/cpufreq.c
40174+++ b/drivers/cpufreq/cpufreq.c
40175@@ -2107,7 +2107,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
40176 }
40177
40178 mutex_lock(&cpufreq_governor_mutex);
40179- list_del(&governor->governor_list);
40180+ pax_list_del(&governor->governor_list);
40181 mutex_unlock(&cpufreq_governor_mutex);
40182 return;
40183 }
40184@@ -2323,7 +2323,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
40185 return NOTIFY_OK;
40186 }
40187
40188-static struct notifier_block __refdata cpufreq_cpu_notifier = {
40189+static struct notifier_block cpufreq_cpu_notifier = {
40190 .notifier_call = cpufreq_cpu_callback,
40191 };
40192
40193@@ -2363,13 +2363,17 @@ int cpufreq_boost_trigger_state(int state)
40194 return 0;
40195
40196 write_lock_irqsave(&cpufreq_driver_lock, flags);
40197- cpufreq_driver->boost_enabled = state;
40198+ pax_open_kernel();
40199+ *(bool *)&cpufreq_driver->boost_enabled = state;
40200+ pax_close_kernel();
40201 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
40202
40203 ret = cpufreq_driver->set_boost(state);
40204 if (ret) {
40205 write_lock_irqsave(&cpufreq_driver_lock, flags);
40206- cpufreq_driver->boost_enabled = !state;
40207+ pax_open_kernel();
40208+ *(bool *)&cpufreq_driver->boost_enabled = !state;
40209+ pax_close_kernel();
40210 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
40211
40212 pr_err("%s: Cannot %s BOOST\n",
40213@@ -2426,8 +2430,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
40214
40215 pr_debug("trying to register driver %s\n", driver_data->name);
40216
40217- if (driver_data->setpolicy)
40218- driver_data->flags |= CPUFREQ_CONST_LOOPS;
40219+ if (driver_data->setpolicy) {
40220+ pax_open_kernel();
40221+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
40222+ pax_close_kernel();
40223+ }
40224
40225 write_lock_irqsave(&cpufreq_driver_lock, flags);
40226 if (cpufreq_driver) {
40227@@ -2442,8 +2449,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
40228 * Check if driver provides function to enable boost -
40229 * if not, use cpufreq_boost_set_sw as default
40230 */
40231- if (!cpufreq_driver->set_boost)
40232- cpufreq_driver->set_boost = cpufreq_boost_set_sw;
40233+ if (!cpufreq_driver->set_boost) {
40234+ pax_open_kernel();
40235+ *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
40236+ pax_close_kernel();
40237+ }
40238
40239 ret = cpufreq_sysfs_create_file(&boost.attr);
40240 if (ret) {
40241diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
40242index 1b44496..b80ff5e 100644
40243--- a/drivers/cpufreq/cpufreq_governor.c
40244+++ b/drivers/cpufreq/cpufreq_governor.c
40245@@ -245,7 +245,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40246 struct dbs_data *dbs_data;
40247 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
40248 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
40249- struct od_ops *od_ops = NULL;
40250+ const struct od_ops *od_ops = NULL;
40251 struct od_dbs_tuners *od_tuners = NULL;
40252 struct cs_dbs_tuners *cs_tuners = NULL;
40253 struct cpu_dbs_common_info *cpu_cdbs;
40254@@ -311,7 +311,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40255
40256 if ((cdata->governor == GOV_CONSERVATIVE) &&
40257 (!policy->governor->initialized)) {
40258- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40259+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40260
40261 cpufreq_register_notifier(cs_ops->notifier_block,
40262 CPUFREQ_TRANSITION_NOTIFIER);
40263@@ -331,7 +331,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40264
40265 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
40266 (policy->governor->initialized == 1)) {
40267- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40268+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40269
40270 cpufreq_unregister_notifier(cs_ops->notifier_block,
40271 CPUFREQ_TRANSITION_NOTIFIER);
40272diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
40273index cc401d1..8197340 100644
40274--- a/drivers/cpufreq/cpufreq_governor.h
40275+++ b/drivers/cpufreq/cpufreq_governor.h
40276@@ -212,7 +212,7 @@ struct common_dbs_data {
40277 void (*exit)(struct dbs_data *dbs_data);
40278
40279 /* Governor specific ops, see below */
40280- void *gov_ops;
40281+ const void *gov_ops;
40282 };
40283
40284 /* Governor Per policy data */
40285@@ -232,7 +232,7 @@ struct od_ops {
40286 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
40287 unsigned int freq_next, unsigned int relation);
40288 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
40289-};
40290+} __no_const;
40291
40292 struct cs_ops {
40293 struct notifier_block *notifier_block;
40294diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
40295index ad3f38f..8f086cd 100644
40296--- a/drivers/cpufreq/cpufreq_ondemand.c
40297+++ b/drivers/cpufreq/cpufreq_ondemand.c
40298@@ -524,7 +524,7 @@ static void od_exit(struct dbs_data *dbs_data)
40299
40300 define_get_cpu_dbs_routines(od_cpu_dbs_info);
40301
40302-static struct od_ops od_ops = {
40303+static struct od_ops od_ops __read_only = {
40304 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
40305 .powersave_bias_target = generic_powersave_bias_target,
40306 .freq_increase = dbs_freq_increase,
40307@@ -579,14 +579,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
40308 (struct cpufreq_policy *, unsigned int, unsigned int),
40309 unsigned int powersave_bias)
40310 {
40311- od_ops.powersave_bias_target = f;
40312+ pax_open_kernel();
40313+ *(void **)&od_ops.powersave_bias_target = f;
40314+ pax_close_kernel();
40315 od_set_powersave_bias(powersave_bias);
40316 }
40317 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
40318
40319 void od_unregister_powersave_bias_handler(void)
40320 {
40321- od_ops.powersave_bias_target = generic_powersave_bias_target;
40322+ pax_open_kernel();
40323+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
40324+ pax_close_kernel();
40325 od_set_powersave_bias(0);
40326 }
40327 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
40328diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
40329index 27bb6d3..4cf595c 100644
40330--- a/drivers/cpufreq/intel_pstate.c
40331+++ b/drivers/cpufreq/intel_pstate.c
40332@@ -133,10 +133,10 @@ struct pstate_funcs {
40333 struct cpu_defaults {
40334 struct pstate_adjust_policy pid_policy;
40335 struct pstate_funcs funcs;
40336-};
40337+} __do_const;
40338
40339 static struct pstate_adjust_policy pid_params;
40340-static struct pstate_funcs pstate_funcs;
40341+static struct pstate_funcs *pstate_funcs;
40342
40343 struct perf_limits {
40344 int no_turbo;
40345@@ -594,18 +594,18 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
40346
40347 cpu->pstate.current_pstate = pstate;
40348
40349- pstate_funcs.set(cpu, pstate);
40350+ pstate_funcs->set(cpu, pstate);
40351 }
40352
40353 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
40354 {
40355- cpu->pstate.min_pstate = pstate_funcs.get_min();
40356- cpu->pstate.max_pstate = pstate_funcs.get_max();
40357- cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
40358- cpu->pstate.scaling = pstate_funcs.get_scaling();
40359+ cpu->pstate.min_pstate = pstate_funcs->get_min();
40360+ cpu->pstate.max_pstate = pstate_funcs->get_max();
40361+ cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
40362+ cpu->pstate.scaling = pstate_funcs->get_scaling();
40363
40364- if (pstate_funcs.get_vid)
40365- pstate_funcs.get_vid(cpu);
40366+ if (pstate_funcs->get_vid)
40367+ pstate_funcs->get_vid(cpu);
40368 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
40369 }
40370
40371@@ -875,9 +875,9 @@ static int intel_pstate_msrs_not_valid(void)
40372 rdmsrl(MSR_IA32_APERF, aperf);
40373 rdmsrl(MSR_IA32_MPERF, mperf);
40374
40375- if (!pstate_funcs.get_max() ||
40376- !pstate_funcs.get_min() ||
40377- !pstate_funcs.get_turbo())
40378+ if (!pstate_funcs->get_max() ||
40379+ !pstate_funcs->get_min() ||
40380+ !pstate_funcs->get_turbo())
40381 return -ENODEV;
40382
40383 rdmsrl(MSR_IA32_APERF, tmp);
40384@@ -891,7 +891,7 @@ static int intel_pstate_msrs_not_valid(void)
40385 return 0;
40386 }
40387
40388-static void copy_pid_params(struct pstate_adjust_policy *policy)
40389+static void copy_pid_params(const struct pstate_adjust_policy *policy)
40390 {
40391 pid_params.sample_rate_ms = policy->sample_rate_ms;
40392 pid_params.p_gain_pct = policy->p_gain_pct;
40393@@ -903,12 +903,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
40394
40395 static void copy_cpu_funcs(struct pstate_funcs *funcs)
40396 {
40397- pstate_funcs.get_max = funcs->get_max;
40398- pstate_funcs.get_min = funcs->get_min;
40399- pstate_funcs.get_turbo = funcs->get_turbo;
40400- pstate_funcs.get_scaling = funcs->get_scaling;
40401- pstate_funcs.set = funcs->set;
40402- pstate_funcs.get_vid = funcs->get_vid;
40403+ pstate_funcs = funcs;
40404 }
40405
40406 #if IS_ENABLED(CONFIG_ACPI)
40407diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
40408index 529cfd9..0e28fff 100644
40409--- a/drivers/cpufreq/p4-clockmod.c
40410+++ b/drivers/cpufreq/p4-clockmod.c
40411@@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
40412 case 0x0F: /* Core Duo */
40413 case 0x16: /* Celeron Core */
40414 case 0x1C: /* Atom */
40415- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40416+ pax_open_kernel();
40417+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40418+ pax_close_kernel();
40419 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
40420 case 0x0D: /* Pentium M (Dothan) */
40421- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40422+ pax_open_kernel();
40423+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40424+ pax_close_kernel();
40425 /* fall through */
40426 case 0x09: /* Pentium M (Banias) */
40427 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
40428@@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
40429
40430 /* on P-4s, the TSC runs with constant frequency independent whether
40431 * throttling is active or not. */
40432- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40433+ pax_open_kernel();
40434+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40435+ pax_close_kernel();
40436
40437 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
40438 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
40439diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
40440index 9bb42ba..b01b4a2 100644
40441--- a/drivers/cpufreq/sparc-us3-cpufreq.c
40442+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
40443@@ -18,14 +18,12 @@
40444 #include <asm/head.h>
40445 #include <asm/timer.h>
40446
40447-static struct cpufreq_driver *cpufreq_us3_driver;
40448-
40449 struct us3_freq_percpu_info {
40450 struct cpufreq_frequency_table table[4];
40451 };
40452
40453 /* Indexed by cpu number. */
40454-static struct us3_freq_percpu_info *us3_freq_table;
40455+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
40456
40457 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
40458 * in the Safari config register.
40459@@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
40460
40461 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
40462 {
40463- if (cpufreq_us3_driver)
40464- us3_freq_target(policy, 0);
40465+ us3_freq_target(policy, 0);
40466
40467 return 0;
40468 }
40469
40470+static int __init us3_freq_init(void);
40471+static void __exit us3_freq_exit(void);
40472+
40473+static struct cpufreq_driver cpufreq_us3_driver = {
40474+ .init = us3_freq_cpu_init,
40475+ .verify = cpufreq_generic_frequency_table_verify,
40476+ .target_index = us3_freq_target,
40477+ .get = us3_freq_get,
40478+ .exit = us3_freq_cpu_exit,
40479+ .name = "UltraSPARC-III",
40480+
40481+};
40482+
40483 static int __init us3_freq_init(void)
40484 {
40485 unsigned long manuf, impl, ver;
40486- int ret;
40487
40488 if (tlb_type != cheetah && tlb_type != cheetah_plus)
40489 return -ENODEV;
40490@@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
40491 (impl == CHEETAH_IMPL ||
40492 impl == CHEETAH_PLUS_IMPL ||
40493 impl == JAGUAR_IMPL ||
40494- impl == PANTHER_IMPL)) {
40495- struct cpufreq_driver *driver;
40496-
40497- ret = -ENOMEM;
40498- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
40499- if (!driver)
40500- goto err_out;
40501-
40502- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
40503- GFP_KERNEL);
40504- if (!us3_freq_table)
40505- goto err_out;
40506-
40507- driver->init = us3_freq_cpu_init;
40508- driver->verify = cpufreq_generic_frequency_table_verify;
40509- driver->target_index = us3_freq_target;
40510- driver->get = us3_freq_get;
40511- driver->exit = us3_freq_cpu_exit;
40512- strcpy(driver->name, "UltraSPARC-III");
40513-
40514- cpufreq_us3_driver = driver;
40515- ret = cpufreq_register_driver(driver);
40516- if (ret)
40517- goto err_out;
40518-
40519- return 0;
40520-
40521-err_out:
40522- if (driver) {
40523- kfree(driver);
40524- cpufreq_us3_driver = NULL;
40525- }
40526- kfree(us3_freq_table);
40527- us3_freq_table = NULL;
40528- return ret;
40529- }
40530+ impl == PANTHER_IMPL))
40531+ return cpufreq_register_driver(&cpufreq_us3_driver);
40532
40533 return -ENODEV;
40534 }
40535
40536 static void __exit us3_freq_exit(void)
40537 {
40538- if (cpufreq_us3_driver) {
40539- cpufreq_unregister_driver(cpufreq_us3_driver);
40540- kfree(cpufreq_us3_driver);
40541- cpufreq_us3_driver = NULL;
40542- kfree(us3_freq_table);
40543- us3_freq_table = NULL;
40544- }
40545+ cpufreq_unregister_driver(&cpufreq_us3_driver);
40546 }
40547
40548 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
40549diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
40550index 7d4a315..21bb886 100644
40551--- a/drivers/cpufreq/speedstep-centrino.c
40552+++ b/drivers/cpufreq/speedstep-centrino.c
40553@@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
40554 !cpu_has(cpu, X86_FEATURE_EST))
40555 return -ENODEV;
40556
40557- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
40558- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
40559+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
40560+ pax_open_kernel();
40561+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
40562+ pax_close_kernel();
40563+ }
40564
40565 if (policy->cpu != 0)
40566 return -ENODEV;
40567diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
40568index e431d11..d0b997e 100644
40569--- a/drivers/cpuidle/driver.c
40570+++ b/drivers/cpuidle/driver.c
40571@@ -194,7 +194,7 @@ static int poll_idle(struct cpuidle_device *dev,
40572
40573 static void poll_idle_init(struct cpuidle_driver *drv)
40574 {
40575- struct cpuidle_state *state = &drv->states[0];
40576+ cpuidle_state_no_const *state = &drv->states[0];
40577
40578 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
40579 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
40580diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
40581index ca89412..a7b9c49 100644
40582--- a/drivers/cpuidle/governor.c
40583+++ b/drivers/cpuidle/governor.c
40584@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
40585 mutex_lock(&cpuidle_lock);
40586 if (__cpuidle_find_governor(gov->name) == NULL) {
40587 ret = 0;
40588- list_add_tail(&gov->governor_list, &cpuidle_governors);
40589+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
40590 if (!cpuidle_curr_governor ||
40591 cpuidle_curr_governor->rating < gov->rating)
40592 cpuidle_switch_governor(gov);
40593diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
40594index 97c5903..023ad23 100644
40595--- a/drivers/cpuidle/sysfs.c
40596+++ b/drivers/cpuidle/sysfs.c
40597@@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
40598 NULL
40599 };
40600
40601-static struct attribute_group cpuidle_attr_group = {
40602+static attribute_group_no_const cpuidle_attr_group = {
40603 .attrs = cpuidle_default_attrs,
40604 .name = "cpuidle",
40605 };
40606diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
40607index 8d2a772..33826c9 100644
40608--- a/drivers/crypto/hifn_795x.c
40609+++ b/drivers/crypto/hifn_795x.c
40610@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
40611 MODULE_PARM_DESC(hifn_pll_ref,
40612 "PLL reference clock (pci[freq] or ext[freq], default ext)");
40613
40614-static atomic_t hifn_dev_number;
40615+static atomic_unchecked_t hifn_dev_number;
40616
40617 #define ACRYPTO_OP_DECRYPT 0
40618 #define ACRYPTO_OP_ENCRYPT 1
40619@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
40620 goto err_out_disable_pci_device;
40621
40622 snprintf(name, sizeof(name), "hifn%d",
40623- atomic_inc_return(&hifn_dev_number)-1);
40624+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
40625
40626 err = pci_request_regions(pdev, name);
40627 if (err)
40628diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
40629index 9f90369..bfcacdb 100644
40630--- a/drivers/devfreq/devfreq.c
40631+++ b/drivers/devfreq/devfreq.c
40632@@ -673,7 +673,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
40633 goto err_out;
40634 }
40635
40636- list_add(&governor->node, &devfreq_governor_list);
40637+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
40638
40639 list_for_each_entry(devfreq, &devfreq_list, node) {
40640 int ret = 0;
40641@@ -761,7 +761,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
40642 }
40643 }
40644
40645- list_del(&governor->node);
40646+ pax_list_del((struct list_head *)&governor->node);
40647 err_out:
40648 mutex_unlock(&devfreq_list_lock);
40649
40650diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
40651index 42d4974..2714f36 100644
40652--- a/drivers/dma/sh/shdma-base.c
40653+++ b/drivers/dma/sh/shdma-base.c
40654@@ -228,8 +228,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
40655 schan->slave_id = -EINVAL;
40656 }
40657
40658- schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
40659- sdev->desc_size, GFP_KERNEL);
40660+ schan->desc = kcalloc(sdev->desc_size,
40661+ NR_DESCS_PER_CHANNEL, GFP_KERNEL);
40662 if (!schan->desc) {
40663 ret = -ENOMEM;
40664 goto edescalloc;
40665diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
40666index 58eb857..d7e42c8 100644
40667--- a/drivers/dma/sh/shdmac.c
40668+++ b/drivers/dma/sh/shdmac.c
40669@@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
40670 return ret;
40671 }
40672
40673-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
40674+static struct notifier_block sh_dmae_nmi_notifier = {
40675 .notifier_call = sh_dmae_nmi_handler,
40676
40677 /* Run before NMI debug handler and KGDB */
40678diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
40679index 592af5f..bb1d583 100644
40680--- a/drivers/edac/edac_device.c
40681+++ b/drivers/edac/edac_device.c
40682@@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
40683 */
40684 int edac_device_alloc_index(void)
40685 {
40686- static atomic_t device_indexes = ATOMIC_INIT(0);
40687+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
40688
40689- return atomic_inc_return(&device_indexes) - 1;
40690+ return atomic_inc_return_unchecked(&device_indexes) - 1;
40691 }
40692 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
40693
40694diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
40695index a6cd361..7bdbf53 100644
40696--- a/drivers/edac/edac_mc_sysfs.c
40697+++ b/drivers/edac/edac_mc_sysfs.c
40698@@ -154,7 +154,7 @@ static const char * const edac_caps[] = {
40699 struct dev_ch_attribute {
40700 struct device_attribute attr;
40701 int channel;
40702-};
40703+} __do_const;
40704
40705 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
40706 struct dev_ch_attribute dev_attr_legacy_##_name = \
40707@@ -1011,14 +1011,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
40708 }
40709
40710 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
40711+ pax_open_kernel();
40712 if (mci->get_sdram_scrub_rate) {
40713- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
40714- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
40715+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
40716+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
40717 }
40718 if (mci->set_sdram_scrub_rate) {
40719- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
40720- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
40721+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
40722+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
40723 }
40724+ pax_close_kernel();
40725 err = device_create_file(&mci->dev,
40726 &dev_attr_sdram_scrub_rate);
40727 if (err) {
40728diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
40729index 2cf44b4d..6dd2dc7 100644
40730--- a/drivers/edac/edac_pci.c
40731+++ b/drivers/edac/edac_pci.c
40732@@ -29,7 +29,7 @@
40733
40734 static DEFINE_MUTEX(edac_pci_ctls_mutex);
40735 static LIST_HEAD(edac_pci_list);
40736-static atomic_t pci_indexes = ATOMIC_INIT(0);
40737+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
40738
40739 /*
40740 * edac_pci_alloc_ctl_info
40741@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
40742 */
40743 int edac_pci_alloc_index(void)
40744 {
40745- return atomic_inc_return(&pci_indexes) - 1;
40746+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
40747 }
40748 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
40749
40750diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
40751index e8658e4..22746d6 100644
40752--- a/drivers/edac/edac_pci_sysfs.c
40753+++ b/drivers/edac/edac_pci_sysfs.c
40754@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
40755 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
40756 static int edac_pci_poll_msec = 1000; /* one second workq period */
40757
40758-static atomic_t pci_parity_count = ATOMIC_INIT(0);
40759-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
40760+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
40761+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
40762
40763 static struct kobject *edac_pci_top_main_kobj;
40764 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
40765@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
40766 void *value;
40767 ssize_t(*show) (void *, char *);
40768 ssize_t(*store) (void *, const char *, size_t);
40769-};
40770+} __do_const;
40771
40772 /* Set of show/store abstract level functions for PCI Parity object */
40773 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
40774@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40775 edac_printk(KERN_CRIT, EDAC_PCI,
40776 "Signaled System Error on %s\n",
40777 pci_name(dev));
40778- atomic_inc(&pci_nonparity_count);
40779+ atomic_inc_unchecked(&pci_nonparity_count);
40780 }
40781
40782 if (status & (PCI_STATUS_PARITY)) {
40783@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40784 "Master Data Parity Error on %s\n",
40785 pci_name(dev));
40786
40787- atomic_inc(&pci_parity_count);
40788+ atomic_inc_unchecked(&pci_parity_count);
40789 }
40790
40791 if (status & (PCI_STATUS_DETECTED_PARITY)) {
40792@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40793 "Detected Parity Error on %s\n",
40794 pci_name(dev));
40795
40796- atomic_inc(&pci_parity_count);
40797+ atomic_inc_unchecked(&pci_parity_count);
40798 }
40799 }
40800
40801@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40802 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
40803 "Signaled System Error on %s\n",
40804 pci_name(dev));
40805- atomic_inc(&pci_nonparity_count);
40806+ atomic_inc_unchecked(&pci_nonparity_count);
40807 }
40808
40809 if (status & (PCI_STATUS_PARITY)) {
40810@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40811 "Master Data Parity Error on "
40812 "%s\n", pci_name(dev));
40813
40814- atomic_inc(&pci_parity_count);
40815+ atomic_inc_unchecked(&pci_parity_count);
40816 }
40817
40818 if (status & (PCI_STATUS_DETECTED_PARITY)) {
40819@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40820 "Detected Parity Error on %s\n",
40821 pci_name(dev));
40822
40823- atomic_inc(&pci_parity_count);
40824+ atomic_inc_unchecked(&pci_parity_count);
40825 }
40826 }
40827 }
40828@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
40829 if (!check_pci_errors)
40830 return;
40831
40832- before_count = atomic_read(&pci_parity_count);
40833+ before_count = atomic_read_unchecked(&pci_parity_count);
40834
40835 /* scan all PCI devices looking for a Parity Error on devices and
40836 * bridges.
40837@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
40838 /* Only if operator has selected panic on PCI Error */
40839 if (edac_pci_get_panic_on_pe()) {
40840 /* If the count is different 'after' from 'before' */
40841- if (before_count != atomic_read(&pci_parity_count))
40842+ if (before_count != atomic_read_unchecked(&pci_parity_count))
40843 panic("EDAC: PCI Parity Error");
40844 }
40845 }
40846diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
40847index 51b7e3a..aa8a3e8 100644
40848--- a/drivers/edac/mce_amd.h
40849+++ b/drivers/edac/mce_amd.h
40850@@ -77,7 +77,7 @@ struct amd_decoder_ops {
40851 bool (*mc0_mce)(u16, u8);
40852 bool (*mc1_mce)(u16, u8);
40853 bool (*mc2_mce)(u16, u8);
40854-};
40855+} __no_const;
40856
40857 void amd_report_gart_errors(bool);
40858 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
40859diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
40860index 57ea7f4..af06b76 100644
40861--- a/drivers/firewire/core-card.c
40862+++ b/drivers/firewire/core-card.c
40863@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
40864 const struct fw_card_driver *driver,
40865 struct device *device)
40866 {
40867- static atomic_t index = ATOMIC_INIT(-1);
40868+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
40869
40870- card->index = atomic_inc_return(&index);
40871+ card->index = atomic_inc_return_unchecked(&index);
40872 card->driver = driver;
40873 card->device = device;
40874 card->current_tlabel = 0;
40875@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
40876
40877 void fw_core_remove_card(struct fw_card *card)
40878 {
40879- struct fw_card_driver dummy_driver = dummy_driver_template;
40880+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
40881
40882 card->driver->update_phy_reg(card, 4,
40883 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
40884diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
40885index 2c6d5e1..a2cca6b 100644
40886--- a/drivers/firewire/core-device.c
40887+++ b/drivers/firewire/core-device.c
40888@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
40889 struct config_rom_attribute {
40890 struct device_attribute attr;
40891 u32 key;
40892-};
40893+} __do_const;
40894
40895 static ssize_t show_immediate(struct device *dev,
40896 struct device_attribute *dattr, char *buf)
40897diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
40898index eb6935c..3cc2bfa 100644
40899--- a/drivers/firewire/core-transaction.c
40900+++ b/drivers/firewire/core-transaction.c
40901@@ -38,6 +38,7 @@
40902 #include <linux/timer.h>
40903 #include <linux/types.h>
40904 #include <linux/workqueue.h>
40905+#include <linux/sched.h>
40906
40907 #include <asm/byteorder.h>
40908
40909diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
40910index e1480ff6..1a429bd 100644
40911--- a/drivers/firewire/core.h
40912+++ b/drivers/firewire/core.h
40913@@ -111,6 +111,7 @@ struct fw_card_driver {
40914
40915 int (*stop_iso)(struct fw_iso_context *ctx);
40916 };
40917+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
40918
40919 void fw_card_initialize(struct fw_card *card,
40920 const struct fw_card_driver *driver, struct device *device);
40921diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
40922index a66a321..f6caf20 100644
40923--- a/drivers/firewire/ohci.c
40924+++ b/drivers/firewire/ohci.c
40925@@ -2056,10 +2056,12 @@ static void bus_reset_work(struct work_struct *work)
40926 be32_to_cpu(ohci->next_header));
40927 }
40928
40929+#ifndef CONFIG_GRKERNSEC
40930 if (param_remote_dma) {
40931 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
40932 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
40933 }
40934+#endif
40935
40936 spin_unlock_irq(&ohci->lock);
40937
40938@@ -2591,8 +2593,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
40939 unsigned long flags;
40940 int n, ret = 0;
40941
40942+#ifndef CONFIG_GRKERNSEC
40943 if (param_remote_dma)
40944 return 0;
40945+#endif
40946
40947 /*
40948 * FIXME: Make sure this bitmask is cleared when we clear the busReset
40949diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
40950index 94a58a0..f5eba42 100644
40951--- a/drivers/firmware/dmi-id.c
40952+++ b/drivers/firmware/dmi-id.c
40953@@ -16,7 +16,7 @@
40954 struct dmi_device_attribute{
40955 struct device_attribute dev_attr;
40956 int field;
40957-};
40958+} __do_const;
40959 #define to_dmi_dev_attr(_dev_attr) \
40960 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
40961
40962diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
40963index 17afc51..0ef90cd 100644
40964--- a/drivers/firmware/dmi_scan.c
40965+++ b/drivers/firmware/dmi_scan.c
40966@@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
40967 if (buf == NULL)
40968 return -1;
40969
40970- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
40971+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
40972
40973 dmi_unmap(buf);
40974 return 0;
40975diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
40976index 5b53d61..72cee96 100644
40977--- a/drivers/firmware/efi/cper.c
40978+++ b/drivers/firmware/efi/cper.c
40979@@ -44,12 +44,12 @@ static char rcd_decode_str[CPER_REC_LEN];
40980 */
40981 u64 cper_next_record_id(void)
40982 {
40983- static atomic64_t seq;
40984+ static atomic64_unchecked_t seq;
40985
40986- if (!atomic64_read(&seq))
40987- atomic64_set(&seq, ((u64)get_seconds()) << 32);
40988+ if (!atomic64_read_unchecked(&seq))
40989+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
40990
40991- return atomic64_inc_return(&seq);
40992+ return atomic64_inc_return_unchecked(&seq);
40993 }
40994 EXPORT_SYMBOL_GPL(cper_next_record_id);
40995
40996diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
40997index 64ecbb5..d921eb3 100644
40998--- a/drivers/firmware/efi/efi.c
40999+++ b/drivers/firmware/efi/efi.c
41000@@ -126,14 +126,16 @@ static struct attribute_group efi_subsys_attr_group = {
41001 };
41002
41003 static struct efivars generic_efivars;
41004-static struct efivar_operations generic_ops;
41005+static efivar_operations_no_const generic_ops __read_only;
41006
41007 static int generic_ops_register(void)
41008 {
41009- generic_ops.get_variable = efi.get_variable;
41010- generic_ops.set_variable = efi.set_variable;
41011- generic_ops.get_next_variable = efi.get_next_variable;
41012- generic_ops.query_variable_store = efi_query_variable_store;
41013+ pax_open_kernel();
41014+ *(void **)&generic_ops.get_variable = efi.get_variable;
41015+ *(void **)&generic_ops.set_variable = efi.set_variable;
41016+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
41017+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
41018+ pax_close_kernel();
41019
41020 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
41021 }
41022diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
41023index f256ecd..387dcb1 100644
41024--- a/drivers/firmware/efi/efivars.c
41025+++ b/drivers/firmware/efi/efivars.c
41026@@ -589,7 +589,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
41027 static int
41028 create_efivars_bin_attributes(void)
41029 {
41030- struct bin_attribute *attr;
41031+ bin_attribute_no_const *attr;
41032 int error;
41033
41034 /* new_var */
41035diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
41036index 2f569aa..c95f4fb 100644
41037--- a/drivers/firmware/google/memconsole.c
41038+++ b/drivers/firmware/google/memconsole.c
41039@@ -155,7 +155,10 @@ static int __init memconsole_init(void)
41040 if (!found_memconsole())
41041 return -ENODEV;
41042
41043- memconsole_bin_attr.size = memconsole_length;
41044+ pax_open_kernel();
41045+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
41046+ pax_close_kernel();
41047+
41048 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
41049 }
41050
41051diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
41052index fe49ec3..1ade794 100644
41053--- a/drivers/gpio/gpio-em.c
41054+++ b/drivers/gpio/gpio-em.c
41055@@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
41056 struct em_gio_priv *p;
41057 struct resource *io[2], *irq[2];
41058 struct gpio_chip *gpio_chip;
41059- struct irq_chip *irq_chip;
41060+ irq_chip_no_const *irq_chip;
41061 const char *name = dev_name(&pdev->dev);
41062 int ret;
41063
41064diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
41065index 3784e81..73637b5 100644
41066--- a/drivers/gpio/gpio-ich.c
41067+++ b/drivers/gpio/gpio-ich.c
41068@@ -94,7 +94,7 @@ struct ichx_desc {
41069 * this option allows driver caching written output values
41070 */
41071 bool use_outlvl_cache;
41072-};
41073+} __do_const;
41074
41075 static struct {
41076 spinlock_t lock;
41077diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
41078index bf6c094..6573caf 100644
41079--- a/drivers/gpio/gpio-rcar.c
41080+++ b/drivers/gpio/gpio-rcar.c
41081@@ -357,7 +357,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
41082 struct gpio_rcar_priv *p;
41083 struct resource *io, *irq;
41084 struct gpio_chip *gpio_chip;
41085- struct irq_chip *irq_chip;
41086+ irq_chip_no_const *irq_chip;
41087 struct device *dev = &pdev->dev;
41088 const char *name = dev_name(dev);
41089 int ret;
41090diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
41091index dbf28fa..04dad4e 100644
41092--- a/drivers/gpio/gpio-vr41xx.c
41093+++ b/drivers/gpio/gpio-vr41xx.c
41094@@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
41095 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
41096 maskl, pendl, maskh, pendh);
41097
41098- atomic_inc(&irq_err_count);
41099+ atomic_inc_unchecked(&irq_err_count);
41100
41101 return -EINVAL;
41102 }
41103diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
41104index c68d037..2f4f9a9 100644
41105--- a/drivers/gpio/gpiolib.c
41106+++ b/drivers/gpio/gpiolib.c
41107@@ -529,8 +529,10 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
41108 }
41109
41110 if (gpiochip->irqchip) {
41111- gpiochip->irqchip->irq_request_resources = NULL;
41112- gpiochip->irqchip->irq_release_resources = NULL;
41113+ pax_open_kernel();
41114+ *(void **)&gpiochip->irqchip->irq_request_resources = NULL;
41115+ *(void **)&gpiochip->irqchip->irq_release_resources = NULL;
41116+ pax_close_kernel();
41117 gpiochip->irqchip = NULL;
41118 }
41119 }
41120@@ -596,8 +598,11 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
41121 gpiochip->irqchip = NULL;
41122 return -EINVAL;
41123 }
41124- irqchip->irq_request_resources = gpiochip_irq_reqres;
41125- irqchip->irq_release_resources = gpiochip_irq_relres;
41126+
41127+ pax_open_kernel();
41128+ *(void **)&irqchip->irq_request_resources = gpiochip_irq_reqres;
41129+ *(void **)&irqchip->irq_release_resources = gpiochip_irq_relres;
41130+ pax_close_kernel();
41131
41132 /*
41133 * Prepare the mapping since the irqchip shall be orthogonal to
41134diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
41135index 90e7730..3b41807 100644
41136--- a/drivers/gpu/drm/drm_crtc.c
41137+++ b/drivers/gpu/drm/drm_crtc.c
41138@@ -3861,7 +3861,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
41139 goto done;
41140 }
41141
41142- if (copy_to_user(&enum_ptr[copied].name,
41143+ if (copy_to_user(enum_ptr[copied].name,
41144 &prop_enum->name, DRM_PROP_NAME_LEN)) {
41145 ret = -EFAULT;
41146 goto done;
41147diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
41148index 3242e20..7e4f621 100644
41149--- a/drivers/gpu/drm/drm_drv.c
41150+++ b/drivers/gpu/drm/drm_drv.c
41151@@ -463,7 +463,7 @@ void drm_unplug_dev(struct drm_device *dev)
41152
41153 drm_device_set_unplugged(dev);
41154
41155- if (dev->open_count == 0) {
41156+ if (local_read(&dev->open_count) == 0) {
41157 drm_put_dev(dev);
41158 }
41159 mutex_unlock(&drm_global_mutex);
41160diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
41161index 79d5221..7ff73496 100644
41162--- a/drivers/gpu/drm/drm_fops.c
41163+++ b/drivers/gpu/drm/drm_fops.c
41164@@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
41165 return PTR_ERR(minor);
41166
41167 dev = minor->dev;
41168- if (!dev->open_count++)
41169+ if (local_inc_return(&dev->open_count) == 1)
41170 need_setup = 1;
41171
41172 /* share address_space across all char-devs of a single device */
41173@@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
41174 return 0;
41175
41176 err_undo:
41177- dev->open_count--;
41178+ local_dec(&dev->open_count);
41179 drm_minor_release(minor);
41180 return retcode;
41181 }
41182@@ -384,7 +384,7 @@ int drm_release(struct inode *inode, struct file *filp)
41183
41184 mutex_lock(&drm_global_mutex);
41185
41186- DRM_DEBUG("open_count = %d\n", dev->open_count);
41187+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
41188
41189 mutex_lock(&dev->struct_mutex);
41190 list_del(&file_priv->lhead);
41191@@ -397,10 +397,10 @@ int drm_release(struct inode *inode, struct file *filp)
41192 * Begin inline drm_release
41193 */
41194
41195- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
41196+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
41197 task_pid_nr(current),
41198 (long)old_encode_dev(file_priv->minor->kdev->devt),
41199- dev->open_count);
41200+ local_read(&dev->open_count));
41201
41202 /* Release any auth tokens that might point to this file_priv,
41203 (do that under the drm_global_mutex) */
41204@@ -471,7 +471,7 @@ int drm_release(struct inode *inode, struct file *filp)
41205 * End inline drm_release
41206 */
41207
41208- if (!--dev->open_count) {
41209+ if (local_dec_and_test(&dev->open_count)) {
41210 retcode = drm_lastclose(dev);
41211 if (drm_device_is_unplugged(dev))
41212 drm_put_dev(dev);
41213diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
41214index 3d2e91c..d31c4c9 100644
41215--- a/drivers/gpu/drm/drm_global.c
41216+++ b/drivers/gpu/drm/drm_global.c
41217@@ -36,7 +36,7 @@
41218 struct drm_global_item {
41219 struct mutex mutex;
41220 void *object;
41221- int refcount;
41222+ atomic_t refcount;
41223 };
41224
41225 static struct drm_global_item glob[DRM_GLOBAL_NUM];
41226@@ -49,7 +49,7 @@ void drm_global_init(void)
41227 struct drm_global_item *item = &glob[i];
41228 mutex_init(&item->mutex);
41229 item->object = NULL;
41230- item->refcount = 0;
41231+ atomic_set(&item->refcount, 0);
41232 }
41233 }
41234
41235@@ -59,7 +59,7 @@ void drm_global_release(void)
41236 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
41237 struct drm_global_item *item = &glob[i];
41238 BUG_ON(item->object != NULL);
41239- BUG_ON(item->refcount != 0);
41240+ BUG_ON(atomic_read(&item->refcount) != 0);
41241 }
41242 }
41243
41244@@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
41245 struct drm_global_item *item = &glob[ref->global_type];
41246
41247 mutex_lock(&item->mutex);
41248- if (item->refcount == 0) {
41249+ if (atomic_read(&item->refcount) == 0) {
41250 item->object = kzalloc(ref->size, GFP_KERNEL);
41251 if (unlikely(item->object == NULL)) {
41252 ret = -ENOMEM;
41253@@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
41254 goto out_err;
41255
41256 }
41257- ++item->refcount;
41258+ atomic_inc(&item->refcount);
41259 ref->object = item->object;
41260 mutex_unlock(&item->mutex);
41261 return 0;
41262@@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
41263 struct drm_global_item *item = &glob[ref->global_type];
41264
41265 mutex_lock(&item->mutex);
41266- BUG_ON(item->refcount == 0);
41267+ BUG_ON(atomic_read(&item->refcount) == 0);
41268 BUG_ON(ref->object != item->object);
41269- if (--item->refcount == 0) {
41270+ if (atomic_dec_and_test(&item->refcount)) {
41271 ref->release(ref);
41272 item->object = NULL;
41273 }
41274diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
41275index ecaf0fa..a49cee9 100644
41276--- a/drivers/gpu/drm/drm_info.c
41277+++ b/drivers/gpu/drm/drm_info.c
41278@@ -73,10 +73,13 @@ int drm_vm_info(struct seq_file *m, void *data)
41279 struct drm_local_map *map;
41280 struct drm_map_list *r_list;
41281
41282- /* Hardcoded from _DRM_FRAME_BUFFER,
41283- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
41284- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
41285- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
41286+ static const char * const types[] = {
41287+ [_DRM_FRAME_BUFFER] = "FB",
41288+ [_DRM_REGISTERS] = "REG",
41289+ [_DRM_SHM] = "SHM",
41290+ [_DRM_AGP] = "AGP",
41291+ [_DRM_SCATTER_GATHER] = "SG",
41292+ [_DRM_CONSISTENT] = "PCI"};
41293 const char *type;
41294 int i;
41295
41296@@ -87,7 +90,7 @@ int drm_vm_info(struct seq_file *m, void *data)
41297 map = r_list->map;
41298 if (!map)
41299 continue;
41300- if (map->type < 0 || map->type > 5)
41301+ if (map->type >= ARRAY_SIZE(types))
41302 type = "??";
41303 else
41304 type = types[map->type];
41305@@ -259,7 +262,11 @@ int drm_vma_info(struct seq_file *m, void *data)
41306 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
41307 vma->vm_flags & VM_LOCKED ? 'l' : '-',
41308 vma->vm_flags & VM_IO ? 'i' : '-',
41309+#ifdef CONFIG_GRKERNSEC_HIDESYM
41310+ 0);
41311+#else
41312 vma->vm_pgoff);
41313+#endif
41314
41315 #if defined(__i386__)
41316 pgprot = pgprot_val(vma->vm_page_prot);
41317diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
41318index 2f4c4343..dd12cd2 100644
41319--- a/drivers/gpu/drm/drm_ioc32.c
41320+++ b/drivers/gpu/drm/drm_ioc32.c
41321@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
41322 request = compat_alloc_user_space(nbytes);
41323 if (!access_ok(VERIFY_WRITE, request, nbytes))
41324 return -EFAULT;
41325- list = (struct drm_buf_desc *) (request + 1);
41326+ list = (struct drm_buf_desc __user *) (request + 1);
41327
41328 if (__put_user(count, &request->count)
41329 || __put_user(list, &request->list))
41330@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
41331 request = compat_alloc_user_space(nbytes);
41332 if (!access_ok(VERIFY_WRITE, request, nbytes))
41333 return -EFAULT;
41334- list = (struct drm_buf_pub *) (request + 1);
41335+ list = (struct drm_buf_pub __user *) (request + 1);
41336
41337 if (__put_user(count, &request->count)
41338 || __put_user(list, &request->list))
41339@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
41340 return 0;
41341 }
41342
41343-drm_ioctl_compat_t *drm_compat_ioctls[] = {
41344+drm_ioctl_compat_t drm_compat_ioctls[] = {
41345 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
41346 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
41347 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
41348@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
41349 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41350 {
41351 unsigned int nr = DRM_IOCTL_NR(cmd);
41352- drm_ioctl_compat_t *fn;
41353 int ret;
41354
41355 /* Assume that ioctls without an explicit compat routine will just
41356@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41357 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
41358 return drm_ioctl(filp, cmd, arg);
41359
41360- fn = drm_compat_ioctls[nr];
41361-
41362- if (fn != NULL)
41363- ret = (*fn) (filp, cmd, arg);
41364+ if (drm_compat_ioctls[nr] != NULL)
41365+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
41366 else
41367 ret = drm_ioctl(filp, cmd, arg);
41368
41369diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
41370index 40be746..fd78faf 100644
41371--- a/drivers/gpu/drm/drm_ioctl.c
41372+++ b/drivers/gpu/drm/drm_ioctl.c
41373@@ -642,7 +642,7 @@ long drm_ioctl(struct file *filp,
41374 struct drm_file *file_priv = filp->private_data;
41375 struct drm_device *dev;
41376 const struct drm_ioctl_desc *ioctl = NULL;
41377- drm_ioctl_t *func;
41378+ drm_ioctl_no_const_t func;
41379 unsigned int nr = DRM_IOCTL_NR(cmd);
41380 int retcode = -EINVAL;
41381 char stack_kdata[128];
41382diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
41383index d4d16ed..8fb0b51 100644
41384--- a/drivers/gpu/drm/i810/i810_drv.h
41385+++ b/drivers/gpu/drm/i810/i810_drv.h
41386@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
41387 int page_flipping;
41388
41389 wait_queue_head_t irq_queue;
41390- atomic_t irq_received;
41391- atomic_t irq_emitted;
41392+ atomic_unchecked_t irq_received;
41393+ atomic_unchecked_t irq_emitted;
41394
41395 int front_offset;
41396 } drm_i810_private_t;
41397diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
41398index 2d23e57..1c61d41 100644
41399--- a/drivers/gpu/drm/i915/i915_dma.c
41400+++ b/drivers/gpu/drm/i915/i915_dma.c
41401@@ -1292,7 +1292,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
41402 * locking inversion with the driver load path. And the access here is
41403 * completely racy anyway. So don't bother with locking for now.
41404 */
41405- return dev->open_count == 0;
41406+ return local_read(&dev->open_count) == 0;
41407 }
41408
41409 static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
41410diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
41411index 60998fc..3b244bc 100644
41412--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
41413+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
41414@@ -891,9 +891,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
41415
41416 static int
41417 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
41418- int count)
41419+ unsigned int count)
41420 {
41421- int i;
41422+ unsigned int i;
41423 unsigned relocs_total = 0;
41424 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
41425
41426diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
41427index 2e0613e..a8b94d9 100644
41428--- a/drivers/gpu/drm/i915/i915_ioc32.c
41429+++ b/drivers/gpu/drm/i915/i915_ioc32.c
41430@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
41431 (unsigned long)request);
41432 }
41433
41434-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
41435+static drm_ioctl_compat_t i915_compat_ioctls[] = {
41436 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
41437 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
41438 [DRM_I915_GETPARAM] = compat_i915_getparam,
41439@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
41440 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41441 {
41442 unsigned int nr = DRM_IOCTL_NR(cmd);
41443- drm_ioctl_compat_t *fn = NULL;
41444 int ret;
41445
41446 if (nr < DRM_COMMAND_BASE)
41447 return drm_compat_ioctl(filp, cmd, arg);
41448
41449- if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
41450- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
41451-
41452- if (fn != NULL)
41453+ if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls)) {
41454+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
41455 ret = (*fn) (filp, cmd, arg);
41456- else
41457+ } else
41458 ret = drm_ioctl(filp, cmd, arg);
41459
41460 return ret;
41461diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
41462index 7bd17b3..ffa0a11 100644
41463--- a/drivers/gpu/drm/i915/intel_display.c
41464+++ b/drivers/gpu/drm/i915/intel_display.c
41465@@ -12441,13 +12441,13 @@ struct intel_quirk {
41466 int subsystem_vendor;
41467 int subsystem_device;
41468 void (*hook)(struct drm_device *dev);
41469-};
41470+} __do_const;
41471
41472 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
41473 struct intel_dmi_quirk {
41474 void (*hook)(struct drm_device *dev);
41475 const struct dmi_system_id (*dmi_id_list)[];
41476-};
41477+} __do_const;
41478
41479 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
41480 {
41481@@ -12455,18 +12455,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
41482 return 1;
41483 }
41484
41485-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
41486+static const struct dmi_system_id intel_dmi_quirks_table[] = {
41487 {
41488- .dmi_id_list = &(const struct dmi_system_id[]) {
41489- {
41490- .callback = intel_dmi_reverse_brightness,
41491- .ident = "NCR Corporation",
41492- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
41493- DMI_MATCH(DMI_PRODUCT_NAME, ""),
41494- },
41495- },
41496- { } /* terminating entry */
41497+ .callback = intel_dmi_reverse_brightness,
41498+ .ident = "NCR Corporation",
41499+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
41500+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
41501 },
41502+ },
41503+ { } /* terminating entry */
41504+};
41505+
41506+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
41507+ {
41508+ .dmi_id_list = &intel_dmi_quirks_table,
41509 .hook = quirk_invert_brightness,
41510 },
41511 };
41512diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
41513index fe45321..836fdca 100644
41514--- a/drivers/gpu/drm/mga/mga_drv.h
41515+++ b/drivers/gpu/drm/mga/mga_drv.h
41516@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
41517 u32 clear_cmd;
41518 u32 maccess;
41519
41520- atomic_t vbl_received; /**< Number of vblanks received. */
41521+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
41522 wait_queue_head_t fence_queue;
41523- atomic_t last_fence_retired;
41524+ atomic_unchecked_t last_fence_retired;
41525 u32 next_fence_to_post;
41526
41527 unsigned int fb_cpp;
41528diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
41529index 729bfd5..ead8823 100644
41530--- a/drivers/gpu/drm/mga/mga_ioc32.c
41531+++ b/drivers/gpu/drm/mga/mga_ioc32.c
41532@@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
41533 return 0;
41534 }
41535
41536-drm_ioctl_compat_t *mga_compat_ioctls[] = {
41537+drm_ioctl_compat_t mga_compat_ioctls[] = {
41538 [DRM_MGA_INIT] = compat_mga_init,
41539 [DRM_MGA_GETPARAM] = compat_mga_getparam,
41540 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
41541@@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
41542 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41543 {
41544 unsigned int nr = DRM_IOCTL_NR(cmd);
41545- drm_ioctl_compat_t *fn = NULL;
41546 int ret;
41547
41548 if (nr < DRM_COMMAND_BASE)
41549 return drm_compat_ioctl(filp, cmd, arg);
41550
41551- if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls))
41552- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
41553-
41554- if (fn != NULL)
41555+ if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls)) {
41556+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
41557 ret = (*fn) (filp, cmd, arg);
41558- else
41559+ } else
41560 ret = drm_ioctl(filp, cmd, arg);
41561
41562 return ret;
41563diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
41564index 1b071b8..de8601a 100644
41565--- a/drivers/gpu/drm/mga/mga_irq.c
41566+++ b/drivers/gpu/drm/mga/mga_irq.c
41567@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
41568 if (crtc != 0)
41569 return 0;
41570
41571- return atomic_read(&dev_priv->vbl_received);
41572+ return atomic_read_unchecked(&dev_priv->vbl_received);
41573 }
41574
41575
41576@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
41577 /* VBLANK interrupt */
41578 if (status & MGA_VLINEPEN) {
41579 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
41580- atomic_inc(&dev_priv->vbl_received);
41581+ atomic_inc_unchecked(&dev_priv->vbl_received);
41582 drm_handle_vblank(dev, 0);
41583 handled = 1;
41584 }
41585@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
41586 if ((prim_start & ~0x03) != (prim_end & ~0x03))
41587 MGA_WRITE(MGA_PRIMEND, prim_end);
41588
41589- atomic_inc(&dev_priv->last_fence_retired);
41590+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
41591 wake_up(&dev_priv->fence_queue);
41592 handled = 1;
41593 }
41594@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
41595 * using fences.
41596 */
41597 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
41598- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
41599+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
41600 - *sequence) <= (1 << 23)));
41601
41602 *sequence = cur_fence;
41603diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
41604index dae2c96..324dbe4 100644
41605--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
41606+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
41607@@ -963,7 +963,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
41608 struct bit_table {
41609 const char id;
41610 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
41611-};
41612+} __no_const;
41613
41614 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
41615
41616diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
41617index b02b024..aed7bad 100644
41618--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
41619+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
41620@@ -119,7 +119,6 @@ struct nouveau_drm {
41621 struct drm_global_reference mem_global_ref;
41622 struct ttm_bo_global_ref bo_global_ref;
41623 struct ttm_bo_device bdev;
41624- atomic_t validate_sequence;
41625 int (*move)(struct nouveau_channel *,
41626 struct ttm_buffer_object *,
41627 struct ttm_mem_reg *, struct ttm_mem_reg *);
41628diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
41629index 462679a..88e32a7 100644
41630--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
41631+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
41632@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
41633 unsigned long arg)
41634 {
41635 unsigned int nr = DRM_IOCTL_NR(cmd);
41636- drm_ioctl_compat_t *fn = NULL;
41637+ drm_ioctl_compat_t fn = NULL;
41638 int ret;
41639
41640 if (nr < DRM_COMMAND_BASE)
41641diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
41642index 53874b7..1db0a68 100644
41643--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
41644+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
41645@@ -127,11 +127,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41646 }
41647
41648 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
41649- nouveau_vram_manager_init,
41650- nouveau_vram_manager_fini,
41651- nouveau_vram_manager_new,
41652- nouveau_vram_manager_del,
41653- nouveau_vram_manager_debug
41654+ .init = nouveau_vram_manager_init,
41655+ .takedown = nouveau_vram_manager_fini,
41656+ .get_node = nouveau_vram_manager_new,
41657+ .put_node = nouveau_vram_manager_del,
41658+ .debug = nouveau_vram_manager_debug
41659 };
41660
41661 static int
41662@@ -196,11 +196,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41663 }
41664
41665 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
41666- nouveau_gart_manager_init,
41667- nouveau_gart_manager_fini,
41668- nouveau_gart_manager_new,
41669- nouveau_gart_manager_del,
41670- nouveau_gart_manager_debug
41671+ .init = nouveau_gart_manager_init,
41672+ .takedown = nouveau_gart_manager_fini,
41673+ .get_node = nouveau_gart_manager_new,
41674+ .put_node = nouveau_gart_manager_del,
41675+ .debug = nouveau_gart_manager_debug
41676 };
41677
41678 /*XXX*/
41679@@ -270,11 +270,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41680 }
41681
41682 const struct ttm_mem_type_manager_func nv04_gart_manager = {
41683- nv04_gart_manager_init,
41684- nv04_gart_manager_fini,
41685- nv04_gart_manager_new,
41686- nv04_gart_manager_del,
41687- nv04_gart_manager_debug
41688+ .init = nv04_gart_manager_init,
41689+ .takedown = nv04_gart_manager_fini,
41690+ .get_node = nv04_gart_manager_new,
41691+ .put_node = nv04_gart_manager_del,
41692+ .debug = nv04_gart_manager_debug
41693 };
41694
41695 int
41696diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
41697index c7592ec..dd45ebc 100644
41698--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
41699+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
41700@@ -72,7 +72,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
41701 * locking inversion with the driver load path. And the access here is
41702 * completely racy anyway. So don't bother with locking for now.
41703 */
41704- return dev->open_count == 0;
41705+ return local_read(&dev->open_count) == 0;
41706 }
41707
41708 static const struct vga_switcheroo_client_ops
41709diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
41710index eb89653..613cf71 100644
41711--- a/drivers/gpu/drm/qxl/qxl_cmd.c
41712+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
41713@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
41714 int ret;
41715
41716 mutex_lock(&qdev->async_io_mutex);
41717- irq_num = atomic_read(&qdev->irq_received_io_cmd);
41718+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
41719 if (qdev->last_sent_io_cmd > irq_num) {
41720 if (intr)
41721 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
41722- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41723+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41724 else
41725 ret = wait_event_timeout(qdev->io_cmd_event,
41726- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41727+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41728 /* 0 is timeout, just bail the "hw" has gone away */
41729 if (ret <= 0)
41730 goto out;
41731- irq_num = atomic_read(&qdev->irq_received_io_cmd);
41732+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
41733 }
41734 outb(val, addr);
41735 qdev->last_sent_io_cmd = irq_num + 1;
41736 if (intr)
41737 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
41738- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41739+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41740 else
41741 ret = wait_event_timeout(qdev->io_cmd_event,
41742- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41743+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41744 out:
41745 if (ret > 0)
41746 ret = 0;
41747diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
41748index c3c2bbd..bc3c0fb 100644
41749--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
41750+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
41751@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
41752 struct drm_info_node *node = (struct drm_info_node *) m->private;
41753 struct qxl_device *qdev = node->minor->dev->dev_private;
41754
41755- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
41756- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
41757- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
41758- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
41759+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
41760+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
41761+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
41762+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
41763 seq_printf(m, "%d\n", qdev->irq_received_error);
41764 return 0;
41765 }
41766diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
41767index 36ed40b..0397633 100644
41768--- a/drivers/gpu/drm/qxl/qxl_drv.h
41769+++ b/drivers/gpu/drm/qxl/qxl_drv.h
41770@@ -290,10 +290,10 @@ struct qxl_device {
41771 unsigned int last_sent_io_cmd;
41772
41773 /* interrupt handling */
41774- atomic_t irq_received;
41775- atomic_t irq_received_display;
41776- atomic_t irq_received_cursor;
41777- atomic_t irq_received_io_cmd;
41778+ atomic_unchecked_t irq_received;
41779+ atomic_unchecked_t irq_received_display;
41780+ atomic_unchecked_t irq_received_cursor;
41781+ atomic_unchecked_t irq_received_io_cmd;
41782 unsigned irq_received_error;
41783 wait_queue_head_t display_event;
41784 wait_queue_head_t cursor_event;
41785diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
41786index b110883..dd06418 100644
41787--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
41788+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
41789@@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
41790
41791 /* TODO copy slow path code from i915 */
41792 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
41793- 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);
41794+ 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);
41795
41796 {
41797 struct qxl_drawable *draw = fb_cmd;
41798@@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
41799 struct drm_qxl_reloc reloc;
41800
41801 if (copy_from_user(&reloc,
41802- &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
41803+ &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
41804 sizeof(reloc))) {
41805 ret = -EFAULT;
41806 goto out_free_bos;
41807@@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
41808
41809 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
41810
41811- struct drm_qxl_command *commands =
41812- (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
41813+ struct drm_qxl_command __user *commands =
41814+ (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
41815
41816- if (copy_from_user(&user_cmd, &commands[cmd_num],
41817+ if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
41818 sizeof(user_cmd)))
41819 return -EFAULT;
41820
41821diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
41822index 0bf1e20..42a7310 100644
41823--- a/drivers/gpu/drm/qxl/qxl_irq.c
41824+++ b/drivers/gpu/drm/qxl/qxl_irq.c
41825@@ -36,19 +36,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
41826 if (!pending)
41827 return IRQ_NONE;
41828
41829- atomic_inc(&qdev->irq_received);
41830+ atomic_inc_unchecked(&qdev->irq_received);
41831
41832 if (pending & QXL_INTERRUPT_DISPLAY) {
41833- atomic_inc(&qdev->irq_received_display);
41834+ atomic_inc_unchecked(&qdev->irq_received_display);
41835 wake_up_all(&qdev->display_event);
41836 qxl_queue_garbage_collect(qdev, false);
41837 }
41838 if (pending & QXL_INTERRUPT_CURSOR) {
41839- atomic_inc(&qdev->irq_received_cursor);
41840+ atomic_inc_unchecked(&qdev->irq_received_cursor);
41841 wake_up_all(&qdev->cursor_event);
41842 }
41843 if (pending & QXL_INTERRUPT_IO_CMD) {
41844- atomic_inc(&qdev->irq_received_io_cmd);
41845+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
41846 wake_up_all(&qdev->io_cmd_event);
41847 }
41848 if (pending & QXL_INTERRUPT_ERROR) {
41849@@ -85,10 +85,10 @@ int qxl_irq_init(struct qxl_device *qdev)
41850 init_waitqueue_head(&qdev->io_cmd_event);
41851 INIT_WORK(&qdev->client_monitors_config_work,
41852 qxl_client_monitors_config_work_func);
41853- atomic_set(&qdev->irq_received, 0);
41854- atomic_set(&qdev->irq_received_display, 0);
41855- atomic_set(&qdev->irq_received_cursor, 0);
41856- atomic_set(&qdev->irq_received_io_cmd, 0);
41857+ atomic_set_unchecked(&qdev->irq_received, 0);
41858+ atomic_set_unchecked(&qdev->irq_received_display, 0);
41859+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
41860+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
41861 qdev->irq_received_error = 0;
41862 ret = drm_irq_install(qdev->ddev, qdev->ddev->pdev->irq);
41863 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
41864diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
41865index 71a1bae..cb1f103 100644
41866--- a/drivers/gpu/drm/qxl/qxl_ttm.c
41867+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
41868@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
41869 }
41870 }
41871
41872-static struct vm_operations_struct qxl_ttm_vm_ops;
41873+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
41874 static const struct vm_operations_struct *ttm_vm_ops;
41875
41876 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41877@@ -145,8 +145,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
41878 return r;
41879 if (unlikely(ttm_vm_ops == NULL)) {
41880 ttm_vm_ops = vma->vm_ops;
41881+ pax_open_kernel();
41882 qxl_ttm_vm_ops = *ttm_vm_ops;
41883 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
41884+ pax_close_kernel();
41885 }
41886 vma->vm_ops = &qxl_ttm_vm_ops;
41887 return 0;
41888@@ -555,25 +557,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
41889 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
41890 {
41891 #if defined(CONFIG_DEBUG_FS)
41892- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
41893- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
41894- unsigned i;
41895+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
41896+ {
41897+ .name = "qxl_mem_mm",
41898+ .show = &qxl_mm_dump_table,
41899+ },
41900+ {
41901+ .name = "qxl_surf_mm",
41902+ .show = &qxl_mm_dump_table,
41903+ }
41904+ };
41905
41906- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
41907- if (i == 0)
41908- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
41909- else
41910- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
41911- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
41912- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
41913- qxl_mem_types_list[i].driver_features = 0;
41914- if (i == 0)
41915- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41916- else
41917- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41918+ pax_open_kernel();
41919+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41920+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41921+ pax_close_kernel();
41922
41923- }
41924- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
41925+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
41926 #else
41927 return 0;
41928 #endif
41929diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
41930index 59459fe..be26b31 100644
41931--- a/drivers/gpu/drm/r128/r128_cce.c
41932+++ b/drivers/gpu/drm/r128/r128_cce.c
41933@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
41934
41935 /* GH: Simple idle check.
41936 */
41937- atomic_set(&dev_priv->idle_count, 0);
41938+ atomic_set_unchecked(&dev_priv->idle_count, 0);
41939
41940 /* We don't support anything other than bus-mastering ring mode,
41941 * but the ring can be in either AGP or PCI space for the ring
41942diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
41943index 5bf3f5f..7000661 100644
41944--- a/drivers/gpu/drm/r128/r128_drv.h
41945+++ b/drivers/gpu/drm/r128/r128_drv.h
41946@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
41947 int is_pci;
41948 unsigned long cce_buffers_offset;
41949
41950- atomic_t idle_count;
41951+ atomic_unchecked_t idle_count;
41952
41953 int page_flipping;
41954 int current_page;
41955 u32 crtc_offset;
41956 u32 crtc_offset_cntl;
41957
41958- atomic_t vbl_received;
41959+ atomic_unchecked_t vbl_received;
41960
41961 u32 color_fmt;
41962 unsigned int front_offset;
41963diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
41964index 663f38c..c689495 100644
41965--- a/drivers/gpu/drm/r128/r128_ioc32.c
41966+++ b/drivers/gpu/drm/r128/r128_ioc32.c
41967@@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
41968 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
41969 }
41970
41971-drm_ioctl_compat_t *r128_compat_ioctls[] = {
41972+drm_ioctl_compat_t r128_compat_ioctls[] = {
41973 [DRM_R128_INIT] = compat_r128_init,
41974 [DRM_R128_DEPTH] = compat_r128_depth,
41975 [DRM_R128_STIPPLE] = compat_r128_stipple,
41976@@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
41977 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41978 {
41979 unsigned int nr = DRM_IOCTL_NR(cmd);
41980- drm_ioctl_compat_t *fn = NULL;
41981 int ret;
41982
41983 if (nr < DRM_COMMAND_BASE)
41984 return drm_compat_ioctl(filp, cmd, arg);
41985
41986- if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls))
41987- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41988-
41989- if (fn != NULL)
41990+ if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls)) {
41991+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41992 ret = (*fn) (filp, cmd, arg);
41993- else
41994+ } else
41995 ret = drm_ioctl(filp, cmd, arg);
41996
41997 return ret;
41998diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
41999index c2ae496..30b5993 100644
42000--- a/drivers/gpu/drm/r128/r128_irq.c
42001+++ b/drivers/gpu/drm/r128/r128_irq.c
42002@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
42003 if (crtc != 0)
42004 return 0;
42005
42006- return atomic_read(&dev_priv->vbl_received);
42007+ return atomic_read_unchecked(&dev_priv->vbl_received);
42008 }
42009
42010 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
42011@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
42012 /* VBLANK interrupt */
42013 if (status & R128_CRTC_VBLANK_INT) {
42014 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
42015- atomic_inc(&dev_priv->vbl_received);
42016+ atomic_inc_unchecked(&dev_priv->vbl_received);
42017 drm_handle_vblank(dev, 0);
42018 return IRQ_HANDLED;
42019 }
42020diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
42021index 575e986..66e62ca 100644
42022--- a/drivers/gpu/drm/r128/r128_state.c
42023+++ b/drivers/gpu/drm/r128/r128_state.c
42024@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
42025
42026 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
42027 {
42028- if (atomic_read(&dev_priv->idle_count) == 0)
42029+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
42030 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
42031 else
42032- atomic_set(&dev_priv->idle_count, 0);
42033+ atomic_set_unchecked(&dev_priv->idle_count, 0);
42034 }
42035
42036 #endif
42037diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
42038index 4a85bb6..aaea819 100644
42039--- a/drivers/gpu/drm/radeon/mkregtable.c
42040+++ b/drivers/gpu/drm/radeon/mkregtable.c
42041@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
42042 regex_t mask_rex;
42043 regmatch_t match[4];
42044 char buf[1024];
42045- size_t end;
42046+ long end;
42047 int len;
42048 int done = 0;
42049 int r;
42050 unsigned o;
42051 struct offset *offset;
42052 char last_reg_s[10];
42053- int last_reg;
42054+ unsigned long last_reg;
42055
42056 if (regcomp
42057 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
42058diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
42059index 5d4416f..80b7fc4 100644
42060--- a/drivers/gpu/drm/radeon/radeon_device.c
42061+++ b/drivers/gpu/drm/radeon/radeon_device.c
42062@@ -1214,7 +1214,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
42063 * locking inversion with the driver load path. And the access here is
42064 * completely racy anyway. So don't bother with locking for now.
42065 */
42066- return dev->open_count == 0;
42067+ return local_read(&dev->open_count) == 0;
42068 }
42069
42070 static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = {
42071diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
42072index dafd812..1bf20c7 100644
42073--- a/drivers/gpu/drm/radeon/radeon_drv.h
42074+++ b/drivers/gpu/drm/radeon/radeon_drv.h
42075@@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
42076
42077 /* SW interrupt */
42078 wait_queue_head_t swi_queue;
42079- atomic_t swi_emitted;
42080+ atomic_unchecked_t swi_emitted;
42081 int vblank_crtc;
42082 uint32_t irq_enable_reg;
42083 uint32_t r500_disp_irq_reg;
42084diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
42085index 0b98ea1..0881827 100644
42086--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
42087+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
42088@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
42089 request = compat_alloc_user_space(sizeof(*request));
42090 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
42091 || __put_user(req32.param, &request->param)
42092- || __put_user((void __user *)(unsigned long)req32.value,
42093+ || __put_user((unsigned long)req32.value,
42094 &request->value))
42095 return -EFAULT;
42096
42097@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
42098 #define compat_radeon_cp_setparam NULL
42099 #endif /* X86_64 || IA64 */
42100
42101-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
42102+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
42103 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
42104 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
42105 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
42106@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
42107 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42108 {
42109 unsigned int nr = DRM_IOCTL_NR(cmd);
42110- drm_ioctl_compat_t *fn = NULL;
42111 int ret;
42112
42113 if (nr < DRM_COMMAND_BASE)
42114 return drm_compat_ioctl(filp, cmd, arg);
42115
42116- if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls))
42117- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
42118-
42119- if (fn != NULL)
42120+ if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls)) {
42121+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
42122 ret = (*fn) (filp, cmd, arg);
42123- else
42124+ } else
42125 ret = drm_ioctl(filp, cmd, arg);
42126
42127 return ret;
42128diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
42129index 244b19b..c19226d 100644
42130--- a/drivers/gpu/drm/radeon/radeon_irq.c
42131+++ b/drivers/gpu/drm/radeon/radeon_irq.c
42132@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
42133 unsigned int ret;
42134 RING_LOCALS;
42135
42136- atomic_inc(&dev_priv->swi_emitted);
42137- ret = atomic_read(&dev_priv->swi_emitted);
42138+ atomic_inc_unchecked(&dev_priv->swi_emitted);
42139+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
42140
42141 BEGIN_RING(4);
42142 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
42143@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
42144 drm_radeon_private_t *dev_priv =
42145 (drm_radeon_private_t *) dev->dev_private;
42146
42147- atomic_set(&dev_priv->swi_emitted, 0);
42148+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
42149 init_waitqueue_head(&dev_priv->swi_queue);
42150
42151 dev->max_vblank_count = 0x001fffff;
42152diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
42153index 23bb64f..69d7234 100644
42154--- a/drivers/gpu/drm/radeon/radeon_state.c
42155+++ b/drivers/gpu/drm/radeon/radeon_state.c
42156@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
42157 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
42158 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
42159
42160- if (copy_from_user(&depth_boxes, clear->depth_boxes,
42161+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
42162 sarea_priv->nbox * sizeof(depth_boxes[0])))
42163 return -EFAULT;
42164
42165@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
42166 {
42167 drm_radeon_private_t *dev_priv = dev->dev_private;
42168 drm_radeon_getparam_t *param = data;
42169- int value;
42170+ int value = 0;
42171
42172 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
42173
42174diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
42175index 72afe82..056a57a 100644
42176--- a/drivers/gpu/drm/radeon/radeon_ttm.c
42177+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
42178@@ -801,7 +801,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
42179 man->size = size >> PAGE_SHIFT;
42180 }
42181
42182-static struct vm_operations_struct radeon_ttm_vm_ops;
42183+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
42184 static const struct vm_operations_struct *ttm_vm_ops = NULL;
42185
42186 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
42187@@ -842,8 +842,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
42188 }
42189 if (unlikely(ttm_vm_ops == NULL)) {
42190 ttm_vm_ops = vma->vm_ops;
42191+ pax_open_kernel();
42192 radeon_ttm_vm_ops = *ttm_vm_ops;
42193 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
42194+ pax_close_kernel();
42195 }
42196 vma->vm_ops = &radeon_ttm_vm_ops;
42197 return 0;
42198diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
42199index 6553fd2..aecd29c 100644
42200--- a/drivers/gpu/drm/tegra/dc.c
42201+++ b/drivers/gpu/drm/tegra/dc.c
42202@@ -1243,7 +1243,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
42203 }
42204
42205 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
42206- dc->debugfs_files[i].data = dc;
42207+ *(void **)&dc->debugfs_files[i].data = dc;
42208
42209 err = drm_debugfs_create_files(dc->debugfs_files,
42210 ARRAY_SIZE(debugfs_files),
42211diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
42212index f787445..2df2c65 100644
42213--- a/drivers/gpu/drm/tegra/dsi.c
42214+++ b/drivers/gpu/drm/tegra/dsi.c
42215@@ -41,7 +41,7 @@ struct tegra_dsi {
42216 struct clk *clk_lp;
42217 struct clk *clk;
42218
42219- struct drm_info_list *debugfs_files;
42220+ drm_info_list_no_const *debugfs_files;
42221 struct drm_minor *minor;
42222 struct dentry *debugfs;
42223
42224diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
42225index ffe2654..03c7b1c 100644
42226--- a/drivers/gpu/drm/tegra/hdmi.c
42227+++ b/drivers/gpu/drm/tegra/hdmi.c
42228@@ -60,7 +60,7 @@ struct tegra_hdmi {
42229 bool stereo;
42230 bool dvi;
42231
42232- struct drm_info_list *debugfs_files;
42233+ drm_info_list_no_const *debugfs_files;
42234 struct drm_minor *minor;
42235 struct dentry *debugfs;
42236 };
42237diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
42238index 9e103a48..0e117f3 100644
42239--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
42240+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
42241@@ -147,10 +147,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
42242 }
42243
42244 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
42245- ttm_bo_man_init,
42246- ttm_bo_man_takedown,
42247- ttm_bo_man_get_node,
42248- ttm_bo_man_put_node,
42249- ttm_bo_man_debug
42250+ .init = ttm_bo_man_init,
42251+ .takedown = ttm_bo_man_takedown,
42252+ .get_node = ttm_bo_man_get_node,
42253+ .put_node = ttm_bo_man_put_node,
42254+ .debug = ttm_bo_man_debug
42255 };
42256 EXPORT_SYMBOL(ttm_bo_manager_func);
42257diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
42258index dbc2def..0a9f710 100644
42259--- a/drivers/gpu/drm/ttm/ttm_memory.c
42260+++ b/drivers/gpu/drm/ttm/ttm_memory.c
42261@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
42262 zone->glob = glob;
42263 glob->zone_kernel = zone;
42264 ret = kobject_init_and_add(
42265- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
42266+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
42267 if (unlikely(ret != 0)) {
42268 kobject_put(&zone->kobj);
42269 return ret;
42270@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
42271 zone->glob = glob;
42272 glob->zone_dma32 = zone;
42273 ret = kobject_init_and_add(
42274- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
42275+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
42276 if (unlikely(ret != 0)) {
42277 kobject_put(&zone->kobj);
42278 return ret;
42279diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
42280index 09874d6..d6da1de 100644
42281--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
42282+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
42283@@ -54,7 +54,7 @@
42284
42285 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
42286 #define SMALL_ALLOCATION 16
42287-#define FREE_ALL_PAGES (~0U)
42288+#define FREE_ALL_PAGES (~0UL)
42289 /* times are in msecs */
42290 #define PAGE_FREE_INTERVAL 1000
42291
42292@@ -299,14 +299,13 @@ static void ttm_pool_update_free_locked(struct ttm_page_pool *pool,
42293 * @free_all: If set to true will free all pages in pool
42294 * @gfp: GFP flags.
42295 **/
42296-static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free,
42297+static unsigned long ttm_page_pool_free(struct ttm_page_pool *pool, unsigned long nr_free,
42298 gfp_t gfp)
42299 {
42300 unsigned long irq_flags;
42301 struct page *p;
42302 struct page **pages_to_free;
42303- unsigned freed_pages = 0,
42304- npages_to_free = nr_free;
42305+ unsigned long freed_pages = 0, npages_to_free = nr_free;
42306
42307 if (NUM_PAGES_TO_ALLOC < nr_free)
42308 npages_to_free = NUM_PAGES_TO_ALLOC;
42309@@ -366,7 +365,8 @@ restart:
42310 __list_del(&p->lru, &pool->list);
42311
42312 ttm_pool_update_free_locked(pool, freed_pages);
42313- nr_free -= freed_pages;
42314+ if (likely(nr_free != FREE_ALL_PAGES))
42315+ nr_free -= freed_pages;
42316 }
42317
42318 spin_unlock_irqrestore(&pool->lock, irq_flags);
42319@@ -395,7 +395,7 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
42320 unsigned i;
42321 unsigned pool_offset;
42322 struct ttm_page_pool *pool;
42323- int shrink_pages = sc->nr_to_scan;
42324+ unsigned long shrink_pages = sc->nr_to_scan;
42325 unsigned long freed = 0;
42326
42327 if (!mutex_trylock(&lock))
42328@@ -403,7 +403,7 @@ ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
42329 pool_offset = ++start_pool % NUM_POOLS;
42330 /* select start pool in round robin fashion */
42331 for (i = 0; i < NUM_POOLS; ++i) {
42332- unsigned nr_free = shrink_pages;
42333+ unsigned long nr_free = shrink_pages;
42334 if (shrink_pages == 0)
42335 break;
42336 pool = &_manager->pools[(i + pool_offset)%NUM_POOLS];
42337@@ -669,7 +669,7 @@ out:
42338 }
42339
42340 /* Put all pages in pages list to correct pool to wait for reuse */
42341-static void ttm_put_pages(struct page **pages, unsigned npages, int flags,
42342+static void ttm_put_pages(struct page **pages, unsigned long npages, int flags,
42343 enum ttm_caching_state cstate)
42344 {
42345 unsigned long irq_flags;
42346@@ -724,7 +724,7 @@ static int ttm_get_pages(struct page **pages, unsigned npages, int flags,
42347 struct list_head plist;
42348 struct page *p = NULL;
42349 gfp_t gfp_flags = GFP_USER;
42350- unsigned count;
42351+ unsigned long count;
42352 int r;
42353
42354 /* set zero flag for page allocation if required */
42355diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
42356index c96db43..c367557 100644
42357--- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
42358+++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
42359@@ -56,7 +56,7 @@
42360
42361 #define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *))
42362 #define SMALL_ALLOCATION 4
42363-#define FREE_ALL_PAGES (~0U)
42364+#define FREE_ALL_PAGES (~0UL)
42365 /* times are in msecs */
42366 #define IS_UNDEFINED (0)
42367 #define IS_WC (1<<1)
42368@@ -413,15 +413,14 @@ static void ttm_dma_page_put(struct dma_pool *pool, struct dma_page *d_page)
42369 * @nr_free: If set to true will free all pages in pool
42370 * @gfp: GFP flags.
42371 **/
42372-static unsigned ttm_dma_page_pool_free(struct dma_pool *pool, unsigned nr_free,
42373+static unsigned long ttm_dma_page_pool_free(struct dma_pool *pool, unsigned long nr_free,
42374 gfp_t gfp)
42375 {
42376 unsigned long irq_flags;
42377 struct dma_page *dma_p, *tmp;
42378 struct page **pages_to_free;
42379 struct list_head d_pages;
42380- unsigned freed_pages = 0,
42381- npages_to_free = nr_free;
42382+ unsigned long freed_pages = 0, npages_to_free = nr_free;
42383
42384 if (NUM_PAGES_TO_ALLOC < nr_free)
42385 npages_to_free = NUM_PAGES_TO_ALLOC;
42386@@ -494,7 +493,8 @@ restart:
42387 /* remove range of pages from the pool */
42388 if (freed_pages) {
42389 ttm_pool_update_free_locked(pool, freed_pages);
42390- nr_free -= freed_pages;
42391+ if (likely(nr_free != FREE_ALL_PAGES))
42392+ nr_free -= freed_pages;
42393 }
42394
42395 spin_unlock_irqrestore(&pool->lock, irq_flags);
42396@@ -929,7 +929,7 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)
42397 struct dma_page *d_page, *next;
42398 enum pool_type type;
42399 bool is_cached = false;
42400- unsigned count = 0, i, npages = 0;
42401+ unsigned long count = 0, i, npages = 0;
42402 unsigned long irq_flags;
42403
42404 type = ttm_to_type(ttm->page_flags, ttm->caching_state);
42405@@ -1007,7 +1007,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
42406 static unsigned start_pool;
42407 unsigned idx = 0;
42408 unsigned pool_offset;
42409- unsigned shrink_pages = sc->nr_to_scan;
42410+ unsigned long shrink_pages = sc->nr_to_scan;
42411 struct device_pools *p;
42412 unsigned long freed = 0;
42413
42414@@ -1020,7 +1020,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
42415 goto out;
42416 pool_offset = ++start_pool % _manager->npools;
42417 list_for_each_entry(p, &_manager->pools, pools) {
42418- unsigned nr_free;
42419+ unsigned long nr_free;
42420
42421 if (!p->dev)
42422 continue;
42423@@ -1034,7 +1034,7 @@ ttm_dma_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
42424 sc->gfp_mask);
42425 freed += nr_free - shrink_pages;
42426
42427- pr_debug("%s: (%s:%d) Asked to shrink %d, have %d more to go\n",
42428+ pr_debug("%s: (%s:%d) Asked to shrink %lu, have %lu more to go\n",
42429 p->pool->dev_name, p->pool->name, current->pid,
42430 nr_free, shrink_pages);
42431 }
42432diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
42433index d1da339..829235e 100644
42434--- a/drivers/gpu/drm/udl/udl_fb.c
42435+++ b/drivers/gpu/drm/udl/udl_fb.c
42436@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
42437 fb_deferred_io_cleanup(info);
42438 kfree(info->fbdefio);
42439 info->fbdefio = NULL;
42440- info->fbops->fb_mmap = udl_fb_mmap;
42441 }
42442
42443 pr_warn("released /dev/fb%d user=%d count=%d\n",
42444diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
42445index ad02732..144f5ed 100644
42446--- a/drivers/gpu/drm/via/via_drv.h
42447+++ b/drivers/gpu/drm/via/via_drv.h
42448@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
42449 typedef uint32_t maskarray_t[5];
42450
42451 typedef struct drm_via_irq {
42452- atomic_t irq_received;
42453+ atomic_unchecked_t irq_received;
42454 uint32_t pending_mask;
42455 uint32_t enable_mask;
42456 wait_queue_head_t irq_queue;
42457@@ -75,7 +75,7 @@ typedef struct drm_via_private {
42458 struct timeval last_vblank;
42459 int last_vblank_valid;
42460 unsigned usec_per_vblank;
42461- atomic_t vbl_received;
42462+ atomic_unchecked_t vbl_received;
42463 drm_via_state_t hc_state;
42464 char pci_buf[VIA_PCI_BUF_SIZE];
42465 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
42466diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
42467index 1319433..a993b0c 100644
42468--- a/drivers/gpu/drm/via/via_irq.c
42469+++ b/drivers/gpu/drm/via/via_irq.c
42470@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
42471 if (crtc != 0)
42472 return 0;
42473
42474- return atomic_read(&dev_priv->vbl_received);
42475+ return atomic_read_unchecked(&dev_priv->vbl_received);
42476 }
42477
42478 irqreturn_t via_driver_irq_handler(int irq, void *arg)
42479@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
42480
42481 status = VIA_READ(VIA_REG_INTERRUPT);
42482 if (status & VIA_IRQ_VBLANK_PENDING) {
42483- atomic_inc(&dev_priv->vbl_received);
42484- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
42485+ atomic_inc_unchecked(&dev_priv->vbl_received);
42486+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
42487 do_gettimeofday(&cur_vblank);
42488 if (dev_priv->last_vblank_valid) {
42489 dev_priv->usec_per_vblank =
42490@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
42491 dev_priv->last_vblank = cur_vblank;
42492 dev_priv->last_vblank_valid = 1;
42493 }
42494- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
42495+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
42496 DRM_DEBUG("US per vblank is: %u\n",
42497 dev_priv->usec_per_vblank);
42498 }
42499@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
42500
42501 for (i = 0; i < dev_priv->num_irqs; ++i) {
42502 if (status & cur_irq->pending_mask) {
42503- atomic_inc(&cur_irq->irq_received);
42504+ atomic_inc_unchecked(&cur_irq->irq_received);
42505 wake_up(&cur_irq->irq_queue);
42506 handled = 1;
42507 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
42508@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
42509 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
42510 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
42511 masks[irq][4]));
42512- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
42513+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
42514 } else {
42515 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
42516 (((cur_irq_sequence =
42517- atomic_read(&cur_irq->irq_received)) -
42518+ atomic_read_unchecked(&cur_irq->irq_received)) -
42519 *sequence) <= (1 << 23)));
42520 }
42521 *sequence = cur_irq_sequence;
42522@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
42523 }
42524
42525 for (i = 0; i < dev_priv->num_irqs; ++i) {
42526- atomic_set(&cur_irq->irq_received, 0);
42527+ atomic_set_unchecked(&cur_irq->irq_received, 0);
42528 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
42529 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
42530 init_waitqueue_head(&cur_irq->irq_queue);
42531@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
42532 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
42533 case VIA_IRQ_RELATIVE:
42534 irqwait->request.sequence +=
42535- atomic_read(&cur_irq->irq_received);
42536+ atomic_read_unchecked(&cur_irq->irq_received);
42537 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
42538 case VIA_IRQ_ABSOLUTE:
42539 break;
42540diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
42541index 99f7317..33a835b 100644
42542--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
42543+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
42544@@ -447,7 +447,7 @@ struct vmw_private {
42545 * Fencing and IRQs.
42546 */
42547
42548- atomic_t marker_seq;
42549+ atomic_unchecked_t marker_seq;
42550 wait_queue_head_t fence_queue;
42551 wait_queue_head_t fifo_queue;
42552 int fence_queue_waiters; /* Protected by hw_mutex */
42553diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
42554index 6eae14d..aa311b3 100644
42555--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
42556+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
42557@@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
42558 (unsigned int) min,
42559 (unsigned int) fifo->capabilities);
42560
42561- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
42562+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
42563 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
42564 vmw_marker_queue_init(&fifo->marker_queue);
42565 return vmw_fifo_send_fence(dev_priv, &dummy);
42566@@ -373,7 +373,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
42567 if (reserveable)
42568 iowrite32(bytes, fifo_mem +
42569 SVGA_FIFO_RESERVED);
42570- return fifo_mem + (next_cmd >> 2);
42571+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
42572 } else {
42573 need_bounce = true;
42574 }
42575@@ -493,7 +493,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
42576
42577 fm = vmw_fifo_reserve(dev_priv, bytes);
42578 if (unlikely(fm == NULL)) {
42579- *seqno = atomic_read(&dev_priv->marker_seq);
42580+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
42581 ret = -ENOMEM;
42582 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
42583 false, 3*HZ);
42584@@ -501,7 +501,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
42585 }
42586
42587 do {
42588- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
42589+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
42590 } while (*seqno == 0);
42591
42592 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
42593diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
42594index 26f8bdd..90a0008 100644
42595--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
42596+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
42597@@ -165,9 +165,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
42598 }
42599
42600 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
42601- vmw_gmrid_man_init,
42602- vmw_gmrid_man_takedown,
42603- vmw_gmrid_man_get_node,
42604- vmw_gmrid_man_put_node,
42605- vmw_gmrid_man_debug
42606+ .init = vmw_gmrid_man_init,
42607+ .takedown = vmw_gmrid_man_takedown,
42608+ .get_node = vmw_gmrid_man_get_node,
42609+ .put_node = vmw_gmrid_man_put_node,
42610+ .debug = vmw_gmrid_man_debug
42611 };
42612diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
42613index 37881ec..319065d 100644
42614--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
42615+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
42616@@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
42617 int ret;
42618
42619 num_clips = arg->num_clips;
42620- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
42621+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
42622
42623 if (unlikely(num_clips == 0))
42624 return 0;
42625@@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
42626 int ret;
42627
42628 num_clips = arg->num_clips;
42629- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
42630+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
42631
42632 if (unlikely(num_clips == 0))
42633 return 0;
42634diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
42635index 0c42376..6febe77 100644
42636--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
42637+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
42638@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
42639 * emitted. Then the fence is stale and signaled.
42640 */
42641
42642- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
42643+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
42644 > VMW_FENCE_WRAP);
42645
42646 return ret;
42647@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
42648
42649 if (fifo_idle)
42650 down_read(&fifo_state->rwsem);
42651- signal_seq = atomic_read(&dev_priv->marker_seq);
42652+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
42653 ret = 0;
42654
42655 for (;;) {
42656diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
42657index efd1ffd..0ae13ca 100644
42658--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
42659+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
42660@@ -135,7 +135,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
42661 while (!vmw_lag_lt(queue, us)) {
42662 spin_lock(&queue->lock);
42663 if (list_empty(&queue->head))
42664- seqno = atomic_read(&dev_priv->marker_seq);
42665+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
42666 else {
42667 marker = list_first_entry(&queue->head,
42668 struct vmw_marker, head);
42669diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
42670index 37ac7b5..d52a5c9 100644
42671--- a/drivers/gpu/vga/vga_switcheroo.c
42672+++ b/drivers/gpu/vga/vga_switcheroo.c
42673@@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
42674
42675 /* this version is for the case where the power switch is separate
42676 to the device being powered down. */
42677-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
42678+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
42679 {
42680 /* copy over all the bus versions */
42681 if (dev->bus && dev->bus->pm) {
42682@@ -695,7 +695,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
42683 return ret;
42684 }
42685
42686-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
42687+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
42688 {
42689 /* copy over all the bus versions */
42690 if (dev->bus && dev->bus->pm) {
42691diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
42692index 12b6e67..ddd983c 100644
42693--- a/drivers/hid/hid-core.c
42694+++ b/drivers/hid/hid-core.c
42695@@ -2500,7 +2500,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
42696
42697 int hid_add_device(struct hid_device *hdev)
42698 {
42699- static atomic_t id = ATOMIC_INIT(0);
42700+ static atomic_unchecked_t id = ATOMIC_INIT(0);
42701 int ret;
42702
42703 if (WARN_ON(hdev->status & HID_STAT_ADDED))
42704@@ -2542,7 +2542,7 @@ int hid_add_device(struct hid_device *hdev)
42705 /* XXX hack, any other cleaner solution after the driver core
42706 * is converted to allow more than 20 bytes as the device name? */
42707 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
42708- hdev->vendor, hdev->product, atomic_inc_return(&id));
42709+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
42710
42711 hid_debug_register(hdev, dev_name(&hdev->dev));
42712 ret = device_add(&hdev->dev);
42713diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
42714index 9bf8637..f462416 100644
42715--- a/drivers/hid/hid-logitech-dj.c
42716+++ b/drivers/hid/hid-logitech-dj.c
42717@@ -682,6 +682,12 @@ static int logi_dj_raw_event(struct hid_device *hdev,
42718 * device (via hid_input_report() ) and return 1 so hid-core does not do
42719 * anything else with it.
42720 */
42721+ if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
42722+ (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
42723+ dev_err(&hdev->dev, "%s: invalid device index:%d\n",
42724+ __func__, dj_report->device_index);
42725+ return false;
42726+ }
42727
42728 /* case 1) */
42729 if (data[0] != REPORT_ID_DJ_SHORT)
42730diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
42731index c13fb5b..55a3802 100644
42732--- a/drivers/hid/hid-wiimote-debug.c
42733+++ b/drivers/hid/hid-wiimote-debug.c
42734@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
42735 else if (size == 0)
42736 return -EIO;
42737
42738- if (copy_to_user(u, buf, size))
42739+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
42740 return -EFAULT;
42741
42742 *off += size;
42743diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
42744index 0cb92e3..c7d453d 100644
42745--- a/drivers/hid/uhid.c
42746+++ b/drivers/hid/uhid.c
42747@@ -47,7 +47,7 @@ struct uhid_device {
42748 struct mutex report_lock;
42749 wait_queue_head_t report_wait;
42750 atomic_t report_done;
42751- atomic_t report_id;
42752+ atomic_unchecked_t report_id;
42753 struct uhid_event report_buf;
42754 };
42755
42756@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
42757
42758 spin_lock_irqsave(&uhid->qlock, flags);
42759 ev->type = UHID_FEATURE;
42760- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
42761+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
42762 ev->u.feature.rnum = rnum;
42763 ev->u.feature.rtype = report_type;
42764
42765@@ -538,7 +538,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
42766 spin_lock_irqsave(&uhid->qlock, flags);
42767
42768 /* id for old report; drop it silently */
42769- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
42770+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
42771 goto unlock;
42772 if (atomic_read(&uhid->report_done))
42773 goto unlock;
42774diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
42775index 19bad59..ca24eaf 100644
42776--- a/drivers/hv/channel.c
42777+++ b/drivers/hv/channel.c
42778@@ -366,8 +366,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
42779 unsigned long flags;
42780 int ret = 0;
42781
42782- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
42783- atomic_inc(&vmbus_connection.next_gpadl_handle);
42784+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
42785+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
42786
42787 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
42788 if (ret)
42789diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
42790index 3e4235c..877d0e5 100644
42791--- a/drivers/hv/hv.c
42792+++ b/drivers/hv/hv.c
42793@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
42794 u64 output_address = (output) ? virt_to_phys(output) : 0;
42795 u32 output_address_hi = output_address >> 32;
42796 u32 output_address_lo = output_address & 0xFFFFFFFF;
42797- void *hypercall_page = hv_context.hypercall_page;
42798+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
42799
42800 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
42801 "=a"(hv_status_lo) : "d" (control_hi),
42802@@ -156,7 +156,7 @@ int hv_init(void)
42803 /* See if the hypercall page is already set */
42804 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
42805
42806- virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
42807+ virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
42808
42809 if (!virtaddr)
42810 goto cleanup;
42811diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
42812index 5e90c5d..d8fcefb 100644
42813--- a/drivers/hv/hv_balloon.c
42814+++ b/drivers/hv/hv_balloon.c
42815@@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
42816
42817 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
42818 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
42819-static atomic_t trans_id = ATOMIC_INIT(0);
42820+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
42821
42822 static int dm_ring_size = (5 * PAGE_SIZE);
42823
42824@@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
42825 pr_info("Memory hot add failed\n");
42826
42827 dm->state = DM_INITIALIZED;
42828- resp.hdr.trans_id = atomic_inc_return(&trans_id);
42829+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42830 vmbus_sendpacket(dm->dev->channel, &resp,
42831 sizeof(struct dm_hot_add_response),
42832 (unsigned long)NULL,
42833@@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
42834 memset(&status, 0, sizeof(struct dm_status));
42835 status.hdr.type = DM_STATUS_REPORT;
42836 status.hdr.size = sizeof(struct dm_status);
42837- status.hdr.trans_id = atomic_inc_return(&trans_id);
42838+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42839
42840 /*
42841 * The host expects the guest to report free memory.
42842@@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
42843 * send the status. This can happen if we were interrupted
42844 * after we picked our transaction ID.
42845 */
42846- if (status.hdr.trans_id != atomic_read(&trans_id))
42847+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
42848 return;
42849
42850 /*
42851@@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
42852 */
42853
42854 do {
42855- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
42856+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42857 ret = vmbus_sendpacket(dm_device.dev->channel,
42858 bl_resp,
42859 bl_resp->hdr.size,
42860@@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
42861
42862 memset(&resp, 0, sizeof(struct dm_unballoon_response));
42863 resp.hdr.type = DM_UNBALLOON_RESPONSE;
42864- resp.hdr.trans_id = atomic_inc_return(&trans_id);
42865+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42866 resp.hdr.size = sizeof(struct dm_unballoon_response);
42867
42868 vmbus_sendpacket(dm_device.dev->channel, &resp,
42869@@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
42870 memset(&version_req, 0, sizeof(struct dm_version_request));
42871 version_req.hdr.type = DM_VERSION_REQUEST;
42872 version_req.hdr.size = sizeof(struct dm_version_request);
42873- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42874+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42875 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
42876 version_req.is_last_attempt = 1;
42877
42878@@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
42879 memset(&version_req, 0, sizeof(struct dm_version_request));
42880 version_req.hdr.type = DM_VERSION_REQUEST;
42881 version_req.hdr.size = sizeof(struct dm_version_request);
42882- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42883+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42884 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
42885 version_req.is_last_attempt = 0;
42886
42887@@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
42888 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
42889 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
42890 cap_msg.hdr.size = sizeof(struct dm_capabilities);
42891- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
42892+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42893
42894 cap_msg.caps.cap_bits.balloon = 1;
42895 cap_msg.caps.cap_bits.hot_add = 1;
42896diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
42897index c386d8d..d6004c4 100644
42898--- a/drivers/hv/hyperv_vmbus.h
42899+++ b/drivers/hv/hyperv_vmbus.h
42900@@ -611,7 +611,7 @@ enum vmbus_connect_state {
42901 struct vmbus_connection {
42902 enum vmbus_connect_state conn_state;
42903
42904- atomic_t next_gpadl_handle;
42905+ atomic_unchecked_t next_gpadl_handle;
42906
42907 /*
42908 * Represents channel interrupts. Each bit position represents a
42909diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
42910index 4d6b269..2e23b86 100644
42911--- a/drivers/hv/vmbus_drv.c
42912+++ b/drivers/hv/vmbus_drv.c
42913@@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
42914 {
42915 int ret = 0;
42916
42917- static atomic_t device_num = ATOMIC_INIT(0);
42918+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
42919
42920 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
42921- atomic_inc_return(&device_num));
42922+ atomic_inc_return_unchecked(&device_num));
42923
42924 child_device_obj->device.bus = &hv_bus;
42925 child_device_obj->device.parent = &hv_acpi_dev->dev;
42926diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
42927index 579bdf9..75118b5 100644
42928--- a/drivers/hwmon/acpi_power_meter.c
42929+++ b/drivers/hwmon/acpi_power_meter.c
42930@@ -116,7 +116,7 @@ struct sensor_template {
42931 struct device_attribute *devattr,
42932 const char *buf, size_t count);
42933 int index;
42934-};
42935+} __do_const;
42936
42937 /* Averaging interval */
42938 static int update_avg_interval(struct acpi_power_meter_resource *resource)
42939@@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
42940 struct sensor_template *attrs)
42941 {
42942 struct device *dev = &resource->acpi_dev->dev;
42943- struct sensor_device_attribute *sensors =
42944+ sensor_device_attribute_no_const *sensors =
42945 &resource->sensors[resource->num_sensors];
42946 int res = 0;
42947
42948diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
42949index 3288f13..71cfb4e 100644
42950--- a/drivers/hwmon/applesmc.c
42951+++ b/drivers/hwmon/applesmc.c
42952@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
42953 {
42954 struct applesmc_node_group *grp;
42955 struct applesmc_dev_attr *node;
42956- struct attribute *attr;
42957+ attribute_no_const *attr;
42958 int ret, i;
42959
42960 for (grp = groups; grp->format; grp++) {
42961diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
42962index cccef87..06ce8ec 100644
42963--- a/drivers/hwmon/asus_atk0110.c
42964+++ b/drivers/hwmon/asus_atk0110.c
42965@@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
42966 struct atk_sensor_data {
42967 struct list_head list;
42968 struct atk_data *data;
42969- struct device_attribute label_attr;
42970- struct device_attribute input_attr;
42971- struct device_attribute limit1_attr;
42972- struct device_attribute limit2_attr;
42973+ device_attribute_no_const label_attr;
42974+ device_attribute_no_const input_attr;
42975+ device_attribute_no_const limit1_attr;
42976+ device_attribute_no_const limit2_attr;
42977 char label_attr_name[ATTR_NAME_SIZE];
42978 char input_attr_name[ATTR_NAME_SIZE];
42979 char limit1_attr_name[ATTR_NAME_SIZE];
42980@@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
42981 static struct device_attribute atk_name_attr =
42982 __ATTR(name, 0444, atk_name_show, NULL);
42983
42984-static void atk_init_attribute(struct device_attribute *attr, char *name,
42985+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
42986 sysfs_show_func show)
42987 {
42988 sysfs_attr_init(&attr->attr);
42989diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
42990index d76f0b7..55ae976 100644
42991--- a/drivers/hwmon/coretemp.c
42992+++ b/drivers/hwmon/coretemp.c
42993@@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
42994 return NOTIFY_OK;
42995 }
42996
42997-static struct notifier_block coretemp_cpu_notifier __refdata = {
42998+static struct notifier_block coretemp_cpu_notifier = {
42999 .notifier_call = coretemp_cpu_callback,
43000 };
43001
43002diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
43003index 7a8a6fb..015c1fd 100644
43004--- a/drivers/hwmon/ibmaem.c
43005+++ b/drivers/hwmon/ibmaem.c
43006@@ -924,7 +924,7 @@ static int aem_register_sensors(struct aem_data *data,
43007 struct aem_rw_sensor_template *rw)
43008 {
43009 struct device *dev = &data->pdev->dev;
43010- struct sensor_device_attribute *sensors = data->sensors;
43011+ sensor_device_attribute_no_const *sensors = data->sensors;
43012 int err;
43013
43014 /* Set up read-only sensors */
43015diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
43016index 14c82da..09b25d7 100644
43017--- a/drivers/hwmon/iio_hwmon.c
43018+++ b/drivers/hwmon/iio_hwmon.c
43019@@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
43020 {
43021 struct device *dev = &pdev->dev;
43022 struct iio_hwmon_state *st;
43023- struct sensor_device_attribute *a;
43024+ sensor_device_attribute_no_const *a;
43025 int ret, i;
43026 int in_i = 1, temp_i = 1, curr_i = 1;
43027 enum iio_chan_type type;
43028diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
43029index 7710f46..427a28d 100644
43030--- a/drivers/hwmon/nct6683.c
43031+++ b/drivers/hwmon/nct6683.c
43032@@ -397,11 +397,11 @@ static struct attribute_group *
43033 nct6683_create_attr_group(struct device *dev, struct sensor_template_group *tg,
43034 int repeat)
43035 {
43036- struct sensor_device_attribute_2 *a2;
43037- struct sensor_device_attribute *a;
43038+ sensor_device_attribute_2_no_const *a2;
43039+ sensor_device_attribute_no_const *a;
43040 struct sensor_device_template **t;
43041 struct sensor_device_attr_u *su;
43042- struct attribute_group *group;
43043+ attribute_group_no_const *group;
43044 struct attribute **attrs;
43045 int i, j, count;
43046
43047diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
43048index 504cbdd..35d6f25 100644
43049--- a/drivers/hwmon/nct6775.c
43050+++ b/drivers/hwmon/nct6775.c
43051@@ -943,10 +943,10 @@ static struct attribute_group *
43052 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
43053 int repeat)
43054 {
43055- struct attribute_group *group;
43056+ attribute_group_no_const *group;
43057 struct sensor_device_attr_u *su;
43058- struct sensor_device_attribute *a;
43059- struct sensor_device_attribute_2 *a2;
43060+ sensor_device_attribute_no_const *a;
43061+ sensor_device_attribute_2_no_const *a2;
43062 struct attribute **attrs;
43063 struct sensor_device_template **t;
43064 int i, count;
43065diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
43066index 291d11f..3f0dbbd 100644
43067--- a/drivers/hwmon/pmbus/pmbus_core.c
43068+++ b/drivers/hwmon/pmbus/pmbus_core.c
43069@@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
43070 return 0;
43071 }
43072
43073-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
43074+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
43075 const char *name,
43076 umode_t mode,
43077 ssize_t (*show)(struct device *dev,
43078@@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
43079 dev_attr->store = store;
43080 }
43081
43082-static void pmbus_attr_init(struct sensor_device_attribute *a,
43083+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
43084 const char *name,
43085 umode_t mode,
43086 ssize_t (*show)(struct device *dev,
43087@@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
43088 u16 reg, u8 mask)
43089 {
43090 struct pmbus_boolean *boolean;
43091- struct sensor_device_attribute *a;
43092+ sensor_device_attribute_no_const *a;
43093
43094 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
43095 if (!boolean)
43096@@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
43097 bool update, bool readonly)
43098 {
43099 struct pmbus_sensor *sensor;
43100- struct device_attribute *a;
43101+ device_attribute_no_const *a;
43102
43103 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
43104 if (!sensor)
43105@@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
43106 const char *lstring, int index)
43107 {
43108 struct pmbus_label *label;
43109- struct device_attribute *a;
43110+ device_attribute_no_const *a;
43111
43112 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
43113 if (!label)
43114diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
43115index 97cd45a..ac54d8b 100644
43116--- a/drivers/hwmon/sht15.c
43117+++ b/drivers/hwmon/sht15.c
43118@@ -169,7 +169,7 @@ struct sht15_data {
43119 int supply_uv;
43120 bool supply_uv_valid;
43121 struct work_struct update_supply_work;
43122- atomic_t interrupt_handled;
43123+ atomic_unchecked_t interrupt_handled;
43124 };
43125
43126 /**
43127@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
43128 ret = gpio_direction_input(data->pdata->gpio_data);
43129 if (ret)
43130 return ret;
43131- atomic_set(&data->interrupt_handled, 0);
43132+ atomic_set_unchecked(&data->interrupt_handled, 0);
43133
43134 enable_irq(gpio_to_irq(data->pdata->gpio_data));
43135 if (gpio_get_value(data->pdata->gpio_data) == 0) {
43136 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
43137 /* Only relevant if the interrupt hasn't occurred. */
43138- if (!atomic_read(&data->interrupt_handled))
43139+ if (!atomic_read_unchecked(&data->interrupt_handled))
43140 schedule_work(&data->read_work);
43141 }
43142 ret = wait_event_timeout(data->wait_queue,
43143@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
43144
43145 /* First disable the interrupt */
43146 disable_irq_nosync(irq);
43147- atomic_inc(&data->interrupt_handled);
43148+ atomic_inc_unchecked(&data->interrupt_handled);
43149 /* Then schedule a reading work struct */
43150 if (data->state != SHT15_READING_NOTHING)
43151 schedule_work(&data->read_work);
43152@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
43153 * If not, then start the interrupt again - care here as could
43154 * have gone low in meantime so verify it hasn't!
43155 */
43156- atomic_set(&data->interrupt_handled, 0);
43157+ atomic_set_unchecked(&data->interrupt_handled, 0);
43158 enable_irq(gpio_to_irq(data->pdata->gpio_data));
43159 /* If still not occurred or another handler was scheduled */
43160 if (gpio_get_value(data->pdata->gpio_data)
43161- || atomic_read(&data->interrupt_handled))
43162+ || atomic_read_unchecked(&data->interrupt_handled))
43163 return;
43164 }
43165
43166diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
43167index 8df43c5..b07b91d 100644
43168--- a/drivers/hwmon/via-cputemp.c
43169+++ b/drivers/hwmon/via-cputemp.c
43170@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
43171 return NOTIFY_OK;
43172 }
43173
43174-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
43175+static struct notifier_block via_cputemp_cpu_notifier = {
43176 .notifier_call = via_cputemp_cpu_callback,
43177 };
43178
43179diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
43180index 41fc683..a39cfea 100644
43181--- a/drivers/i2c/busses/i2c-amd756-s4882.c
43182+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
43183@@ -43,7 +43,7 @@
43184 extern struct i2c_adapter amd756_smbus;
43185
43186 static struct i2c_adapter *s4882_adapter;
43187-static struct i2c_algorithm *s4882_algo;
43188+static i2c_algorithm_no_const *s4882_algo;
43189
43190 /* Wrapper access functions for multiplexed SMBus */
43191 static DEFINE_MUTEX(amd756_lock);
43192diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
43193index b19a310..d6eece0 100644
43194--- a/drivers/i2c/busses/i2c-diolan-u2c.c
43195+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
43196@@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
43197 /* usb layer */
43198
43199 /* Send command to device, and get response. */
43200-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
43201+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
43202 {
43203 int ret = 0;
43204 int actual;
43205diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
43206index b170bdf..3c76427 100644
43207--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
43208+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
43209@@ -41,7 +41,7 @@
43210 extern struct i2c_adapter *nforce2_smbus;
43211
43212 static struct i2c_adapter *s4985_adapter;
43213-static struct i2c_algorithm *s4985_algo;
43214+static i2c_algorithm_no_const *s4985_algo;
43215
43216 /* Wrapper access functions for multiplexed SMBus */
43217 static DEFINE_MUTEX(nforce2_lock);
43218diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
43219index 80b47e8..1a6040d9 100644
43220--- a/drivers/i2c/i2c-dev.c
43221+++ b/drivers/i2c/i2c-dev.c
43222@@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
43223 break;
43224 }
43225
43226- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
43227+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
43228 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
43229 if (IS_ERR(rdwr_pa[i].buf)) {
43230 res = PTR_ERR(rdwr_pa[i].buf);
43231diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
43232index 0b510ba..4fbb5085 100644
43233--- a/drivers/ide/ide-cd.c
43234+++ b/drivers/ide/ide-cd.c
43235@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
43236 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
43237 if ((unsigned long)buf & alignment
43238 || blk_rq_bytes(rq) & q->dma_pad_mask
43239- || object_is_on_stack(buf))
43240+ || object_starts_on_stack(buf))
43241 drive->dma = 0;
43242 }
43243 }
43244diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
43245index af3e76d..96dfe5e 100644
43246--- a/drivers/iio/industrialio-core.c
43247+++ b/drivers/iio/industrialio-core.c
43248@@ -555,7 +555,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
43249 }
43250
43251 static
43252-int __iio_device_attr_init(struct device_attribute *dev_attr,
43253+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
43254 const char *postfix,
43255 struct iio_chan_spec const *chan,
43256 ssize_t (*readfunc)(struct device *dev,
43257diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
43258index e28a494..f7c2671 100644
43259--- a/drivers/infiniband/core/cm.c
43260+++ b/drivers/infiniband/core/cm.c
43261@@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
43262
43263 struct cm_counter_group {
43264 struct kobject obj;
43265- atomic_long_t counter[CM_ATTR_COUNT];
43266+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
43267 };
43268
43269 struct cm_counter_attribute {
43270@@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
43271 struct ib_mad_send_buf *msg = NULL;
43272 int ret;
43273
43274- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43275+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43276 counter[CM_REQ_COUNTER]);
43277
43278 /* Quick state check to discard duplicate REQs. */
43279@@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
43280 if (!cm_id_priv)
43281 return;
43282
43283- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43284+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43285 counter[CM_REP_COUNTER]);
43286 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
43287 if (ret)
43288@@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
43289 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
43290 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
43291 spin_unlock_irq(&cm_id_priv->lock);
43292- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43293+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43294 counter[CM_RTU_COUNTER]);
43295 goto out;
43296 }
43297@@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
43298 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
43299 dreq_msg->local_comm_id);
43300 if (!cm_id_priv) {
43301- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43302+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43303 counter[CM_DREQ_COUNTER]);
43304 cm_issue_drep(work->port, work->mad_recv_wc);
43305 return -EINVAL;
43306@@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
43307 case IB_CM_MRA_REP_RCVD:
43308 break;
43309 case IB_CM_TIMEWAIT:
43310- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43311+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43312 counter[CM_DREQ_COUNTER]);
43313 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
43314 goto unlock;
43315@@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
43316 cm_free_msg(msg);
43317 goto deref;
43318 case IB_CM_DREQ_RCVD:
43319- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43320+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43321 counter[CM_DREQ_COUNTER]);
43322 goto unlock;
43323 default:
43324@@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
43325 ib_modify_mad(cm_id_priv->av.port->mad_agent,
43326 cm_id_priv->msg, timeout)) {
43327 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
43328- atomic_long_inc(&work->port->
43329+ atomic_long_inc_unchecked(&work->port->
43330 counter_group[CM_RECV_DUPLICATES].
43331 counter[CM_MRA_COUNTER]);
43332 goto out;
43333@@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
43334 break;
43335 case IB_CM_MRA_REQ_RCVD:
43336 case IB_CM_MRA_REP_RCVD:
43337- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43338+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43339 counter[CM_MRA_COUNTER]);
43340 /* fall through */
43341 default:
43342@@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
43343 case IB_CM_LAP_IDLE:
43344 break;
43345 case IB_CM_MRA_LAP_SENT:
43346- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43347+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43348 counter[CM_LAP_COUNTER]);
43349 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
43350 goto unlock;
43351@@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
43352 cm_free_msg(msg);
43353 goto deref;
43354 case IB_CM_LAP_RCVD:
43355- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43356+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43357 counter[CM_LAP_COUNTER]);
43358 goto unlock;
43359 default:
43360@@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
43361 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
43362 if (cur_cm_id_priv) {
43363 spin_unlock_irq(&cm.lock);
43364- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43365+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43366 counter[CM_SIDR_REQ_COUNTER]);
43367 goto out; /* Duplicate message. */
43368 }
43369@@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
43370 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
43371 msg->retries = 1;
43372
43373- atomic_long_add(1 + msg->retries,
43374+ atomic_long_add_unchecked(1 + msg->retries,
43375 &port->counter_group[CM_XMIT].counter[attr_index]);
43376 if (msg->retries)
43377- atomic_long_add(msg->retries,
43378+ atomic_long_add_unchecked(msg->retries,
43379 &port->counter_group[CM_XMIT_RETRIES].
43380 counter[attr_index]);
43381
43382@@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
43383 }
43384
43385 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
43386- atomic_long_inc(&port->counter_group[CM_RECV].
43387+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
43388 counter[attr_id - CM_ATTR_ID_OFFSET]);
43389
43390 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
43391@@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
43392 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
43393
43394 return sprintf(buf, "%ld\n",
43395- atomic_long_read(&group->counter[cm_attr->index]));
43396+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
43397 }
43398
43399 static const struct sysfs_ops cm_counter_ops = {
43400diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
43401index 9f5ad7c..588cd84 100644
43402--- a/drivers/infiniband/core/fmr_pool.c
43403+++ b/drivers/infiniband/core/fmr_pool.c
43404@@ -98,8 +98,8 @@ struct ib_fmr_pool {
43405
43406 struct task_struct *thread;
43407
43408- atomic_t req_ser;
43409- atomic_t flush_ser;
43410+ atomic_unchecked_t req_ser;
43411+ atomic_unchecked_t flush_ser;
43412
43413 wait_queue_head_t force_wait;
43414 };
43415@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
43416 struct ib_fmr_pool *pool = pool_ptr;
43417
43418 do {
43419- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
43420+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
43421 ib_fmr_batch_release(pool);
43422
43423- atomic_inc(&pool->flush_ser);
43424+ atomic_inc_unchecked(&pool->flush_ser);
43425 wake_up_interruptible(&pool->force_wait);
43426
43427 if (pool->flush_function)
43428@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
43429 }
43430
43431 set_current_state(TASK_INTERRUPTIBLE);
43432- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
43433+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
43434 !kthread_should_stop())
43435 schedule();
43436 __set_current_state(TASK_RUNNING);
43437@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
43438 pool->dirty_watermark = params->dirty_watermark;
43439 pool->dirty_len = 0;
43440 spin_lock_init(&pool->pool_lock);
43441- atomic_set(&pool->req_ser, 0);
43442- atomic_set(&pool->flush_ser, 0);
43443+ atomic_set_unchecked(&pool->req_ser, 0);
43444+ atomic_set_unchecked(&pool->flush_ser, 0);
43445 init_waitqueue_head(&pool->force_wait);
43446
43447 pool->thread = kthread_run(ib_fmr_cleanup_thread,
43448@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
43449 }
43450 spin_unlock_irq(&pool->pool_lock);
43451
43452- serial = atomic_inc_return(&pool->req_ser);
43453+ serial = atomic_inc_return_unchecked(&pool->req_ser);
43454 wake_up_process(pool->thread);
43455
43456 if (wait_event_interruptible(pool->force_wait,
43457- atomic_read(&pool->flush_ser) - serial >= 0))
43458+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
43459 return -EINTR;
43460
43461 return 0;
43462@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
43463 } else {
43464 list_add_tail(&fmr->list, &pool->dirty_list);
43465 if (++pool->dirty_len >= pool->dirty_watermark) {
43466- atomic_inc(&pool->req_ser);
43467+ atomic_inc_unchecked(&pool->req_ser);
43468 wake_up_process(pool->thread);
43469 }
43470 }
43471diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
43472index ec7a298..8742e59 100644
43473--- a/drivers/infiniband/hw/cxgb4/mem.c
43474+++ b/drivers/infiniband/hw/cxgb4/mem.c
43475@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
43476 int err;
43477 struct fw_ri_tpte tpt;
43478 u32 stag_idx;
43479- static atomic_t key;
43480+ static atomic_unchecked_t key;
43481
43482 if (c4iw_fatal_error(rdev))
43483 return -EIO;
43484@@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
43485 if (rdev->stats.stag.cur > rdev->stats.stag.max)
43486 rdev->stats.stag.max = rdev->stats.stag.cur;
43487 mutex_unlock(&rdev->stats.lock);
43488- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
43489+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
43490 }
43491 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
43492 __func__, stag_state, type, pdid, stag_idx);
43493diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
43494index 79b3dbc..96e5fcc 100644
43495--- a/drivers/infiniband/hw/ipath/ipath_rc.c
43496+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
43497@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
43498 struct ib_atomic_eth *ateth;
43499 struct ipath_ack_entry *e;
43500 u64 vaddr;
43501- atomic64_t *maddr;
43502+ atomic64_unchecked_t *maddr;
43503 u64 sdata;
43504 u32 rkey;
43505 u8 next;
43506@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
43507 IB_ACCESS_REMOTE_ATOMIC)))
43508 goto nack_acc_unlck;
43509 /* Perform atomic OP and save result. */
43510- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
43511+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
43512 sdata = be64_to_cpu(ateth->swap_data);
43513 e = &qp->s_ack_queue[qp->r_head_ack_queue];
43514 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
43515- (u64) atomic64_add_return(sdata, maddr) - sdata :
43516+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
43517 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
43518 be64_to_cpu(ateth->compare_data),
43519 sdata);
43520diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
43521index 1f95bba..9530f87 100644
43522--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
43523+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
43524@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
43525 unsigned long flags;
43526 struct ib_wc wc;
43527 u64 sdata;
43528- atomic64_t *maddr;
43529+ atomic64_unchecked_t *maddr;
43530 enum ib_wc_status send_status;
43531
43532 /*
43533@@ -382,11 +382,11 @@ again:
43534 IB_ACCESS_REMOTE_ATOMIC)))
43535 goto acc_err;
43536 /* Perform atomic OP and save result. */
43537- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
43538+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
43539 sdata = wqe->wr.wr.atomic.compare_add;
43540 *(u64 *) sqp->s_sge.sge.vaddr =
43541 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
43542- (u64) atomic64_add_return(sdata, maddr) - sdata :
43543+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
43544 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
43545 sdata, wqe->wr.wr.atomic.swap);
43546 goto send_comp;
43547diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
43548index 82a7dd8..8fb6ba6 100644
43549--- a/drivers/infiniband/hw/mlx4/mad.c
43550+++ b/drivers/infiniband/hw/mlx4/mad.c
43551@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
43552
43553 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
43554 {
43555- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
43556+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
43557 cpu_to_be64(0xff00000000000000LL);
43558 }
43559
43560diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
43561index ed327e6..ca1739e0 100644
43562--- a/drivers/infiniband/hw/mlx4/mcg.c
43563+++ b/drivers/infiniband/hw/mlx4/mcg.c
43564@@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
43565 {
43566 char name[20];
43567
43568- atomic_set(&ctx->tid, 0);
43569+ atomic_set_unchecked(&ctx->tid, 0);
43570 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
43571 ctx->mcg_wq = create_singlethread_workqueue(name);
43572 if (!ctx->mcg_wq)
43573diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
43574index 6eb743f..a7b0f6d 100644
43575--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
43576+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
43577@@ -426,7 +426,7 @@ struct mlx4_ib_demux_ctx {
43578 struct list_head mcg_mgid0_list;
43579 struct workqueue_struct *mcg_wq;
43580 struct mlx4_ib_demux_pv_ctx **tun;
43581- atomic_t tid;
43582+ atomic_unchecked_t tid;
43583 int flushing; /* flushing the work queue */
43584 };
43585
43586diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
43587index 9d3e5c1..6f166df 100644
43588--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
43589+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
43590@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
43591 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
43592 }
43593
43594-int mthca_QUERY_FW(struct mthca_dev *dev)
43595+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
43596 {
43597 struct mthca_mailbox *mailbox;
43598 u32 *outbox;
43599@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43600 CMD_TIME_CLASS_B);
43601 }
43602
43603-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43604+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43605 int num_mtt)
43606 {
43607 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
43608@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
43609 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
43610 }
43611
43612-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43613+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43614 int eq_num)
43615 {
43616 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
43617@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
43618 CMD_TIME_CLASS_B);
43619 }
43620
43621-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
43622+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
43623 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
43624 void *in_mad, void *response_mad)
43625 {
43626diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
43627index ded76c1..0cf0a08 100644
43628--- a/drivers/infiniband/hw/mthca/mthca_main.c
43629+++ b/drivers/infiniband/hw/mthca/mthca_main.c
43630@@ -692,7 +692,7 @@ err_close:
43631 return err;
43632 }
43633
43634-static int mthca_setup_hca(struct mthca_dev *dev)
43635+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
43636 {
43637 int err;
43638
43639diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
43640index ed9a989..6aa5dc2 100644
43641--- a/drivers/infiniband/hw/mthca/mthca_mr.c
43642+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
43643@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
43644 * through the bitmaps)
43645 */
43646
43647-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
43648+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
43649 {
43650 int o;
43651 int m;
43652@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
43653 return key;
43654 }
43655
43656-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43657+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43658 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
43659 {
43660 struct mthca_mailbox *mailbox;
43661@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
43662 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
43663 }
43664
43665-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43666+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43667 u64 *buffer_list, int buffer_size_shift,
43668 int list_len, u64 iova, u64 total_size,
43669 u32 access, struct mthca_mr *mr)
43670diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
43671index 415f8e1..e34214e 100644
43672--- a/drivers/infiniband/hw/mthca/mthca_provider.c
43673+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
43674@@ -764,7 +764,7 @@ unlock:
43675 return 0;
43676 }
43677
43678-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43679+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43680 {
43681 struct mthca_dev *dev = to_mdev(ibcq->device);
43682 struct mthca_cq *cq = to_mcq(ibcq);
43683diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
43684index 3b2a6dc..bce26ff 100644
43685--- a/drivers/infiniband/hw/nes/nes.c
43686+++ b/drivers/infiniband/hw/nes/nes.c
43687@@ -97,7 +97,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
43688 LIST_HEAD(nes_adapter_list);
43689 static LIST_HEAD(nes_dev_list);
43690
43691-atomic_t qps_destroyed;
43692+atomic_unchecked_t qps_destroyed;
43693
43694 static unsigned int ee_flsh_adapter;
43695 static unsigned int sysfs_nonidx_addr;
43696@@ -278,7 +278,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
43697 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
43698 struct nes_adapter *nesadapter = nesdev->nesadapter;
43699
43700- atomic_inc(&qps_destroyed);
43701+ atomic_inc_unchecked(&qps_destroyed);
43702
43703 /* Free the control structures */
43704
43705diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
43706index bd9d132..70d84f4 100644
43707--- a/drivers/infiniband/hw/nes/nes.h
43708+++ b/drivers/infiniband/hw/nes/nes.h
43709@@ -180,17 +180,17 @@ extern unsigned int nes_debug_level;
43710 extern unsigned int wqm_quanta;
43711 extern struct list_head nes_adapter_list;
43712
43713-extern atomic_t cm_connects;
43714-extern atomic_t cm_accepts;
43715-extern atomic_t cm_disconnects;
43716-extern atomic_t cm_closes;
43717-extern atomic_t cm_connecteds;
43718-extern atomic_t cm_connect_reqs;
43719-extern atomic_t cm_rejects;
43720-extern atomic_t mod_qp_timouts;
43721-extern atomic_t qps_created;
43722-extern atomic_t qps_destroyed;
43723-extern atomic_t sw_qps_destroyed;
43724+extern atomic_unchecked_t cm_connects;
43725+extern atomic_unchecked_t cm_accepts;
43726+extern atomic_unchecked_t cm_disconnects;
43727+extern atomic_unchecked_t cm_closes;
43728+extern atomic_unchecked_t cm_connecteds;
43729+extern atomic_unchecked_t cm_connect_reqs;
43730+extern atomic_unchecked_t cm_rejects;
43731+extern atomic_unchecked_t mod_qp_timouts;
43732+extern atomic_unchecked_t qps_created;
43733+extern atomic_unchecked_t qps_destroyed;
43734+extern atomic_unchecked_t sw_qps_destroyed;
43735 extern u32 mh_detected;
43736 extern u32 mh_pauses_sent;
43737 extern u32 cm_packets_sent;
43738@@ -199,16 +199,16 @@ extern u32 cm_packets_created;
43739 extern u32 cm_packets_received;
43740 extern u32 cm_packets_dropped;
43741 extern u32 cm_packets_retrans;
43742-extern atomic_t cm_listens_created;
43743-extern atomic_t cm_listens_destroyed;
43744+extern atomic_unchecked_t cm_listens_created;
43745+extern atomic_unchecked_t cm_listens_destroyed;
43746 extern u32 cm_backlog_drops;
43747-extern atomic_t cm_loopbacks;
43748-extern atomic_t cm_nodes_created;
43749-extern atomic_t cm_nodes_destroyed;
43750-extern atomic_t cm_accel_dropped_pkts;
43751-extern atomic_t cm_resets_recvd;
43752-extern atomic_t pau_qps_created;
43753-extern atomic_t pau_qps_destroyed;
43754+extern atomic_unchecked_t cm_loopbacks;
43755+extern atomic_unchecked_t cm_nodes_created;
43756+extern atomic_unchecked_t cm_nodes_destroyed;
43757+extern atomic_unchecked_t cm_accel_dropped_pkts;
43758+extern atomic_unchecked_t cm_resets_recvd;
43759+extern atomic_unchecked_t pau_qps_created;
43760+extern atomic_unchecked_t pau_qps_destroyed;
43761
43762 extern u32 int_mod_timer_init;
43763 extern u32 int_mod_cq_depth_256;
43764diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
43765index 6f09a72..cf4399d 100644
43766--- a/drivers/infiniband/hw/nes/nes_cm.c
43767+++ b/drivers/infiniband/hw/nes/nes_cm.c
43768@@ -69,14 +69,14 @@ u32 cm_packets_dropped;
43769 u32 cm_packets_retrans;
43770 u32 cm_packets_created;
43771 u32 cm_packets_received;
43772-atomic_t cm_listens_created;
43773-atomic_t cm_listens_destroyed;
43774+atomic_unchecked_t cm_listens_created;
43775+atomic_unchecked_t cm_listens_destroyed;
43776 u32 cm_backlog_drops;
43777-atomic_t cm_loopbacks;
43778-atomic_t cm_nodes_created;
43779-atomic_t cm_nodes_destroyed;
43780-atomic_t cm_accel_dropped_pkts;
43781-atomic_t cm_resets_recvd;
43782+atomic_unchecked_t cm_loopbacks;
43783+atomic_unchecked_t cm_nodes_created;
43784+atomic_unchecked_t cm_nodes_destroyed;
43785+atomic_unchecked_t cm_accel_dropped_pkts;
43786+atomic_unchecked_t cm_resets_recvd;
43787
43788 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
43789 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
43790@@ -135,28 +135,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
43791 /* instance of function pointers for client API */
43792 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
43793 static struct nes_cm_ops nes_cm_api = {
43794- mini_cm_accelerated,
43795- mini_cm_listen,
43796- mini_cm_del_listen,
43797- mini_cm_connect,
43798- mini_cm_close,
43799- mini_cm_accept,
43800- mini_cm_reject,
43801- mini_cm_recv_pkt,
43802- mini_cm_dealloc_core,
43803- mini_cm_get,
43804- mini_cm_set
43805+ .accelerated = mini_cm_accelerated,
43806+ .listen = mini_cm_listen,
43807+ .stop_listener = mini_cm_del_listen,
43808+ .connect = mini_cm_connect,
43809+ .close = mini_cm_close,
43810+ .accept = mini_cm_accept,
43811+ .reject = mini_cm_reject,
43812+ .recv_pkt = mini_cm_recv_pkt,
43813+ .destroy_cm_core = mini_cm_dealloc_core,
43814+ .get = mini_cm_get,
43815+ .set = mini_cm_set
43816 };
43817
43818 static struct nes_cm_core *g_cm_core;
43819
43820-atomic_t cm_connects;
43821-atomic_t cm_accepts;
43822-atomic_t cm_disconnects;
43823-atomic_t cm_closes;
43824-atomic_t cm_connecteds;
43825-atomic_t cm_connect_reqs;
43826-atomic_t cm_rejects;
43827+atomic_unchecked_t cm_connects;
43828+atomic_unchecked_t cm_accepts;
43829+atomic_unchecked_t cm_disconnects;
43830+atomic_unchecked_t cm_closes;
43831+atomic_unchecked_t cm_connecteds;
43832+atomic_unchecked_t cm_connect_reqs;
43833+atomic_unchecked_t cm_rejects;
43834
43835 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
43836 {
43837@@ -1436,7 +1436,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
43838 kfree(listener);
43839 listener = NULL;
43840 ret = 0;
43841- atomic_inc(&cm_listens_destroyed);
43842+ atomic_inc_unchecked(&cm_listens_destroyed);
43843 } else {
43844 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
43845 }
43846@@ -1637,7 +1637,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
43847 cm_node->rem_mac);
43848
43849 add_hte_node(cm_core, cm_node);
43850- atomic_inc(&cm_nodes_created);
43851+ atomic_inc_unchecked(&cm_nodes_created);
43852
43853 return cm_node;
43854 }
43855@@ -1698,7 +1698,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
43856 }
43857
43858 atomic_dec(&cm_core->node_cnt);
43859- atomic_inc(&cm_nodes_destroyed);
43860+ atomic_inc_unchecked(&cm_nodes_destroyed);
43861 nesqp = cm_node->nesqp;
43862 if (nesqp) {
43863 nesqp->cm_node = NULL;
43864@@ -1762,7 +1762,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
43865
43866 static void drop_packet(struct sk_buff *skb)
43867 {
43868- atomic_inc(&cm_accel_dropped_pkts);
43869+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
43870 dev_kfree_skb_any(skb);
43871 }
43872
43873@@ -1825,7 +1825,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
43874 {
43875
43876 int reset = 0; /* whether to send reset in case of err.. */
43877- atomic_inc(&cm_resets_recvd);
43878+ atomic_inc_unchecked(&cm_resets_recvd);
43879 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
43880 " refcnt=%d\n", cm_node, cm_node->state,
43881 atomic_read(&cm_node->ref_count));
43882@@ -2492,7 +2492,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
43883 rem_ref_cm_node(cm_node->cm_core, cm_node);
43884 return NULL;
43885 }
43886- atomic_inc(&cm_loopbacks);
43887+ atomic_inc_unchecked(&cm_loopbacks);
43888 loopbackremotenode->loopbackpartner = cm_node;
43889 loopbackremotenode->tcp_cntxt.rcv_wscale =
43890 NES_CM_DEFAULT_RCV_WND_SCALE;
43891@@ -2773,7 +2773,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
43892 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
43893 else {
43894 rem_ref_cm_node(cm_core, cm_node);
43895- atomic_inc(&cm_accel_dropped_pkts);
43896+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
43897 dev_kfree_skb_any(skb);
43898 }
43899 break;
43900@@ -3081,7 +3081,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43901
43902 if ((cm_id) && (cm_id->event_handler)) {
43903 if (issue_disconn) {
43904- atomic_inc(&cm_disconnects);
43905+ atomic_inc_unchecked(&cm_disconnects);
43906 cm_event.event = IW_CM_EVENT_DISCONNECT;
43907 cm_event.status = disconn_status;
43908 cm_event.local_addr = cm_id->local_addr;
43909@@ -3103,7 +3103,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43910 }
43911
43912 if (issue_close) {
43913- atomic_inc(&cm_closes);
43914+ atomic_inc_unchecked(&cm_closes);
43915 nes_disconnect(nesqp, 1);
43916
43917 cm_id->provider_data = nesqp;
43918@@ -3241,7 +3241,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43919
43920 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
43921 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
43922- atomic_inc(&cm_accepts);
43923+ atomic_inc_unchecked(&cm_accepts);
43924
43925 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
43926 netdev_refcnt_read(nesvnic->netdev));
43927@@ -3439,7 +3439,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
43928 struct nes_cm_core *cm_core;
43929 u8 *start_buff;
43930
43931- atomic_inc(&cm_rejects);
43932+ atomic_inc_unchecked(&cm_rejects);
43933 cm_node = (struct nes_cm_node *)cm_id->provider_data;
43934 loopback = cm_node->loopbackpartner;
43935 cm_core = cm_node->cm_core;
43936@@ -3504,7 +3504,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43937 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
43938 ntohs(laddr->sin_port));
43939
43940- atomic_inc(&cm_connects);
43941+ atomic_inc_unchecked(&cm_connects);
43942 nesqp->active_conn = 1;
43943
43944 /* cache the cm_id in the qp */
43945@@ -3649,7 +3649,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
43946 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
43947 return err;
43948 }
43949- atomic_inc(&cm_listens_created);
43950+ atomic_inc_unchecked(&cm_listens_created);
43951 }
43952
43953 cm_id->add_ref(cm_id);
43954@@ -3756,7 +3756,7 @@ static void cm_event_connected(struct nes_cm_event *event)
43955
43956 if (nesqp->destroyed)
43957 return;
43958- atomic_inc(&cm_connecteds);
43959+ atomic_inc_unchecked(&cm_connecteds);
43960 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
43961 " local port 0x%04X. jiffies = %lu.\n",
43962 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
43963@@ -3941,7 +3941,7 @@ static void cm_event_reset(struct nes_cm_event *event)
43964
43965 cm_id->add_ref(cm_id);
43966 ret = cm_id->event_handler(cm_id, &cm_event);
43967- atomic_inc(&cm_closes);
43968+ atomic_inc_unchecked(&cm_closes);
43969 cm_event.event = IW_CM_EVENT_CLOSE;
43970 cm_event.status = 0;
43971 cm_event.provider_data = cm_id->provider_data;
43972@@ -3981,7 +3981,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
43973 return;
43974 cm_id = cm_node->cm_id;
43975
43976- atomic_inc(&cm_connect_reqs);
43977+ atomic_inc_unchecked(&cm_connect_reqs);
43978 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43979 cm_node, cm_id, jiffies);
43980
43981@@ -4030,7 +4030,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
43982 return;
43983 cm_id = cm_node->cm_id;
43984
43985- atomic_inc(&cm_connect_reqs);
43986+ atomic_inc_unchecked(&cm_connect_reqs);
43987 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43988 cm_node, cm_id, jiffies);
43989
43990diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
43991index 4166452..fc952c3 100644
43992--- a/drivers/infiniband/hw/nes/nes_mgt.c
43993+++ b/drivers/infiniband/hw/nes/nes_mgt.c
43994@@ -40,8 +40,8 @@
43995 #include "nes.h"
43996 #include "nes_mgt.h"
43997
43998-atomic_t pau_qps_created;
43999-atomic_t pau_qps_destroyed;
44000+atomic_unchecked_t pau_qps_created;
44001+atomic_unchecked_t pau_qps_destroyed;
44002
44003 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
44004 {
44005@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
44006 {
44007 struct sk_buff *skb;
44008 unsigned long flags;
44009- atomic_inc(&pau_qps_destroyed);
44010+ atomic_inc_unchecked(&pau_qps_destroyed);
44011
44012 /* Free packets that have not yet been forwarded */
44013 /* Lock is acquired by skb_dequeue when removing the skb */
44014@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
44015 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
44016 skb_queue_head_init(&nesqp->pau_list);
44017 spin_lock_init(&nesqp->pau_lock);
44018- atomic_inc(&pau_qps_created);
44019+ atomic_inc_unchecked(&pau_qps_created);
44020 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
44021 }
44022
44023diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
44024index 49eb511..a774366 100644
44025--- a/drivers/infiniband/hw/nes/nes_nic.c
44026+++ b/drivers/infiniband/hw/nes/nes_nic.c
44027@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
44028 target_stat_values[++index] = mh_detected;
44029 target_stat_values[++index] = mh_pauses_sent;
44030 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
44031- target_stat_values[++index] = atomic_read(&cm_connects);
44032- target_stat_values[++index] = atomic_read(&cm_accepts);
44033- target_stat_values[++index] = atomic_read(&cm_disconnects);
44034- target_stat_values[++index] = atomic_read(&cm_connecteds);
44035- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
44036- target_stat_values[++index] = atomic_read(&cm_rejects);
44037- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
44038- target_stat_values[++index] = atomic_read(&qps_created);
44039- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
44040- target_stat_values[++index] = atomic_read(&qps_destroyed);
44041- target_stat_values[++index] = atomic_read(&cm_closes);
44042+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
44043+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
44044+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
44045+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
44046+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
44047+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
44048+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
44049+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
44050+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
44051+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
44052+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
44053 target_stat_values[++index] = cm_packets_sent;
44054 target_stat_values[++index] = cm_packets_bounced;
44055 target_stat_values[++index] = cm_packets_created;
44056 target_stat_values[++index] = cm_packets_received;
44057 target_stat_values[++index] = cm_packets_dropped;
44058 target_stat_values[++index] = cm_packets_retrans;
44059- target_stat_values[++index] = atomic_read(&cm_listens_created);
44060- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
44061+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
44062+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
44063 target_stat_values[++index] = cm_backlog_drops;
44064- target_stat_values[++index] = atomic_read(&cm_loopbacks);
44065- target_stat_values[++index] = atomic_read(&cm_nodes_created);
44066- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
44067- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
44068- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
44069+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
44070+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
44071+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
44072+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
44073+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
44074 target_stat_values[++index] = nesadapter->free_4kpbl;
44075 target_stat_values[++index] = nesadapter->free_256pbl;
44076 target_stat_values[++index] = int_mod_timer_init;
44077 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
44078 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
44079 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
44080- target_stat_values[++index] = atomic_read(&pau_qps_created);
44081- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
44082+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
44083+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
44084 }
44085
44086 /**
44087diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
44088index fef067c..6a25ccd 100644
44089--- a/drivers/infiniband/hw/nes/nes_verbs.c
44090+++ b/drivers/infiniband/hw/nes/nes_verbs.c
44091@@ -46,9 +46,9 @@
44092
44093 #include <rdma/ib_umem.h>
44094
44095-atomic_t mod_qp_timouts;
44096-atomic_t qps_created;
44097-atomic_t sw_qps_destroyed;
44098+atomic_unchecked_t mod_qp_timouts;
44099+atomic_unchecked_t qps_created;
44100+atomic_unchecked_t sw_qps_destroyed;
44101
44102 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
44103
44104@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
44105 if (init_attr->create_flags)
44106 return ERR_PTR(-EINVAL);
44107
44108- atomic_inc(&qps_created);
44109+ atomic_inc_unchecked(&qps_created);
44110 switch (init_attr->qp_type) {
44111 case IB_QPT_RC:
44112 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
44113@@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
44114 struct iw_cm_event cm_event;
44115 int ret = 0;
44116
44117- atomic_inc(&sw_qps_destroyed);
44118+ atomic_inc_unchecked(&sw_qps_destroyed);
44119 nesqp->destroyed = 1;
44120
44121 /* Blow away the connection if it exists. */
44122diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
44123index c00ae09..04e91be 100644
44124--- a/drivers/infiniband/hw/qib/qib.h
44125+++ b/drivers/infiniband/hw/qib/qib.h
44126@@ -52,6 +52,7 @@
44127 #include <linux/kref.h>
44128 #include <linux/sched.h>
44129 #include <linux/kthread.h>
44130+#include <linux/slab.h>
44131
44132 #include "qib_common.h"
44133 #include "qib_verbs.h"
44134diff --git a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
44135index cdc7df4..a2fdfdb 100644
44136--- a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
44137+++ b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
44138@@ -156,7 +156,7 @@ static size_t ipoib_get_size(const struct net_device *dev)
44139 nla_total_size(2); /* IFLA_IPOIB_UMCAST */
44140 }
44141
44142-static struct rtnl_link_ops ipoib_link_ops __read_mostly = {
44143+static struct rtnl_link_ops ipoib_link_ops = {
44144 .kind = "ipoib",
44145 .maxtype = IFLA_IPOIB_MAX,
44146 .policy = ipoib_policy,
44147diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
44148index de05545..b535322 100644
44149--- a/drivers/input/evdev.c
44150+++ b/drivers/input/evdev.c
44151@@ -421,7 +421,7 @@ static int evdev_open(struct inode *inode, struct file *file)
44152
44153 err_free_client:
44154 evdev_detach_client(evdev, client);
44155- kfree(client);
44156+ kvfree(client);
44157 return error;
44158 }
44159
44160diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
44161index 24c41ba..102d71f 100644
44162--- a/drivers/input/gameport/gameport.c
44163+++ b/drivers/input/gameport/gameport.c
44164@@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
44165 */
44166 static void gameport_init_port(struct gameport *gameport)
44167 {
44168- static atomic_t gameport_no = ATOMIC_INIT(0);
44169+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
44170
44171 __module_get(THIS_MODULE);
44172
44173 mutex_init(&gameport->drv_mutex);
44174 device_initialize(&gameport->dev);
44175 dev_set_name(&gameport->dev, "gameport%lu",
44176- (unsigned long)atomic_inc_return(&gameport_no) - 1);
44177+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
44178 gameport->dev.bus = &gameport_bus;
44179 gameport->dev.release = gameport_release_port;
44180 if (gameport->parent)
44181diff --git a/drivers/input/input.c b/drivers/input/input.c
44182index 29ca0bb..f4bc2e3 100644
44183--- a/drivers/input/input.c
44184+++ b/drivers/input/input.c
44185@@ -1774,7 +1774,7 @@ EXPORT_SYMBOL_GPL(input_class);
44186 */
44187 struct input_dev *input_allocate_device(void)
44188 {
44189- static atomic_t input_no = ATOMIC_INIT(0);
44190+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
44191 struct input_dev *dev;
44192
44193 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
44194@@ -1789,7 +1789,7 @@ struct input_dev *input_allocate_device(void)
44195 INIT_LIST_HEAD(&dev->node);
44196
44197 dev_set_name(&dev->dev, "input%ld",
44198- (unsigned long) atomic_inc_return(&input_no) - 1);
44199+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
44200
44201 __module_get(THIS_MODULE);
44202 }
44203diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
44204index 4a95b22..874c182 100644
44205--- a/drivers/input/joystick/sidewinder.c
44206+++ b/drivers/input/joystick/sidewinder.c
44207@@ -30,6 +30,7 @@
44208 #include <linux/kernel.h>
44209 #include <linux/module.h>
44210 #include <linux/slab.h>
44211+#include <linux/sched.h>
44212 #include <linux/input.h>
44213 #include <linux/gameport.h>
44214 #include <linux/jiffies.h>
44215diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
44216index e65d9c0..ad3942e 100644
44217--- a/drivers/input/joystick/xpad.c
44218+++ b/drivers/input/joystick/xpad.c
44219@@ -850,7 +850,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
44220
44221 static int xpad_led_probe(struct usb_xpad *xpad)
44222 {
44223- static atomic_t led_seq = ATOMIC_INIT(0);
44224+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
44225 long led_no;
44226 struct xpad_led *led;
44227 struct led_classdev *led_cdev;
44228@@ -863,7 +863,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
44229 if (!led)
44230 return -ENOMEM;
44231
44232- led_no = (long)atomic_inc_return(&led_seq) - 1;
44233+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
44234
44235 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
44236 led->xpad = xpad;
44237diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
44238index 719410f..1896169 100644
44239--- a/drivers/input/misc/ims-pcu.c
44240+++ b/drivers/input/misc/ims-pcu.c
44241@@ -1851,7 +1851,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
44242
44243 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
44244 {
44245- static atomic_t device_no = ATOMIC_INIT(0);
44246+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
44247
44248 const struct ims_pcu_device_info *info;
44249 int error;
44250@@ -1882,7 +1882,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
44251 }
44252
44253 /* Device appears to be operable, complete initialization */
44254- pcu->device_no = atomic_inc_return(&device_no) - 1;
44255+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
44256
44257 /*
44258 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
44259diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
44260index 2f0b39d..7370f13 100644
44261--- a/drivers/input/mouse/psmouse.h
44262+++ b/drivers/input/mouse/psmouse.h
44263@@ -116,7 +116,7 @@ struct psmouse_attribute {
44264 ssize_t (*set)(struct psmouse *psmouse, void *data,
44265 const char *buf, size_t count);
44266 bool protect;
44267-};
44268+} __do_const;
44269 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
44270
44271 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
44272diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
44273index b604564..3f14ae4 100644
44274--- a/drivers/input/mousedev.c
44275+++ b/drivers/input/mousedev.c
44276@@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
44277
44278 spin_unlock_irq(&client->packet_lock);
44279
44280- if (copy_to_user(buffer, data, count))
44281+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
44282 return -EFAULT;
44283
44284 return count;
44285diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
44286index b29134d..394deb0 100644
44287--- a/drivers/input/serio/serio.c
44288+++ b/drivers/input/serio/serio.c
44289@@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
44290 */
44291 static void serio_init_port(struct serio *serio)
44292 {
44293- static atomic_t serio_no = ATOMIC_INIT(0);
44294+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
44295
44296 __module_get(THIS_MODULE);
44297
44298@@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
44299 mutex_init(&serio->drv_mutex);
44300 device_initialize(&serio->dev);
44301 dev_set_name(&serio->dev, "serio%ld",
44302- (long)atomic_inc_return(&serio_no) - 1);
44303+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
44304 serio->dev.bus = &serio_bus;
44305 serio->dev.release = serio_release_port;
44306 serio->dev.groups = serio_device_attr_groups;
44307diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
44308index c9a02fe..0debc75 100644
44309--- a/drivers/input/serio/serio_raw.c
44310+++ b/drivers/input/serio/serio_raw.c
44311@@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
44312
44313 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
44314 {
44315- static atomic_t serio_raw_no = ATOMIC_INIT(0);
44316+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
44317 struct serio_raw *serio_raw;
44318 int err;
44319
44320@@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
44321 }
44322
44323 snprintf(serio_raw->name, sizeof(serio_raw->name),
44324- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
44325+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
44326 kref_init(&serio_raw->kref);
44327 INIT_LIST_HEAD(&serio_raw->client_list);
44328 init_waitqueue_head(&serio_raw->wait);
44329diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
44330index 5aff937..9cff67c 100644
44331--- a/drivers/iommu/amd_iommu.c
44332+++ b/drivers/iommu/amd_iommu.c
44333@@ -798,11 +798,21 @@ static void copy_cmd_to_buffer(struct amd_iommu *iommu,
44334
44335 static void build_completion_wait(struct iommu_cmd *cmd, u64 address)
44336 {
44337+ phys_addr_t physaddr;
44338 WARN_ON(address & 0x7ULL);
44339
44340 memset(cmd, 0, sizeof(*cmd));
44341- cmd->data[0] = lower_32_bits(__pa(address)) | CMD_COMPL_WAIT_STORE_MASK;
44342- cmd->data[1] = upper_32_bits(__pa(address));
44343+
44344+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
44345+ if (object_starts_on_stack(address)) {
44346+ void *adjbuf = (void *)address - current->stack + current->lowmem_stack;
44347+ physaddr = __pa((u64)adjbuf);
44348+ } else
44349+#endif
44350+ physaddr = __pa(address);
44351+
44352+ cmd->data[0] = lower_32_bits(physaddr) | CMD_COMPL_WAIT_STORE_MASK;
44353+ cmd->data[1] = upper_32_bits(physaddr);
44354 cmd->data[2] = 1;
44355 CMD_SET_TYPE(cmd, CMD_COMPL_WAIT);
44356 }
44357diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
44358index a83cc2a..64462e6 100644
44359--- a/drivers/iommu/arm-smmu.c
44360+++ b/drivers/iommu/arm-smmu.c
44361@@ -921,7 +921,7 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain,
44362 cfg->irptndx = cfg->cbndx;
44363 }
44364
44365- ACCESS_ONCE(smmu_domain->smmu) = smmu;
44366+ ACCESS_ONCE_RW(smmu_domain->smmu) = smmu;
44367 arm_smmu_init_context_bank(smmu_domain);
44368 spin_unlock_irqrestore(&smmu_domain->lock, flags);
44369
44370diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
44371index 33c4395..e06447e 100644
44372--- a/drivers/iommu/irq_remapping.c
44373+++ b/drivers/iommu/irq_remapping.c
44374@@ -354,7 +354,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
44375 void panic_if_irq_remap(const char *msg)
44376 {
44377 if (irq_remapping_enabled)
44378- panic(msg);
44379+ panic("%s", msg);
44380 }
44381
44382 static void ir_ack_apic_edge(struct irq_data *data)
44383@@ -375,10 +375,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
44384
44385 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
44386 {
44387- chip->irq_print_chip = ir_print_prefix;
44388- chip->irq_ack = ir_ack_apic_edge;
44389- chip->irq_eoi = ir_ack_apic_level;
44390- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
44391+ pax_open_kernel();
44392+ *(void **)&chip->irq_print_chip = ir_print_prefix;
44393+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
44394+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
44395+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
44396+ pax_close_kernel();
44397 }
44398
44399 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
44400diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
44401index dda6dbc..f9adebb 100644
44402--- a/drivers/irqchip/irq-gic.c
44403+++ b/drivers/irqchip/irq-gic.c
44404@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
44405 * Supported arch specific GIC irq extension.
44406 * Default make them NULL.
44407 */
44408-struct irq_chip gic_arch_extn = {
44409+irq_chip_no_const gic_arch_extn = {
44410 .irq_eoi = NULL,
44411 .irq_mask = NULL,
44412 .irq_unmask = NULL,
44413@@ -312,7 +312,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
44414 chained_irq_exit(chip, desc);
44415 }
44416
44417-static struct irq_chip gic_chip = {
44418+static irq_chip_no_const gic_chip __read_only = {
44419 .name = "GIC",
44420 .irq_mask = gic_mask_irq,
44421 .irq_unmask = gic_unmask_irq,
44422diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
44423index 8777065..a4a9967 100644
44424--- a/drivers/irqchip/irq-renesas-irqc.c
44425+++ b/drivers/irqchip/irq-renesas-irqc.c
44426@@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
44427 struct irqc_priv *p;
44428 struct resource *io;
44429 struct resource *irq;
44430- struct irq_chip *irq_chip;
44431+ irq_chip_no_const *irq_chip;
44432 const char *name = dev_name(&pdev->dev);
44433 int ret;
44434 int k;
44435diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
44436index 6a2df32..dc962f1 100644
44437--- a/drivers/isdn/capi/capi.c
44438+++ b/drivers/isdn/capi/capi.c
44439@@ -81,8 +81,8 @@ struct capiminor {
44440
44441 struct capi20_appl *ap;
44442 u32 ncci;
44443- atomic_t datahandle;
44444- atomic_t msgid;
44445+ atomic_unchecked_t datahandle;
44446+ atomic_unchecked_t msgid;
44447
44448 struct tty_port port;
44449 int ttyinstop;
44450@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
44451 capimsg_setu16(s, 2, mp->ap->applid);
44452 capimsg_setu8 (s, 4, CAPI_DATA_B3);
44453 capimsg_setu8 (s, 5, CAPI_RESP);
44454- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
44455+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
44456 capimsg_setu32(s, 8, mp->ncci);
44457 capimsg_setu16(s, 12, datahandle);
44458 }
44459@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
44460 mp->outbytes -= len;
44461 spin_unlock_bh(&mp->outlock);
44462
44463- datahandle = atomic_inc_return(&mp->datahandle);
44464+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
44465 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
44466 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
44467 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
44468 capimsg_setu16(skb->data, 2, mp->ap->applid);
44469 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
44470 capimsg_setu8 (skb->data, 5, CAPI_REQ);
44471- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
44472+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
44473 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
44474 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
44475 capimsg_setu16(skb->data, 16, len); /* Data length */
44476diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
44477index b7ae0a0..04590fa 100644
44478--- a/drivers/isdn/gigaset/bas-gigaset.c
44479+++ b/drivers/isdn/gigaset/bas-gigaset.c
44480@@ -2565,22 +2565,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
44481
44482
44483 static const struct gigaset_ops gigops = {
44484- gigaset_write_cmd,
44485- gigaset_write_room,
44486- gigaset_chars_in_buffer,
44487- gigaset_brkchars,
44488- gigaset_init_bchannel,
44489- gigaset_close_bchannel,
44490- gigaset_initbcshw,
44491- gigaset_freebcshw,
44492- gigaset_reinitbcshw,
44493- gigaset_initcshw,
44494- gigaset_freecshw,
44495- gigaset_set_modem_ctrl,
44496- gigaset_baud_rate,
44497- gigaset_set_line_ctrl,
44498- gigaset_isoc_send_skb,
44499- gigaset_isoc_input,
44500+ .write_cmd = gigaset_write_cmd,
44501+ .write_room = gigaset_write_room,
44502+ .chars_in_buffer = gigaset_chars_in_buffer,
44503+ .brkchars = gigaset_brkchars,
44504+ .init_bchannel = gigaset_init_bchannel,
44505+ .close_bchannel = gigaset_close_bchannel,
44506+ .initbcshw = gigaset_initbcshw,
44507+ .freebcshw = gigaset_freebcshw,
44508+ .reinitbcshw = gigaset_reinitbcshw,
44509+ .initcshw = gigaset_initcshw,
44510+ .freecshw = gigaset_freecshw,
44511+ .set_modem_ctrl = gigaset_set_modem_ctrl,
44512+ .baud_rate = gigaset_baud_rate,
44513+ .set_line_ctrl = gigaset_set_line_ctrl,
44514+ .send_skb = gigaset_isoc_send_skb,
44515+ .handle_input = gigaset_isoc_input,
44516 };
44517
44518 /* bas_gigaset_init
44519diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
44520index 600c79b..3752bab 100644
44521--- a/drivers/isdn/gigaset/interface.c
44522+++ b/drivers/isdn/gigaset/interface.c
44523@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
44524 }
44525 tty->driver_data = cs;
44526
44527- ++cs->port.count;
44528+ atomic_inc(&cs->port.count);
44529
44530- if (cs->port.count == 1) {
44531+ if (atomic_read(&cs->port.count) == 1) {
44532 tty_port_tty_set(&cs->port, tty);
44533 cs->port.low_latency = 1;
44534 }
44535@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
44536
44537 if (!cs->connected)
44538 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
44539- else if (!cs->port.count)
44540+ else if (!atomic_read(&cs->port.count))
44541 dev_warn(cs->dev, "%s: device not opened\n", __func__);
44542- else if (!--cs->port.count)
44543+ else if (!atomic_dec_return(&cs->port.count))
44544 tty_port_tty_set(&cs->port, NULL);
44545
44546 mutex_unlock(&cs->mutex);
44547diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
44548index 8c91fd5..14f13ce 100644
44549--- a/drivers/isdn/gigaset/ser-gigaset.c
44550+++ b/drivers/isdn/gigaset/ser-gigaset.c
44551@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
44552 }
44553
44554 static const struct gigaset_ops ops = {
44555- gigaset_write_cmd,
44556- gigaset_write_room,
44557- gigaset_chars_in_buffer,
44558- gigaset_brkchars,
44559- gigaset_init_bchannel,
44560- gigaset_close_bchannel,
44561- gigaset_initbcshw,
44562- gigaset_freebcshw,
44563- gigaset_reinitbcshw,
44564- gigaset_initcshw,
44565- gigaset_freecshw,
44566- gigaset_set_modem_ctrl,
44567- gigaset_baud_rate,
44568- gigaset_set_line_ctrl,
44569- gigaset_m10x_send_skb, /* asyncdata.c */
44570- gigaset_m10x_input, /* asyncdata.c */
44571+ .write_cmd = gigaset_write_cmd,
44572+ .write_room = gigaset_write_room,
44573+ .chars_in_buffer = gigaset_chars_in_buffer,
44574+ .brkchars = gigaset_brkchars,
44575+ .init_bchannel = gigaset_init_bchannel,
44576+ .close_bchannel = gigaset_close_bchannel,
44577+ .initbcshw = gigaset_initbcshw,
44578+ .freebcshw = gigaset_freebcshw,
44579+ .reinitbcshw = gigaset_reinitbcshw,
44580+ .initcshw = gigaset_initcshw,
44581+ .freecshw = gigaset_freecshw,
44582+ .set_modem_ctrl = gigaset_set_modem_ctrl,
44583+ .baud_rate = gigaset_baud_rate,
44584+ .set_line_ctrl = gigaset_set_line_ctrl,
44585+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
44586+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
44587 };
44588
44589
44590diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
44591index d0a41cb..b953e50 100644
44592--- a/drivers/isdn/gigaset/usb-gigaset.c
44593+++ b/drivers/isdn/gigaset/usb-gigaset.c
44594@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
44595 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
44596 memcpy(cs->hw.usb->bchars, buf, 6);
44597 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
44598- 0, 0, &buf, 6, 2000);
44599+ 0, 0, buf, 6, 2000);
44600 }
44601
44602 static void gigaset_freebcshw(struct bc_state *bcs)
44603@@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
44604 }
44605
44606 static const struct gigaset_ops ops = {
44607- gigaset_write_cmd,
44608- gigaset_write_room,
44609- gigaset_chars_in_buffer,
44610- gigaset_brkchars,
44611- gigaset_init_bchannel,
44612- gigaset_close_bchannel,
44613- gigaset_initbcshw,
44614- gigaset_freebcshw,
44615- gigaset_reinitbcshw,
44616- gigaset_initcshw,
44617- gigaset_freecshw,
44618- gigaset_set_modem_ctrl,
44619- gigaset_baud_rate,
44620- gigaset_set_line_ctrl,
44621- gigaset_m10x_send_skb,
44622- gigaset_m10x_input,
44623+ .write_cmd = gigaset_write_cmd,
44624+ .write_room = gigaset_write_room,
44625+ .chars_in_buffer = gigaset_chars_in_buffer,
44626+ .brkchars = gigaset_brkchars,
44627+ .init_bchannel = gigaset_init_bchannel,
44628+ .close_bchannel = gigaset_close_bchannel,
44629+ .initbcshw = gigaset_initbcshw,
44630+ .freebcshw = gigaset_freebcshw,
44631+ .reinitbcshw = gigaset_reinitbcshw,
44632+ .initcshw = gigaset_initcshw,
44633+ .freecshw = gigaset_freecshw,
44634+ .set_modem_ctrl = gigaset_set_modem_ctrl,
44635+ .baud_rate = gigaset_baud_rate,
44636+ .set_line_ctrl = gigaset_set_line_ctrl,
44637+ .send_skb = gigaset_m10x_send_skb,
44638+ .handle_input = gigaset_m10x_input,
44639 };
44640
44641 /*
44642diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
44643index 4d9b195..455075c 100644
44644--- a/drivers/isdn/hardware/avm/b1.c
44645+++ b/drivers/isdn/hardware/avm/b1.c
44646@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
44647 }
44648 if (left) {
44649 if (t4file->user) {
44650- if (copy_from_user(buf, dp, left))
44651+ if (left > sizeof buf || copy_from_user(buf, dp, left))
44652 return -EFAULT;
44653 } else {
44654 memcpy(buf, dp, left);
44655@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
44656 }
44657 if (left) {
44658 if (config->user) {
44659- if (copy_from_user(buf, dp, left))
44660+ if (left > sizeof buf || copy_from_user(buf, dp, left))
44661 return -EFAULT;
44662 } else {
44663 memcpy(buf, dp, left);
44664diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
44665index 9b856e1..fa03c92 100644
44666--- a/drivers/isdn/i4l/isdn_common.c
44667+++ b/drivers/isdn/i4l/isdn_common.c
44668@@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
44669 } else
44670 return -EINVAL;
44671 case IIOCDBGVAR:
44672+ if (!capable(CAP_SYS_RAWIO))
44673+ return -EPERM;
44674 if (arg) {
44675 if (copy_to_user(argp, &dev, sizeof(ulong)))
44676 return -EFAULT;
44677diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
44678index 91d5730..336523e 100644
44679--- a/drivers/isdn/i4l/isdn_concap.c
44680+++ b/drivers/isdn/i4l/isdn_concap.c
44681@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
44682 }
44683
44684 struct concap_device_ops isdn_concap_reliable_dl_dops = {
44685- &isdn_concap_dl_data_req,
44686- &isdn_concap_dl_connect_req,
44687- &isdn_concap_dl_disconn_req
44688+ .data_req = &isdn_concap_dl_data_req,
44689+ .connect_req = &isdn_concap_dl_connect_req,
44690+ .disconn_req = &isdn_concap_dl_disconn_req
44691 };
44692
44693 /* The following should better go into a dedicated source file such that
44694diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
44695index 3c5f249..5fac4d0 100644
44696--- a/drivers/isdn/i4l/isdn_tty.c
44697+++ b/drivers/isdn/i4l/isdn_tty.c
44698@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
44699
44700 #ifdef ISDN_DEBUG_MODEM_OPEN
44701 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
44702- port->count);
44703+ atomic_read(&port->count));
44704 #endif
44705- port->count++;
44706+ atomic_inc(&port->count);
44707 port->tty = tty;
44708 /*
44709 * Start up serial port
44710@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44711 #endif
44712 return;
44713 }
44714- if ((tty->count == 1) && (port->count != 1)) {
44715+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
44716 /*
44717 * Uh, oh. tty->count is 1, which means that the tty
44718 * structure will be freed. Info->count should always
44719@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44720 * serial port won't be shutdown.
44721 */
44722 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
44723- "info->count is %d\n", port->count);
44724- port->count = 1;
44725+ "info->count is %d\n", atomic_read(&port->count));
44726+ atomic_set(&port->count, 1);
44727 }
44728- if (--port->count < 0) {
44729+ if (atomic_dec_return(&port->count) < 0) {
44730 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
44731- info->line, port->count);
44732- port->count = 0;
44733+ info->line, atomic_read(&port->count));
44734+ atomic_set(&port->count, 0);
44735 }
44736- if (port->count) {
44737+ if (atomic_read(&port->count)) {
44738 #ifdef ISDN_DEBUG_MODEM_OPEN
44739 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
44740 #endif
44741@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
44742 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
44743 return;
44744 isdn_tty_shutdown(info);
44745- port->count = 0;
44746+ atomic_set(&port->count, 0);
44747 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44748 port->tty = NULL;
44749 wake_up_interruptible(&port->open_wait);
44750@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
44751 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
44752 modem_info *info = &dev->mdm.info[i];
44753
44754- if (info->port.count == 0)
44755+ if (atomic_read(&info->port.count) == 0)
44756 continue;
44757 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
44758 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
44759diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
44760index e2d4e58..40cd045 100644
44761--- a/drivers/isdn/i4l/isdn_x25iface.c
44762+++ b/drivers/isdn/i4l/isdn_x25iface.c
44763@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
44764
44765
44766 static struct concap_proto_ops ix25_pops = {
44767- &isdn_x25iface_proto_new,
44768- &isdn_x25iface_proto_del,
44769- &isdn_x25iface_proto_restart,
44770- &isdn_x25iface_proto_close,
44771- &isdn_x25iface_xmit,
44772- &isdn_x25iface_receive,
44773- &isdn_x25iface_connect_ind,
44774- &isdn_x25iface_disconn_ind
44775+ .proto_new = &isdn_x25iface_proto_new,
44776+ .proto_del = &isdn_x25iface_proto_del,
44777+ .restart = &isdn_x25iface_proto_restart,
44778+ .close = &isdn_x25iface_proto_close,
44779+ .encap_and_xmit = &isdn_x25iface_xmit,
44780+ .data_ind = &isdn_x25iface_receive,
44781+ .connect_ind = &isdn_x25iface_connect_ind,
44782+ .disconn_ind = &isdn_x25iface_disconn_ind
44783 };
44784
44785 /* error message helper function */
44786diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
44787index 6a7447c..cae33fe 100644
44788--- a/drivers/isdn/icn/icn.c
44789+++ b/drivers/isdn/icn/icn.c
44790@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
44791 if (count > len)
44792 count = len;
44793 if (user) {
44794- if (copy_from_user(msg, buf, count))
44795+ if (count > sizeof msg || copy_from_user(msg, buf, count))
44796 return -EFAULT;
44797 } else
44798 memcpy(msg, buf, count);
44799diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
44800index a4f05c5..1433bc5 100644
44801--- a/drivers/isdn/mISDN/dsp_cmx.c
44802+++ b/drivers/isdn/mISDN/dsp_cmx.c
44803@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
44804 static u16 dsp_count; /* last sample count */
44805 static int dsp_count_valid; /* if we have last sample count */
44806
44807-void
44808+void __intentional_overflow(-1)
44809 dsp_cmx_send(void *arg)
44810 {
44811 struct dsp_conf *conf;
44812diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
44813index f58a354..fbae176 100644
44814--- a/drivers/leds/leds-clevo-mail.c
44815+++ b/drivers/leds/leds-clevo-mail.c
44816@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
44817 * detected as working, but in reality it is not) as low as
44818 * possible.
44819 */
44820-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
44821+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
44822 {
44823 .callback = clevo_mail_led_dmi_callback,
44824 .ident = "Clevo D410J",
44825diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
44826index 046cb70..6b20d39 100644
44827--- a/drivers/leds/leds-ss4200.c
44828+++ b/drivers/leds/leds-ss4200.c
44829@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
44830 * detected as working, but in reality it is not) as low as
44831 * possible.
44832 */
44833-static struct dmi_system_id nas_led_whitelist[] __initdata = {
44834+static struct dmi_system_id nas_led_whitelist[] __initconst = {
44835 {
44836 .callback = ss4200_led_dmi_callback,
44837 .ident = "Intel SS4200-E",
44838diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
44839index 6590558..a74c5dd 100644
44840--- a/drivers/lguest/core.c
44841+++ b/drivers/lguest/core.c
44842@@ -96,9 +96,17 @@ static __init int map_switcher(void)
44843 * The end address needs +1 because __get_vm_area allocates an
44844 * extra guard page, so we need space for that.
44845 */
44846+
44847+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
44848+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44849+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
44850+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44851+#else
44852 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44853 VM_ALLOC, switcher_addr, switcher_addr
44854 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44855+#endif
44856+
44857 if (!switcher_vma) {
44858 err = -ENOMEM;
44859 printk("lguest: could not map switcher pages high\n");
44860@@ -121,7 +129,7 @@ static __init int map_switcher(void)
44861 * Now the Switcher is mapped at the right address, we can't fail!
44862 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
44863 */
44864- memcpy(switcher_vma->addr, start_switcher_text,
44865+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
44866 end_switcher_text - start_switcher_text);
44867
44868 printk(KERN_INFO "lguest: mapped switcher at %p\n",
44869diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
44870index e8b55c3..3514c37 100644
44871--- a/drivers/lguest/page_tables.c
44872+++ b/drivers/lguest/page_tables.c
44873@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
44874 /*:*/
44875
44876 #ifdef CONFIG_X86_PAE
44877-static void release_pmd(pmd_t *spmd)
44878+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
44879 {
44880 /* If the entry's not present, there's nothing to release. */
44881 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
44882diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
44883index 922a1ac..9dd0c2a 100644
44884--- a/drivers/lguest/x86/core.c
44885+++ b/drivers/lguest/x86/core.c
44886@@ -59,7 +59,7 @@ static struct {
44887 /* Offset from where switcher.S was compiled to where we've copied it */
44888 static unsigned long switcher_offset(void)
44889 {
44890- return switcher_addr - (unsigned long)start_switcher_text;
44891+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
44892 }
44893
44894 /* This cpu's struct lguest_pages (after the Switcher text page) */
44895@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
44896 * These copies are pretty cheap, so we do them unconditionally: */
44897 /* Save the current Host top-level page directory.
44898 */
44899+
44900+#ifdef CONFIG_PAX_PER_CPU_PGD
44901+ pages->state.host_cr3 = read_cr3();
44902+#else
44903 pages->state.host_cr3 = __pa(current->mm->pgd);
44904+#endif
44905+
44906 /*
44907 * Set up the Guest's page tables to see this CPU's pages (and no
44908 * other CPU's pages).
44909@@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
44910 * compiled-in switcher code and the high-mapped copy we just made.
44911 */
44912 for (i = 0; i < IDT_ENTRIES; i++)
44913- default_idt_entries[i] += switcher_offset();
44914+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
44915
44916 /*
44917 * Set up the Switcher's per-cpu areas.
44918@@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
44919 * it will be undisturbed when we switch. To change %cs and jump we
44920 * need this structure to feed to Intel's "lcall" instruction.
44921 */
44922- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
44923+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
44924 lguest_entry.segment = LGUEST_CS;
44925
44926 /*
44927diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
44928index 40634b0..4f5855e 100644
44929--- a/drivers/lguest/x86/switcher_32.S
44930+++ b/drivers/lguest/x86/switcher_32.S
44931@@ -87,6 +87,7 @@
44932 #include <asm/page.h>
44933 #include <asm/segment.h>
44934 #include <asm/lguest.h>
44935+#include <asm/processor-flags.h>
44936
44937 // We mark the start of the code to copy
44938 // It's placed in .text tho it's never run here
44939@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
44940 // Changes type when we load it: damn Intel!
44941 // For after we switch over our page tables
44942 // That entry will be read-only: we'd crash.
44943+
44944+#ifdef CONFIG_PAX_KERNEXEC
44945+ mov %cr0, %edx
44946+ xor $X86_CR0_WP, %edx
44947+ mov %edx, %cr0
44948+#endif
44949+
44950 movl $(GDT_ENTRY_TSS*8), %edx
44951 ltr %dx
44952
44953@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
44954 // Let's clear it again for our return.
44955 // The GDT descriptor of the Host
44956 // Points to the table after two "size" bytes
44957- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
44958+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
44959 // Clear "used" from type field (byte 5, bit 2)
44960- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
44961+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
44962+
44963+#ifdef CONFIG_PAX_KERNEXEC
44964+ mov %cr0, %eax
44965+ xor $X86_CR0_WP, %eax
44966+ mov %eax, %cr0
44967+#endif
44968
44969 // Once our page table's switched, the Guest is live!
44970 // The Host fades as we run this final step.
44971@@ -295,13 +309,12 @@ deliver_to_host:
44972 // I consulted gcc, and it gave
44973 // These instructions, which I gladly credit:
44974 leal (%edx,%ebx,8), %eax
44975- movzwl (%eax),%edx
44976- movl 4(%eax), %eax
44977- xorw %ax, %ax
44978- orl %eax, %edx
44979+ movl 4(%eax), %edx
44980+ movw (%eax), %dx
44981 // Now the address of the handler's in %edx
44982 // We call it now: its "iret" drops us home.
44983- jmp *%edx
44984+ ljmp $__KERNEL_CS, $1f
44985+1: jmp *%edx
44986
44987 // Every interrupt can come to us here
44988 // But we must truly tell each apart.
44989diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
44990index a08e3ee..df8ade2 100644
44991--- a/drivers/md/bcache/closure.h
44992+++ b/drivers/md/bcache/closure.h
44993@@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
44994 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
44995 struct workqueue_struct *wq)
44996 {
44997- BUG_ON(object_is_on_stack(cl));
44998+ BUG_ON(object_starts_on_stack(cl));
44999 closure_set_ip(cl);
45000 cl->fn = fn;
45001 cl->wq = wq;
45002diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
45003index 67f8b31..9418f2b 100644
45004--- a/drivers/md/bitmap.c
45005+++ b/drivers/md/bitmap.c
45006@@ -1775,7 +1775,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
45007 chunk_kb ? "KB" : "B");
45008 if (bitmap->storage.file) {
45009 seq_printf(seq, ", file: ");
45010- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
45011+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
45012 }
45013
45014 seq_printf(seq, "\n");
45015diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
45016index 5152142..623d141 100644
45017--- a/drivers/md/dm-ioctl.c
45018+++ b/drivers/md/dm-ioctl.c
45019@@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
45020 cmd == DM_LIST_VERSIONS_CMD)
45021 return 0;
45022
45023- if ((cmd == DM_DEV_CREATE_CMD)) {
45024+ if (cmd == DM_DEV_CREATE_CMD) {
45025 if (!*param->name) {
45026 DMWARN("name not supplied when creating device");
45027 return -EINVAL;
45028diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
45029index 7dfdb5c..4caada6 100644
45030--- a/drivers/md/dm-raid1.c
45031+++ b/drivers/md/dm-raid1.c
45032@@ -40,7 +40,7 @@ enum dm_raid1_error {
45033
45034 struct mirror {
45035 struct mirror_set *ms;
45036- atomic_t error_count;
45037+ atomic_unchecked_t error_count;
45038 unsigned long error_type;
45039 struct dm_dev *dev;
45040 sector_t offset;
45041@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
45042 struct mirror *m;
45043
45044 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
45045- if (!atomic_read(&m->error_count))
45046+ if (!atomic_read_unchecked(&m->error_count))
45047 return m;
45048
45049 return NULL;
45050@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
45051 * simple way to tell if a device has encountered
45052 * errors.
45053 */
45054- atomic_inc(&m->error_count);
45055+ atomic_inc_unchecked(&m->error_count);
45056
45057 if (test_and_set_bit(error_type, &m->error_type))
45058 return;
45059@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
45060 struct mirror *m = get_default_mirror(ms);
45061
45062 do {
45063- if (likely(!atomic_read(&m->error_count)))
45064+ if (likely(!atomic_read_unchecked(&m->error_count)))
45065 return m;
45066
45067 if (m-- == ms->mirror)
45068@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
45069 {
45070 struct mirror *default_mirror = get_default_mirror(m->ms);
45071
45072- return !atomic_read(&default_mirror->error_count);
45073+ return !atomic_read_unchecked(&default_mirror->error_count);
45074 }
45075
45076 static int mirror_available(struct mirror_set *ms, struct bio *bio)
45077@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
45078 */
45079 if (likely(region_in_sync(ms, region, 1)))
45080 m = choose_mirror(ms, bio->bi_iter.bi_sector);
45081- else if (m && atomic_read(&m->error_count))
45082+ else if (m && atomic_read_unchecked(&m->error_count))
45083 m = NULL;
45084
45085 if (likely(m))
45086@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
45087 }
45088
45089 ms->mirror[mirror].ms = ms;
45090- atomic_set(&(ms->mirror[mirror].error_count), 0);
45091+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
45092 ms->mirror[mirror].error_type = 0;
45093 ms->mirror[mirror].offset = offset;
45094
45095@@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
45096 */
45097 static char device_status_char(struct mirror *m)
45098 {
45099- if (!atomic_read(&(m->error_count)))
45100+ if (!atomic_read_unchecked(&(m->error_count)))
45101 return 'A';
45102
45103 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
45104diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
45105index 28a9012..9c0f6a5 100644
45106--- a/drivers/md/dm-stats.c
45107+++ b/drivers/md/dm-stats.c
45108@@ -382,7 +382,7 @@ do_sync_free:
45109 synchronize_rcu_expedited();
45110 dm_stat_free(&s->rcu_head);
45111 } else {
45112- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
45113+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
45114 call_rcu(&s->rcu_head, dm_stat_free);
45115 }
45116 return 0;
45117@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
45118 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
45119 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
45120 ));
45121- ACCESS_ONCE(last->last_sector) = end_sector;
45122- ACCESS_ONCE(last->last_rw) = bi_rw;
45123+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
45124+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
45125 }
45126
45127 rcu_read_lock();
45128diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
45129index d1600d2..4c3af3a 100644
45130--- a/drivers/md/dm-stripe.c
45131+++ b/drivers/md/dm-stripe.c
45132@@ -21,7 +21,7 @@ struct stripe {
45133 struct dm_dev *dev;
45134 sector_t physical_start;
45135
45136- atomic_t error_count;
45137+ atomic_unchecked_t error_count;
45138 };
45139
45140 struct stripe_c {
45141@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
45142 kfree(sc);
45143 return r;
45144 }
45145- atomic_set(&(sc->stripe[i].error_count), 0);
45146+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
45147 }
45148
45149 ti->private = sc;
45150@@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
45151 DMEMIT("%d ", sc->stripes);
45152 for (i = 0; i < sc->stripes; i++) {
45153 DMEMIT("%s ", sc->stripe[i].dev->name);
45154- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
45155+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
45156 'D' : 'A';
45157 }
45158 buffer[i] = '\0';
45159@@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
45160 */
45161 for (i = 0; i < sc->stripes; i++)
45162 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
45163- atomic_inc(&(sc->stripe[i].error_count));
45164- if (atomic_read(&(sc->stripe[i].error_count)) <
45165+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
45166+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
45167 DM_IO_ERROR_THRESHOLD)
45168 schedule_work(&sc->trigger_event);
45169 }
45170diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
45171index f9c6cb8..e272df6 100644
45172--- a/drivers/md/dm-table.c
45173+++ b/drivers/md/dm-table.c
45174@@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
45175 static int open_dev(struct dm_dev_internal *d, dev_t dev,
45176 struct mapped_device *md)
45177 {
45178- static char *_claim_ptr = "I belong to device-mapper";
45179+ static char _claim_ptr[] = "I belong to device-mapper";
45180 struct block_device *bdev;
45181
45182 int r;
45183@@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
45184 if (!dev_size)
45185 return 0;
45186
45187- if ((start >= dev_size) || (start + len > dev_size)) {
45188+ if ((start >= dev_size) || (len > dev_size - start)) {
45189 DMWARN("%s: %s too small for target: "
45190 "start=%llu, len=%llu, dev_size=%llu",
45191 dm_device_name(ti->table->md), bdevname(bdev, b),
45192diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
45193index e9d33ad..dae9880d 100644
45194--- a/drivers/md/dm-thin-metadata.c
45195+++ b/drivers/md/dm-thin-metadata.c
45196@@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
45197 {
45198 pmd->info.tm = pmd->tm;
45199 pmd->info.levels = 2;
45200- pmd->info.value_type.context = pmd->data_sm;
45201+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
45202 pmd->info.value_type.size = sizeof(__le64);
45203 pmd->info.value_type.inc = data_block_inc;
45204 pmd->info.value_type.dec = data_block_dec;
45205@@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
45206
45207 pmd->bl_info.tm = pmd->tm;
45208 pmd->bl_info.levels = 1;
45209- pmd->bl_info.value_type.context = pmd->data_sm;
45210+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
45211 pmd->bl_info.value_type.size = sizeof(__le64);
45212 pmd->bl_info.value_type.inc = data_block_inc;
45213 pmd->bl_info.value_type.dec = data_block_dec;
45214diff --git a/drivers/md/dm.c b/drivers/md/dm.c
45215index 32b958d..34011e8 100644
45216--- a/drivers/md/dm.c
45217+++ b/drivers/md/dm.c
45218@@ -180,9 +180,9 @@ struct mapped_device {
45219 /*
45220 * Event handling.
45221 */
45222- atomic_t event_nr;
45223+ atomic_unchecked_t event_nr;
45224 wait_queue_head_t eventq;
45225- atomic_t uevent_seq;
45226+ atomic_unchecked_t uevent_seq;
45227 struct list_head uevent_list;
45228 spinlock_t uevent_lock; /* Protect access to uevent_list */
45229
45230@@ -1952,8 +1952,8 @@ static struct mapped_device *alloc_dev(int minor)
45231 spin_lock_init(&md->deferred_lock);
45232 atomic_set(&md->holders, 1);
45233 atomic_set(&md->open_count, 0);
45234- atomic_set(&md->event_nr, 0);
45235- atomic_set(&md->uevent_seq, 0);
45236+ atomic_set_unchecked(&md->event_nr, 0);
45237+ atomic_set_unchecked(&md->uevent_seq, 0);
45238 INIT_LIST_HEAD(&md->uevent_list);
45239 spin_lock_init(&md->uevent_lock);
45240
45241@@ -2107,7 +2107,7 @@ static void event_callback(void *context)
45242
45243 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
45244
45245- atomic_inc(&md->event_nr);
45246+ atomic_inc_unchecked(&md->event_nr);
45247 wake_up(&md->eventq);
45248 }
45249
45250@@ -2800,18 +2800,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
45251
45252 uint32_t dm_next_uevent_seq(struct mapped_device *md)
45253 {
45254- return atomic_add_return(1, &md->uevent_seq);
45255+ return atomic_add_return_unchecked(1, &md->uevent_seq);
45256 }
45257
45258 uint32_t dm_get_event_nr(struct mapped_device *md)
45259 {
45260- return atomic_read(&md->event_nr);
45261+ return atomic_read_unchecked(&md->event_nr);
45262 }
45263
45264 int dm_wait_event(struct mapped_device *md, int event_nr)
45265 {
45266 return wait_event_interruptible(md->eventq,
45267- (event_nr != atomic_read(&md->event_nr)));
45268+ (event_nr != atomic_read_unchecked(&md->event_nr)));
45269 }
45270
45271 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
45272diff --git a/drivers/md/md.c b/drivers/md/md.c
45273index b7f603c..723d2bd 100644
45274--- a/drivers/md/md.c
45275+++ b/drivers/md/md.c
45276@@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
45277 * start build, activate spare
45278 */
45279 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
45280-static atomic_t md_event_count;
45281+static atomic_unchecked_t md_event_count;
45282 void md_new_event(struct mddev *mddev)
45283 {
45284- atomic_inc(&md_event_count);
45285+ atomic_inc_unchecked(&md_event_count);
45286 wake_up(&md_event_waiters);
45287 }
45288 EXPORT_SYMBOL_GPL(md_new_event);
45289@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
45290 */
45291 static void md_new_event_inintr(struct mddev *mddev)
45292 {
45293- atomic_inc(&md_event_count);
45294+ atomic_inc_unchecked(&md_event_count);
45295 wake_up(&md_event_waiters);
45296 }
45297
45298@@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
45299 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
45300 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
45301 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
45302- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
45303+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
45304
45305 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
45306 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
45307@@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
45308 else
45309 sb->resync_offset = cpu_to_le64(0);
45310
45311- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
45312+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
45313
45314 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
45315 sb->size = cpu_to_le64(mddev->dev_sectors);
45316@@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
45317 static ssize_t
45318 errors_show(struct md_rdev *rdev, char *page)
45319 {
45320- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
45321+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
45322 }
45323
45324 static ssize_t
45325@@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
45326 char *e;
45327 unsigned long n = simple_strtoul(buf, &e, 10);
45328 if (*buf && (*e == 0 || *e == '\n')) {
45329- atomic_set(&rdev->corrected_errors, n);
45330+ atomic_set_unchecked(&rdev->corrected_errors, n);
45331 return len;
45332 }
45333 return -EINVAL;
45334@@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
45335 rdev->sb_loaded = 0;
45336 rdev->bb_page = NULL;
45337 atomic_set(&rdev->nr_pending, 0);
45338- atomic_set(&rdev->read_errors, 0);
45339- atomic_set(&rdev->corrected_errors, 0);
45340+ atomic_set_unchecked(&rdev->read_errors, 0);
45341+ atomic_set_unchecked(&rdev->corrected_errors, 0);
45342
45343 INIT_LIST_HEAD(&rdev->same_set);
45344 init_waitqueue_head(&rdev->blocked_wait);
45345@@ -7072,7 +7072,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
45346
45347 spin_unlock(&pers_lock);
45348 seq_printf(seq, "\n");
45349- seq->poll_event = atomic_read(&md_event_count);
45350+ seq->poll_event = atomic_read_unchecked(&md_event_count);
45351 return 0;
45352 }
45353 if (v == (void*)2) {
45354@@ -7175,7 +7175,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
45355 return error;
45356
45357 seq = file->private_data;
45358- seq->poll_event = atomic_read(&md_event_count);
45359+ seq->poll_event = atomic_read_unchecked(&md_event_count);
45360 return error;
45361 }
45362
45363@@ -7192,7 +7192,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
45364 /* always allow read */
45365 mask = POLLIN | POLLRDNORM;
45366
45367- if (seq->poll_event != atomic_read(&md_event_count))
45368+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
45369 mask |= POLLERR | POLLPRI;
45370 return mask;
45371 }
45372@@ -7236,7 +7236,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
45373 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
45374 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
45375 (int)part_stat_read(&disk->part0, sectors[1]) -
45376- atomic_read(&disk->sync_io);
45377+ atomic_read_unchecked(&disk->sync_io);
45378 /* sync IO will cause sync_io to increase before the disk_stats
45379 * as sync_io is counted when a request starts, and
45380 * disk_stats is counted when it completes.
45381diff --git a/drivers/md/md.h b/drivers/md/md.h
45382index a49d991..3582bb7 100644
45383--- a/drivers/md/md.h
45384+++ b/drivers/md/md.h
45385@@ -94,13 +94,13 @@ struct md_rdev {
45386 * only maintained for arrays that
45387 * support hot removal
45388 */
45389- atomic_t read_errors; /* number of consecutive read errors that
45390+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
45391 * we have tried to ignore.
45392 */
45393 struct timespec last_read_error; /* monotonic time since our
45394 * last read error
45395 */
45396- atomic_t corrected_errors; /* number of corrected read errors,
45397+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
45398 * for reporting to userspace and storing
45399 * in superblock.
45400 */
45401@@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
45402
45403 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
45404 {
45405- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
45406+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
45407 }
45408
45409 struct md_personality
45410diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
45411index 786b689..ea8c956 100644
45412--- a/drivers/md/persistent-data/dm-space-map-metadata.c
45413+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
45414@@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
45415 * Flick into a mode where all blocks get allocated in the new area.
45416 */
45417 smm->begin = old_len;
45418- memcpy(sm, &bootstrap_ops, sizeof(*sm));
45419+ memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
45420
45421 /*
45422 * Extend.
45423@@ -710,7 +710,7 @@ out:
45424 /*
45425 * Switch back to normal behaviour.
45426 */
45427- memcpy(sm, &ops, sizeof(*sm));
45428+ memcpy((void *)sm, &ops, sizeof(*sm));
45429 return r;
45430 }
45431
45432diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
45433index 3e6d115..ffecdeb 100644
45434--- a/drivers/md/persistent-data/dm-space-map.h
45435+++ b/drivers/md/persistent-data/dm-space-map.h
45436@@ -71,6 +71,7 @@ struct dm_space_map {
45437 dm_sm_threshold_fn fn,
45438 void *context);
45439 };
45440+typedef struct dm_space_map __no_const dm_space_map_no_const;
45441
45442 /*----------------------------------------------------------------*/
45443
45444diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
45445index 55de4f6..b1c57fe 100644
45446--- a/drivers/md/raid1.c
45447+++ b/drivers/md/raid1.c
45448@@ -1936,7 +1936,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
45449 if (r1_sync_page_io(rdev, sect, s,
45450 bio->bi_io_vec[idx].bv_page,
45451 READ) != 0)
45452- atomic_add(s, &rdev->corrected_errors);
45453+ atomic_add_unchecked(s, &rdev->corrected_errors);
45454 }
45455 sectors -= s;
45456 sect += s;
45457@@ -2170,7 +2170,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
45458 !test_bit(Faulty, &rdev->flags)) {
45459 if (r1_sync_page_io(rdev, sect, s,
45460 conf->tmppage, READ)) {
45461- atomic_add(s, &rdev->corrected_errors);
45462+ atomic_add_unchecked(s, &rdev->corrected_errors);
45463 printk(KERN_INFO
45464 "md/raid1:%s: read error corrected "
45465 "(%d sectors at %llu on %s)\n",
45466diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
45467index 6703751..187af1e 100644
45468--- a/drivers/md/raid10.c
45469+++ b/drivers/md/raid10.c
45470@@ -1948,7 +1948,7 @@ static void end_sync_read(struct bio *bio, int error)
45471 /* The write handler will notice the lack of
45472 * R10BIO_Uptodate and record any errors etc
45473 */
45474- atomic_add(r10_bio->sectors,
45475+ atomic_add_unchecked(r10_bio->sectors,
45476 &conf->mirrors[d].rdev->corrected_errors);
45477
45478 /* for reconstruct, we always reschedule after a read.
45479@@ -2306,7 +2306,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
45480 {
45481 struct timespec cur_time_mon;
45482 unsigned long hours_since_last;
45483- unsigned int read_errors = atomic_read(&rdev->read_errors);
45484+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
45485
45486 ktime_get_ts(&cur_time_mon);
45487
45488@@ -2328,9 +2328,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
45489 * overflowing the shift of read_errors by hours_since_last.
45490 */
45491 if (hours_since_last >= 8 * sizeof(read_errors))
45492- atomic_set(&rdev->read_errors, 0);
45493+ atomic_set_unchecked(&rdev->read_errors, 0);
45494 else
45495- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
45496+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
45497 }
45498
45499 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
45500@@ -2384,8 +2384,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
45501 return;
45502
45503 check_decay_read_errors(mddev, rdev);
45504- atomic_inc(&rdev->read_errors);
45505- if (atomic_read(&rdev->read_errors) > max_read_errors) {
45506+ atomic_inc_unchecked(&rdev->read_errors);
45507+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
45508 char b[BDEVNAME_SIZE];
45509 bdevname(rdev->bdev, b);
45510
45511@@ -2393,7 +2393,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
45512 "md/raid10:%s: %s: Raid device exceeded "
45513 "read_error threshold [cur %d:max %d]\n",
45514 mdname(mddev), b,
45515- atomic_read(&rdev->read_errors), max_read_errors);
45516+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
45517 printk(KERN_NOTICE
45518 "md/raid10:%s: %s: Failing raid device\n",
45519 mdname(mddev), b);
45520@@ -2548,7 +2548,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
45521 sect +
45522 choose_data_offset(r10_bio, rdev)),
45523 bdevname(rdev->bdev, b));
45524- atomic_add(s, &rdev->corrected_errors);
45525+ atomic_add_unchecked(s, &rdev->corrected_errors);
45526 }
45527
45528 rdev_dec_pending(rdev, mddev);
45529diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
45530index 9f0fbec..991e7a1 100644
45531--- a/drivers/md/raid5.c
45532+++ b/drivers/md/raid5.c
45533@@ -1735,6 +1735,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
45534 return 1;
45535 }
45536
45537+#ifdef CONFIG_GRKERNSEC_HIDESYM
45538+static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
45539+#endif
45540+
45541 static int grow_stripes(struct r5conf *conf, int num)
45542 {
45543 struct kmem_cache *sc;
45544@@ -1746,7 +1750,11 @@ static int grow_stripes(struct r5conf *conf, int num)
45545 "raid%d-%s", conf->level, mdname(conf->mddev));
45546 else
45547 sprintf(conf->cache_name[0],
45548+#ifdef CONFIG_GRKERNSEC_HIDESYM
45549+ "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
45550+#else
45551 "raid%d-%p", conf->level, conf->mddev);
45552+#endif
45553 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
45554
45555 conf->active_name = 0;
45556@@ -2022,21 +2030,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
45557 mdname(conf->mddev), STRIPE_SECTORS,
45558 (unsigned long long)s,
45559 bdevname(rdev->bdev, b));
45560- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
45561+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
45562 clear_bit(R5_ReadError, &sh->dev[i].flags);
45563 clear_bit(R5_ReWrite, &sh->dev[i].flags);
45564 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
45565 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
45566
45567- if (atomic_read(&rdev->read_errors))
45568- atomic_set(&rdev->read_errors, 0);
45569+ if (atomic_read_unchecked(&rdev->read_errors))
45570+ atomic_set_unchecked(&rdev->read_errors, 0);
45571 } else {
45572 const char *bdn = bdevname(rdev->bdev, b);
45573 int retry = 0;
45574 int set_bad = 0;
45575
45576 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
45577- atomic_inc(&rdev->read_errors);
45578+ atomic_inc_unchecked(&rdev->read_errors);
45579 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
45580 printk_ratelimited(
45581 KERN_WARNING
45582@@ -2064,7 +2072,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
45583 mdname(conf->mddev),
45584 (unsigned long long)s,
45585 bdn);
45586- } else if (atomic_read(&rdev->read_errors)
45587+ } else if (atomic_read_unchecked(&rdev->read_errors)
45588 > conf->max_nr_stripes)
45589 printk(KERN_WARNING
45590 "md/raid:%s: Too many read errors, failing device %s.\n",
45591diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
45592index 983db75..ef9248c 100644
45593--- a/drivers/media/dvb-core/dvbdev.c
45594+++ b/drivers/media/dvb-core/dvbdev.c
45595@@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
45596 const struct dvb_device *template, void *priv, int type)
45597 {
45598 struct dvb_device *dvbdev;
45599- struct file_operations *dvbdevfops;
45600+ file_operations_no_const *dvbdevfops;
45601 struct device *clsdev;
45602 int minor;
45603 int id;
45604diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
45605index 539f4db..cdd403b 100644
45606--- a/drivers/media/dvb-frontends/af9033.h
45607+++ b/drivers/media/dvb-frontends/af9033.h
45608@@ -82,7 +82,7 @@ struct af9033_ops {
45609 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
45610 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
45611 int onoff);
45612-};
45613+} __no_const;
45614
45615
45616 #if IS_ENABLED(CONFIG_DVB_AF9033)
45617diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
45618index 9b6c3bb..baeb5c7 100644
45619--- a/drivers/media/dvb-frontends/dib3000.h
45620+++ b/drivers/media/dvb-frontends/dib3000.h
45621@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
45622 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
45623 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
45624 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
45625-};
45626+} __no_const;
45627
45628 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
45629 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
45630diff --git a/drivers/media/dvb-frontends/dib7000p.h b/drivers/media/dvb-frontends/dib7000p.h
45631index 1fea0e9..321ce8f 100644
45632--- a/drivers/media/dvb-frontends/dib7000p.h
45633+++ b/drivers/media/dvb-frontends/dib7000p.h
45634@@ -64,7 +64,7 @@ struct dib7000p_ops {
45635 int (*get_adc_power)(struct dvb_frontend *fe);
45636 int (*slave_reset)(struct dvb_frontend *fe);
45637 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg);
45638-};
45639+} __no_const;
45640
45641 #if IS_ENABLED(CONFIG_DVB_DIB7000P)
45642 void *dib7000p_attach(struct dib7000p_ops *ops);
45643diff --git a/drivers/media/dvb-frontends/dib8000.h b/drivers/media/dvb-frontends/dib8000.h
45644index 84cc103..5780c54 100644
45645--- a/drivers/media/dvb-frontends/dib8000.h
45646+++ b/drivers/media/dvb-frontends/dib8000.h
45647@@ -61,7 +61,7 @@ struct dib8000_ops {
45648 int (*pid_filter_ctrl)(struct dvb_frontend *fe, u8 onoff);
45649 int (*pid_filter)(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff);
45650 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib8000_config *cfg);
45651-};
45652+} __no_const;
45653
45654 #if IS_ENABLED(CONFIG_DVB_DIB8000)
45655 void *dib8000_attach(struct dib8000_ops *ops);
45656diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
45657index ed8cb90..5ef7f79 100644
45658--- a/drivers/media/pci/cx88/cx88-video.c
45659+++ b/drivers/media/pci/cx88/cx88-video.c
45660@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
45661
45662 /* ------------------------------------------------------------------ */
45663
45664-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45665-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45666-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45667+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45668+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45669+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45670
45671 module_param_array(video_nr, int, NULL, 0444);
45672 module_param_array(vbi_nr, int, NULL, 0444);
45673diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
45674index 802642d..5534900 100644
45675--- a/drivers/media/pci/ivtv/ivtv-driver.c
45676+++ b/drivers/media/pci/ivtv/ivtv-driver.c
45677@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
45678 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
45679
45680 /* ivtv instance counter */
45681-static atomic_t ivtv_instance = ATOMIC_INIT(0);
45682+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
45683
45684 /* Parameter declarations */
45685 static int cardtype[IVTV_MAX_CARDS];
45686diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c b/drivers/media/pci/solo6x10/solo6x10-core.c
45687index 172583d..0f806f4 100644
45688--- a/drivers/media/pci/solo6x10/solo6x10-core.c
45689+++ b/drivers/media/pci/solo6x10/solo6x10-core.c
45690@@ -430,7 +430,7 @@ static void solo_device_release(struct device *dev)
45691
45692 static int solo_sysfs_init(struct solo_dev *solo_dev)
45693 {
45694- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
45695+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
45696 struct device *dev = &solo_dev->dev;
45697 const char *driver;
45698 int i;
45699diff --git a/drivers/media/pci/solo6x10/solo6x10-g723.c b/drivers/media/pci/solo6x10/solo6x10-g723.c
45700index c7141f2..5301fec 100644
45701--- a/drivers/media/pci/solo6x10/solo6x10-g723.c
45702+++ b/drivers/media/pci/solo6x10/solo6x10-g723.c
45703@@ -351,7 +351,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
45704
45705 int solo_g723_init(struct solo_dev *solo_dev)
45706 {
45707- static struct snd_device_ops ops = { NULL };
45708+ static struct snd_device_ops ops = { };
45709 struct snd_card *card;
45710 struct snd_kcontrol_new kctl;
45711 char name[32];
45712diff --git a/drivers/media/pci/solo6x10/solo6x10-p2m.c b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45713index 8c84846..27b4f83 100644
45714--- a/drivers/media/pci/solo6x10/solo6x10-p2m.c
45715+++ b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45716@@ -73,7 +73,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
45717
45718 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
45719 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
45720- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
45721+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
45722 if (p2m_id < 0)
45723 p2m_id = -p2m_id;
45724 }
45725diff --git a/drivers/media/pci/solo6x10/solo6x10.h b/drivers/media/pci/solo6x10/solo6x10.h
45726index c6154b0..73e4ae9 100644
45727--- a/drivers/media/pci/solo6x10/solo6x10.h
45728+++ b/drivers/media/pci/solo6x10/solo6x10.h
45729@@ -219,7 +219,7 @@ struct solo_dev {
45730
45731 /* P2M DMA Engine */
45732 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
45733- atomic_t p2m_count;
45734+ atomic_unchecked_t p2m_count;
45735 int p2m_jiffies;
45736 unsigned int p2m_timeouts;
45737
45738diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
45739index 2d177fa..5b925a1 100644
45740--- a/drivers/media/platform/omap/omap_vout.c
45741+++ b/drivers/media/platform/omap/omap_vout.c
45742@@ -63,7 +63,6 @@ enum omap_vout_channels {
45743 OMAP_VIDEO2,
45744 };
45745
45746-static struct videobuf_queue_ops video_vbq_ops;
45747 /* Variables configurable through module params*/
45748 static u32 video1_numbuffers = 3;
45749 static u32 video2_numbuffers = 3;
45750@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
45751 {
45752 struct videobuf_queue *q;
45753 struct omap_vout_device *vout = NULL;
45754+ static struct videobuf_queue_ops video_vbq_ops = {
45755+ .buf_setup = omap_vout_buffer_setup,
45756+ .buf_prepare = omap_vout_buffer_prepare,
45757+ .buf_release = omap_vout_buffer_release,
45758+ .buf_queue = omap_vout_buffer_queue,
45759+ };
45760
45761 vout = video_drvdata(file);
45762 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
45763@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
45764 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
45765
45766 q = &vout->vbq;
45767- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
45768- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
45769- video_vbq_ops.buf_release = omap_vout_buffer_release;
45770- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
45771 spin_lock_init(&vout->vbq_lock);
45772
45773 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
45774diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
45775index fb2acc5..a2fcbdc4 100644
45776--- a/drivers/media/platform/s5p-tv/mixer.h
45777+++ b/drivers/media/platform/s5p-tv/mixer.h
45778@@ -156,7 +156,7 @@ struct mxr_layer {
45779 /** layer index (unique identifier) */
45780 int idx;
45781 /** callbacks for layer methods */
45782- struct mxr_layer_ops ops;
45783+ struct mxr_layer_ops *ops;
45784 /** format array */
45785 const struct mxr_format **fmt_array;
45786 /** size of format array */
45787diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45788index 74344c7..a39e70e 100644
45789--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45790+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45791@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
45792 {
45793 struct mxr_layer *layer;
45794 int ret;
45795- struct mxr_layer_ops ops = {
45796+ static struct mxr_layer_ops ops = {
45797 .release = mxr_graph_layer_release,
45798 .buffer_set = mxr_graph_buffer_set,
45799 .stream_set = mxr_graph_stream_set,
45800diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
45801index b713403..53cb5ad 100644
45802--- a/drivers/media/platform/s5p-tv/mixer_reg.c
45803+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
45804@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
45805 layer->update_buf = next;
45806 }
45807
45808- layer->ops.buffer_set(layer, layer->update_buf);
45809+ layer->ops->buffer_set(layer, layer->update_buf);
45810
45811 if (done && done != layer->shadow_buf)
45812 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
45813diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
45814index b4d2696..91df48e 100644
45815--- a/drivers/media/platform/s5p-tv/mixer_video.c
45816+++ b/drivers/media/platform/s5p-tv/mixer_video.c
45817@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
45818 layer->geo.src.height = layer->geo.src.full_height;
45819
45820 mxr_geometry_dump(mdev, &layer->geo);
45821- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45822+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45823 mxr_geometry_dump(mdev, &layer->geo);
45824 }
45825
45826@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
45827 layer->geo.dst.full_width = mbus_fmt.width;
45828 layer->geo.dst.full_height = mbus_fmt.height;
45829 layer->geo.dst.field = mbus_fmt.field;
45830- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45831+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45832
45833 mxr_geometry_dump(mdev, &layer->geo);
45834 }
45835@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
45836 /* set source size to highest accepted value */
45837 geo->src.full_width = max(geo->dst.full_width, pix->width);
45838 geo->src.full_height = max(geo->dst.full_height, pix->height);
45839- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45840+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45841 mxr_geometry_dump(mdev, &layer->geo);
45842 /* set cropping to total visible screen */
45843 geo->src.width = pix->width;
45844@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
45845 geo->src.x_offset = 0;
45846 geo->src.y_offset = 0;
45847 /* assure consistency of geometry */
45848- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45849+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45850 mxr_geometry_dump(mdev, &layer->geo);
45851 /* set full size to lowest possible value */
45852 geo->src.full_width = 0;
45853 geo->src.full_height = 0;
45854- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45855+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45856 mxr_geometry_dump(mdev, &layer->geo);
45857
45858 /* returning results */
45859@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
45860 target->width = s->r.width;
45861 target->height = s->r.height;
45862
45863- layer->ops.fix_geometry(layer, stage, s->flags);
45864+ layer->ops->fix_geometry(layer, stage, s->flags);
45865
45866 /* retrieve update selection rectangle */
45867 res.left = target->x_offset;
45868@@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
45869 mxr_output_get(mdev);
45870
45871 mxr_layer_update_output(layer);
45872- layer->ops.format_set(layer);
45873+ layer->ops->format_set(layer);
45874 /* enabling layer in hardware */
45875 spin_lock_irqsave(&layer->enq_slock, flags);
45876 layer->state = MXR_LAYER_STREAMING;
45877 spin_unlock_irqrestore(&layer->enq_slock, flags);
45878
45879- layer->ops.stream_set(layer, MXR_ENABLE);
45880+ layer->ops->stream_set(layer, MXR_ENABLE);
45881 mxr_streamer_get(mdev);
45882
45883 return 0;
45884@@ -1030,7 +1030,7 @@ static void stop_streaming(struct vb2_queue *vq)
45885 spin_unlock_irqrestore(&layer->enq_slock, flags);
45886
45887 /* disabling layer in hardware */
45888- layer->ops.stream_set(layer, MXR_DISABLE);
45889+ layer->ops->stream_set(layer, MXR_DISABLE);
45890 /* remove one streamer */
45891 mxr_streamer_put(mdev);
45892 /* allow changes in output configuration */
45893@@ -1068,8 +1068,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
45894
45895 void mxr_layer_release(struct mxr_layer *layer)
45896 {
45897- if (layer->ops.release)
45898- layer->ops.release(layer);
45899+ if (layer->ops->release)
45900+ layer->ops->release(layer);
45901 }
45902
45903 void mxr_base_layer_release(struct mxr_layer *layer)
45904@@ -1095,7 +1095,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
45905
45906 layer->mdev = mdev;
45907 layer->idx = idx;
45908- layer->ops = *ops;
45909+ layer->ops = ops;
45910
45911 spin_lock_init(&layer->enq_slock);
45912 INIT_LIST_HEAD(&layer->enq_list);
45913diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45914index c9388c4..ce71ece 100644
45915--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45916+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45917@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
45918 {
45919 struct mxr_layer *layer;
45920 int ret;
45921- struct mxr_layer_ops ops = {
45922+ static struct mxr_layer_ops ops = {
45923 .release = mxr_vp_layer_release,
45924 .buffer_set = mxr_vp_buffer_set,
45925 .stream_set = mxr_vp_stream_set,
45926diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
45927index 8033371..de5bca0 100644
45928--- a/drivers/media/platform/vivi.c
45929+++ b/drivers/media/platform/vivi.c
45930@@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
45931 MODULE_LICENSE("Dual BSD/GPL");
45932 MODULE_VERSION(VIVI_VERSION);
45933
45934-static unsigned video_nr = -1;
45935-module_param(video_nr, uint, 0644);
45936+static int video_nr = -1;
45937+module_param(video_nr, int, 0644);
45938 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
45939
45940 static unsigned n_devs = 1;
45941diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
45942index 82affae..42833ec 100644
45943--- a/drivers/media/radio/radio-cadet.c
45944+++ b/drivers/media/radio/radio-cadet.c
45945@@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45946 unsigned char readbuf[RDS_BUFFER];
45947 int i = 0;
45948
45949+ if (count > RDS_BUFFER)
45950+ return -EFAULT;
45951 mutex_lock(&dev->lock);
45952 if (dev->rdsstat == 0)
45953 cadet_start_rds(dev);
45954@@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45955 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
45956 mutex_unlock(&dev->lock);
45957
45958- if (i && copy_to_user(data, readbuf, i))
45959- return -EFAULT;
45960+ if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
45961+ i = -EFAULT;
45962+
45963 return i;
45964 }
45965
45966diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
45967index 5236035..c622c74 100644
45968--- a/drivers/media/radio/radio-maxiradio.c
45969+++ b/drivers/media/radio/radio-maxiradio.c
45970@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
45971 /* TEA5757 pin mappings */
45972 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
45973
45974-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
45975+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
45976
45977 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
45978 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
45979diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
45980index 050b3bb..79f62b9 100644
45981--- a/drivers/media/radio/radio-shark.c
45982+++ b/drivers/media/radio/radio-shark.c
45983@@ -79,7 +79,7 @@ struct shark_device {
45984 u32 last_val;
45985 };
45986
45987-static atomic_t shark_instance = ATOMIC_INIT(0);
45988+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45989
45990 static void shark_write_val(struct snd_tea575x *tea, u32 val)
45991 {
45992diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
45993index 8654e0d..0608a64 100644
45994--- a/drivers/media/radio/radio-shark2.c
45995+++ b/drivers/media/radio/radio-shark2.c
45996@@ -74,7 +74,7 @@ struct shark_device {
45997 u8 *transfer_buffer;
45998 };
45999
46000-static atomic_t shark_instance = ATOMIC_INIT(0);
46001+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
46002
46003 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
46004 {
46005diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
46006index 633022b..7f10754 100644
46007--- a/drivers/media/radio/radio-si476x.c
46008+++ b/drivers/media/radio/radio-si476x.c
46009@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
46010 struct si476x_radio *radio;
46011 struct v4l2_ctrl *ctrl;
46012
46013- static atomic_t instance = ATOMIC_INIT(0);
46014+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
46015
46016 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
46017 if (!radio)
46018diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c b/drivers/media/usb/dvb-usb/cinergyT2-core.c
46019index 9fd1527..8927230 100644
46020--- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
46021+++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
46022@@ -50,29 +50,73 @@ static struct dvb_usb_device_properties cinergyt2_properties;
46023
46024 static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
46025 {
46026- char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
46027- char result[64];
46028- return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
46029- sizeof(result), 0);
46030+ char *buf;
46031+ char *result;
46032+ int retval;
46033+
46034+ buf = kmalloc(2, GFP_KERNEL);
46035+ if (buf == NULL)
46036+ return -ENOMEM;
46037+ result = kmalloc(64, GFP_KERNEL);
46038+ if (result == NULL) {
46039+ kfree(buf);
46040+ return -ENOMEM;
46041+ }
46042+
46043+ buf[0] = CINERGYT2_EP1_CONTROL_STREAM_TRANSFER;
46044+ buf[1] = enable ? 1 : 0;
46045+
46046+ retval = dvb_usb_generic_rw(adap->dev, buf, 2, result, 64, 0);
46047+
46048+ kfree(buf);
46049+ kfree(result);
46050+ return retval;
46051 }
46052
46053 static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
46054 {
46055- char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
46056- char state[3];
46057- return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
46058+ char *buf;
46059+ char *state;
46060+ int retval;
46061+
46062+ buf = kmalloc(2, GFP_KERNEL);
46063+ if (buf == NULL)
46064+ return -ENOMEM;
46065+ state = kmalloc(3, GFP_KERNEL);
46066+ if (state == NULL) {
46067+ kfree(buf);
46068+ return -ENOMEM;
46069+ }
46070+
46071+ buf[0] = CINERGYT2_EP1_SLEEP_MODE;
46072+ buf[1] = enable ? 1 : 0;
46073+
46074+ retval = dvb_usb_generic_rw(d, buf, 2, state, 3, 0);
46075+
46076+ kfree(buf);
46077+ kfree(state);
46078+ return retval;
46079 }
46080
46081 static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
46082 {
46083- char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
46084- char state[3];
46085+ char *query;
46086+ char *state;
46087 int ret;
46088+ query = kmalloc(1, GFP_KERNEL);
46089+ if (query == NULL)
46090+ return -ENOMEM;
46091+ state = kmalloc(3, GFP_KERNEL);
46092+ if (state == NULL) {
46093+ kfree(query);
46094+ return -ENOMEM;
46095+ }
46096+
46097+ query[0] = CINERGYT2_EP1_GET_FIRMWARE_VERSION;
46098
46099 adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev);
46100
46101- ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
46102- sizeof(state), 0);
46103+ ret = dvb_usb_generic_rw(adap->dev, query, 1, state, 3, 0);
46104 if (ret < 0) {
46105 deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
46106 "state info\n");
46107@@ -80,7 +124,8 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
46108
46109 /* Copy this pointer as we are gonna need it in the release phase */
46110 cinergyt2_usb_device = adap->dev;
46111-
46112+ kfree(query);
46113+ kfree(state);
46114 return 0;
46115 }
46116
46117@@ -141,12 +186,23 @@ static int repeatable_keys[] = {
46118 static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
46119 {
46120 struct cinergyt2_state *st = d->priv;
46121- u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
46122+ u8 *key, *cmd;
46123 int i;
46124
46125+ cmd = kmalloc(1, GFP_KERNEL);
46126+ if (cmd == NULL)
46127+ return -EINVAL;
46128+ key = kzalloc(5, GFP_KERNEL);
46129+ if (key == NULL) {
46130+ kfree(cmd);
46131+ return -EINVAL;
46132+ }
46133+
46134+ cmd[0] = CINERGYT2_EP1_GET_RC_EVENTS;
46135+
46136 *state = REMOTE_NO_KEY_PRESSED;
46137
46138- dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0);
46139+ dvb_usb_generic_rw(d, cmd, 1, key, 5, 0);
46140 if (key[4] == 0xff) {
46141 /* key repeat */
46142 st->rc_counter++;
46143@@ -157,12 +213,12 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
46144 *event = d->last_event;
46145 deb_rc("repeat key, event %x\n",
46146 *event);
46147- return 0;
46148+ goto out;
46149 }
46150 }
46151 deb_rc("repeated key (non repeatable)\n");
46152 }
46153- return 0;
46154+ goto out;
46155 }
46156
46157 /* hack to pass checksum on the custom field */
46158@@ -174,6 +230,9 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
46159
46160 deb_rc("key: %*ph\n", 5, key);
46161 }
46162+out:
46163+ kfree(cmd);
46164+ kfree(key);
46165 return 0;
46166 }
46167
46168diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
46169index c890fe4..f9b2ae6 100644
46170--- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
46171+++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
46172@@ -145,103 +145,176 @@ static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
46173 fe_status_t *status)
46174 {
46175 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46176- struct dvbt_get_status_msg result;
46177- u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46178+ struct dvbt_get_status_msg *result;
46179+ u8 *cmd;
46180 int ret;
46181
46182- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&result,
46183- sizeof(result), 0);
46184+ cmd = kmalloc(1, GFP_KERNEL);
46185+ if (cmd == NULL)
46186+ return -ENOMEM;
46187+ result = kmalloc(sizeof(*result), GFP_KERNEL);
46188+ if (result == NULL) {
46189+ kfree(cmd);
46190+ return -ENOMEM;
46191+ }
46192+
46193+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46194+
46195+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)result,
46196+ sizeof(*result), 0);
46197 if (ret < 0)
46198- return ret;
46199+ goto out;
46200
46201 *status = 0;
46202
46203- if (0xffff - le16_to_cpu(result.gain) > 30)
46204+ if (0xffff - le16_to_cpu(result->gain) > 30)
46205 *status |= FE_HAS_SIGNAL;
46206- if (result.lock_bits & (1 << 6))
46207+ if (result->lock_bits & (1 << 6))
46208 *status |= FE_HAS_LOCK;
46209- if (result.lock_bits & (1 << 5))
46210+ if (result->lock_bits & (1 << 5))
46211 *status |= FE_HAS_SYNC;
46212- if (result.lock_bits & (1 << 4))
46213+ if (result->lock_bits & (1 << 4))
46214 *status |= FE_HAS_CARRIER;
46215- if (result.lock_bits & (1 << 1))
46216+ if (result->lock_bits & (1 << 1))
46217 *status |= FE_HAS_VITERBI;
46218
46219 if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
46220 (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))
46221 *status &= ~FE_HAS_LOCK;
46222
46223- return 0;
46224+out:
46225+ kfree(cmd);
46226+ kfree(result);
46227+ return ret;
46228 }
46229
46230 static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
46231 {
46232 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46233- struct dvbt_get_status_msg status;
46234- char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46235+ struct dvbt_get_status_msg *status;
46236+ char *cmd;
46237 int ret;
46238
46239- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
46240- sizeof(status), 0);
46241+ cmd = kmalloc(1, GFP_KERNEL);
46242+ if (cmd == NULL)
46243+ return -ENOMEM;
46244+ status = kmalloc(sizeof(*status), GFP_KERNEL);
46245+ if (status == NULL) {
46246+ kfree(cmd);
46247+ return -ENOMEM;
46248+ }
46249+
46250+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46251+
46252+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
46253+ sizeof(*status), 0);
46254 if (ret < 0)
46255- return ret;
46256+ goto out;
46257
46258- *ber = le32_to_cpu(status.viterbi_error_rate);
46259+ *ber = le32_to_cpu(status->viterbi_error_rate);
46260+out:
46261+ kfree(cmd);
46262+ kfree(status);
46263 return 0;
46264 }
46265
46266 static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
46267 {
46268 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46269- struct dvbt_get_status_msg status;
46270- u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46271+ struct dvbt_get_status_msg *status;
46272+ u8 *cmd;
46273 int ret;
46274
46275- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&status,
46276- sizeof(status), 0);
46277+ cmd = kmalloc(1, GFP_KERNEL);
46278+ if (cmd == NULL)
46279+ return -ENOMEM;
46280+ status = kmalloc(sizeof(*status), GFP_KERNEL);
46281+ if (status == NULL) {
46282+ kfree(cmd);
46283+ return -ENOMEM;
46284+ }
46285+
46286+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46287+
46288+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)status,
46289+ sizeof(*status), 0);
46290 if (ret < 0) {
46291 err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n",
46292 ret);
46293- return ret;
46294+ goto out;
46295 }
46296- *unc = le32_to_cpu(status.uncorrected_block_count);
46297- return 0;
46298+ *unc = le32_to_cpu(status->uncorrected_block_count);
46299+
46300+out:
46301+ kfree(cmd);
46302+ kfree(status);
46303+ return ret;
46304 }
46305
46306 static int cinergyt2_fe_read_signal_strength(struct dvb_frontend *fe,
46307 u16 *strength)
46308 {
46309 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46310- struct dvbt_get_status_msg status;
46311- char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46312+ struct dvbt_get_status_msg *status;
46313+ char *cmd;
46314 int ret;
46315
46316- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
46317- sizeof(status), 0);
46318+ cmd = kmalloc(1, GFP_KERNEL);
46319+ if (cmd == NULL)
46320+ return -ENOMEM;
46321+ status = kmalloc(sizeof(*status), GFP_KERNEL);
46322+ if (status == NULL) {
46323+ kfree(cmd);
46324+ return -ENOMEM;
46325+ }
46326+
46327+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46328+
46329+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
46330+ sizeof(*status), 0);
46331 if (ret < 0) {
46332 err("cinergyt2_fe_read_signal_strength() Failed!"
46333 " (Error=%d)\n", ret);
46334- return ret;
46335+ goto out;
46336 }
46337- *strength = (0xffff - le16_to_cpu(status.gain));
46338+ *strength = (0xffff - le16_to_cpu(status->gain));
46339+
46340+out:
46341+ kfree(cmd);
46342+ kfree(status);
46343 return 0;
46344 }
46345
46346 static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
46347 {
46348 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46349- struct dvbt_get_status_msg status;
46350- char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46351+ struct dvbt_get_status_msg *status;
46352+ char *cmd;
46353 int ret;
46354
46355- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
46356- sizeof(status), 0);
46357+ cmd = kmalloc(1, GFP_KERNEL);
46358+ if (cmd == NULL)
46359+ return -ENOMEM;
46360+ status = kmalloc(sizeof(*status), GFP_KERNEL);
46361+ if (status == NULL) {
46362+ kfree(cmd);
46363+ return -ENOMEM;
46364+ }
46365+
46366+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46367+
46368+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
46369+ sizeof(*status), 0);
46370 if (ret < 0) {
46371 err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret);
46372- return ret;
46373+ goto out;
46374 }
46375- *snr = (status.snr << 8) | status.snr;
46376- return 0;
46377+ *snr = (status->snr << 8) | status->snr;
46378+
46379+out:
46380+ kfree(cmd);
46381+ kfree(status);
46382+ return ret;
46383 }
46384
46385 static int cinergyt2_fe_init(struct dvb_frontend *fe)
46386@@ -266,35 +339,46 @@ static int cinergyt2_fe_set_frontend(struct dvb_frontend *fe)
46387 {
46388 struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
46389 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46390- struct dvbt_set_parameters_msg param;
46391- char result[2];
46392+ struct dvbt_set_parameters_msg *param;
46393+ char *result;
46394 int err;
46395
46396- param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
46397- param.tps = cpu_to_le16(compute_tps(fep));
46398- param.freq = cpu_to_le32(fep->frequency / 1000);
46399- param.flags = 0;
46400+ result = kmalloc(2, GFP_KERNEL);
46401+ if (result == NULL)
46402+ return -ENOMEM;
46403+ param = kmalloc(sizeof(*param), GFP_KERNEL);
46404+ if (param == NULL) {
46405+ kfree(result);
46406+ return -ENOMEM;
46407+ }
46408+
46409+ param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
46410+ param->tps = cpu_to_le16(compute_tps(fep));
46411+ param->freq = cpu_to_le32(fep->frequency / 1000);
46412+ param->flags = 0;
46413
46414 switch (fep->bandwidth_hz) {
46415 default:
46416 case 8000000:
46417- param.bandwidth = 8;
46418+ param->bandwidth = 8;
46419 break;
46420 case 7000000:
46421- param.bandwidth = 7;
46422+ param->bandwidth = 7;
46423 break;
46424 case 6000000:
46425- param.bandwidth = 6;
46426+ param->bandwidth = 6;
46427 break;
46428 }
46429
46430 err = dvb_usb_generic_rw(state->d,
46431- (char *)&param, sizeof(param),
46432- result, sizeof(result), 0);
46433+ (char *)param, sizeof(*param),
46434+ result, 2, 0);
46435 if (err < 0)
46436 err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err);
46437
46438- return (err < 0) ? err : 0;
46439+ kfree(result);
46440+ kfree(param);
46441+ return err;
46442 }
46443
46444 static void cinergyt2_fe_release(struct dvb_frontend *fe)
46445diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46446index 733a7ff..f8b52e3 100644
46447--- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46448+++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46449@@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
46450
46451 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
46452 {
46453- struct hexline hx;
46454- u8 reset;
46455+ struct hexline *hx;
46456+ u8 *reset;
46457 int ret,pos=0;
46458
46459+ reset = kmalloc(1, GFP_KERNEL);
46460+ if (reset == NULL)
46461+ return -ENOMEM;
46462+
46463+ hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
46464+ if (hx == NULL) {
46465+ kfree(reset);
46466+ return -ENOMEM;
46467+ }
46468+
46469 /* stop the CPU */
46470- reset = 1;
46471- if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
46472+ reset[0] = 1;
46473+ if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
46474 err("could not stop the USB controller CPU.");
46475
46476- while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
46477- deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
46478- ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
46479+ while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
46480+ deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
46481+ ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
46482
46483- if (ret != hx.len) {
46484+ if (ret != hx->len) {
46485 err("error while transferring firmware "
46486 "(transferred size: %d, block size: %d)",
46487- ret,hx.len);
46488+ ret,hx->len);
46489 ret = -EINVAL;
46490 break;
46491 }
46492 }
46493 if (ret < 0) {
46494 err("firmware download failed at %d with %d",pos,ret);
46495+ kfree(reset);
46496+ kfree(hx);
46497 return ret;
46498 }
46499
46500 if (ret == 0) {
46501 /* restart the CPU */
46502- reset = 0;
46503- if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
46504+ reset[0] = 0;
46505+ if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
46506 err("could not restart the USB controller CPU.");
46507 ret = -EINVAL;
46508 }
46509 } else
46510 ret = -EIO;
46511
46512+ kfree(reset);
46513+ kfree(hx);
46514+
46515 return ret;
46516 }
46517 EXPORT_SYMBOL(usb_cypress_load_firmware);
46518diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
46519index 2add8c5..c33b854 100644
46520--- a/drivers/media/usb/dvb-usb/dw2102.c
46521+++ b/drivers/media/usb/dvb-usb/dw2102.c
46522@@ -118,7 +118,7 @@ struct su3000_state {
46523
46524 struct s6x0_state {
46525 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
46526-};
46527+} __no_const;
46528
46529 /* debug */
46530 static int dvb_usb_dw2102_debug;
46531diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
46532index 6b0b8b6b..4038398 100644
46533--- a/drivers/media/usb/dvb-usb/technisat-usb2.c
46534+++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
46535@@ -87,8 +87,11 @@ struct technisat_usb2_state {
46536 static int technisat_usb2_i2c_access(struct usb_device *udev,
46537 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
46538 {
46539- u8 b[64];
46540- int ret, actual_length;
46541+ u8 *b = kmalloc(64, GFP_KERNEL);
46542+ int ret, actual_length, error = 0;
46543+
46544+ if (b == NULL)
46545+ return -ENOMEM;
46546
46547 deb_i2c("i2c-access: %02x, tx: ", device_addr);
46548 debug_dump(tx, txlen, deb_i2c);
46549@@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46550
46551 if (ret < 0) {
46552 err("i2c-error: out failed %02x = %d", device_addr, ret);
46553- return -ENODEV;
46554+ error = -ENODEV;
46555+ goto out;
46556 }
46557
46558 ret = usb_bulk_msg(udev,
46559@@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46560 b, 64, &actual_length, 1000);
46561 if (ret < 0) {
46562 err("i2c-error: in failed %02x = %d", device_addr, ret);
46563- return -ENODEV;
46564+ error = -ENODEV;
46565+ goto out;
46566 }
46567
46568 if (b[0] != I2C_STATUS_OK) {
46569@@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46570 /* handle tuner-i2c-nak */
46571 if (!(b[0] == I2C_STATUS_NAK &&
46572 device_addr == 0x60
46573- /* && device_is_technisat_usb2 */))
46574- return -ENODEV;
46575+ /* && device_is_technisat_usb2 */)) {
46576+ error = -ENODEV;
46577+ goto out;
46578+ }
46579 }
46580
46581 deb_i2c("status: %d, ", b[0]);
46582@@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46583
46584 deb_i2c("\n");
46585
46586- return 0;
46587+out:
46588+ kfree(b);
46589+ return error;
46590 }
46591
46592 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
46593@@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
46594 {
46595 int ret;
46596
46597- u8 led[8] = {
46598- red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
46599- 0
46600- };
46601+ u8 *led = kzalloc(8, GFP_KERNEL);
46602+
46603+ if (led == NULL)
46604+ return -ENOMEM;
46605
46606 if (disable_led_control && state != TECH_LED_OFF)
46607 return 0;
46608
46609+ led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
46610+
46611 switch (state) {
46612 case TECH_LED_ON:
46613 led[1] = 0x82;
46614@@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
46615 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
46616 USB_TYPE_VENDOR | USB_DIR_OUT,
46617 0, 0,
46618- led, sizeof(led), 500);
46619+ led, 8, 500);
46620
46621 mutex_unlock(&d->i2c_mutex);
46622+
46623+ kfree(led);
46624+
46625 return ret;
46626 }
46627
46628 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
46629 {
46630 int ret;
46631- u8 b = 0;
46632+ u8 *b = kzalloc(1, GFP_KERNEL);
46633+
46634+ if (b == NULL)
46635+ return -ENOMEM;
46636
46637 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
46638 return -EAGAIN;
46639@@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
46640 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
46641 USB_TYPE_VENDOR | USB_DIR_OUT,
46642 (red << 8) | green, 0,
46643- &b, 1, 500);
46644+ b, 1, 500);
46645
46646 mutex_unlock(&d->i2c_mutex);
46647
46648+ kfree(b);
46649+
46650 return ret;
46651 }
46652
46653@@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46654 struct dvb_usb_device_description **desc, int *cold)
46655 {
46656 int ret;
46657- u8 version[3];
46658+ u8 *version = kmalloc(3, GFP_KERNEL);
46659
46660 /* first select the interface */
46661 if (usb_set_interface(udev, 0, 1) != 0)
46662@@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46663
46664 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
46665
46666+ if (version == NULL)
46667+ return 0;
46668+
46669 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
46670 GET_VERSION_INFO_VENDOR_REQUEST,
46671 USB_TYPE_VENDOR | USB_DIR_IN,
46672 0, 0,
46673- version, sizeof(version), 500);
46674+ version, 3, 500);
46675
46676 if (ret < 0)
46677 *cold = 1;
46678@@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46679 *cold = 0;
46680 }
46681
46682+ kfree(version);
46683+
46684 return 0;
46685 }
46686
46687@@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
46688
46689 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46690 {
46691- u8 buf[62], *b;
46692+ u8 *buf, *b;
46693 int ret;
46694 struct ir_raw_event ev;
46695
46696+ buf = kmalloc(62, GFP_KERNEL);
46697+
46698+ if (buf == NULL)
46699+ return -ENOMEM;
46700+
46701 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
46702 buf[1] = 0x08;
46703 buf[2] = 0x8f;
46704@@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46705 GET_IR_DATA_VENDOR_REQUEST,
46706 USB_TYPE_VENDOR | USB_DIR_IN,
46707 0x8080, 0,
46708- buf, sizeof(buf), 500);
46709+ buf, 62, 500);
46710
46711 unlock:
46712 mutex_unlock(&d->i2c_mutex);
46713
46714- if (ret < 0)
46715+ if (ret < 0) {
46716+ kfree(buf);
46717 return ret;
46718+ }
46719
46720- if (ret == 1)
46721+ if (ret == 1) {
46722+ kfree(buf);
46723 return 0; /* no key pressed */
46724+ }
46725
46726 /* decoding */
46727 b = buf+1;
46728@@ -653,6 +686,8 @@ unlock:
46729
46730 ir_raw_event_handle(d->rc_dev);
46731
46732+ kfree(buf);
46733+
46734 return 1;
46735 }
46736
46737diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46738index cca6c2f..77b9a18 100644
46739--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46740+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46741@@ -328,7 +328,7 @@ struct v4l2_buffer32 {
46742 __u32 reserved;
46743 };
46744
46745-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
46746+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
46747 enum v4l2_memory memory)
46748 {
46749 void __user *up_pln;
46750@@ -357,7 +357,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
46751 return 0;
46752 }
46753
46754-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
46755+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
46756 enum v4l2_memory memory)
46757 {
46758 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
46759@@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46760 * by passing a very big num_planes value */
46761 uplane = compat_alloc_user_space(num_planes *
46762 sizeof(struct v4l2_plane));
46763- kp->m.planes = uplane;
46764+ kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
46765
46766 while (--num_planes >= 0) {
46767 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
46768@@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46769 if (num_planes == 0)
46770 return 0;
46771
46772- uplane = kp->m.planes;
46773+ uplane = (struct v4l2_plane __force_user *)kp->m.planes;
46774 if (get_user(p, &up->m.planes))
46775 return -EFAULT;
46776 uplane32 = compat_ptr(p);
46777@@ -562,7 +562,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
46778 get_user(kp->flags, &up->flags) ||
46779 copy_from_user(&kp->fmt, &up->fmt, sizeof(up->fmt)))
46780 return -EFAULT;
46781- kp->base = compat_ptr(tmp);
46782+ kp->base = (void __force_kernel *)compat_ptr(tmp);
46783 return 0;
46784 }
46785
46786@@ -667,7 +667,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46787 n * sizeof(struct v4l2_ext_control32)))
46788 return -EFAULT;
46789 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
46790- kp->controls = kcontrols;
46791+ kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
46792 while (--n >= 0) {
46793 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
46794 return -EFAULT;
46795@@ -689,7 +689,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46796 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
46797 {
46798 struct v4l2_ext_control32 __user *ucontrols;
46799- struct v4l2_ext_control __user *kcontrols = kp->controls;
46800+ struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
46801 int n = kp->count;
46802 compat_caddr_t p;
46803
46804@@ -783,7 +783,7 @@ static int put_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
46805 put_user(kp->start_block, &up->start_block) ||
46806 put_user(kp->blocks, &up->blocks) ||
46807 put_user(tmp, &up->edid) ||
46808- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
46809+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
46810 return -EFAULT;
46811 return 0;
46812 }
46813diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
46814index 015f92a..59e311e 100644
46815--- a/drivers/media/v4l2-core/v4l2-device.c
46816+++ b/drivers/media/v4l2-core/v4l2-device.c
46817@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
46818 EXPORT_SYMBOL_GPL(v4l2_device_put);
46819
46820 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
46821- atomic_t *instance)
46822+ atomic_unchecked_t *instance)
46823 {
46824- int num = atomic_inc_return(instance) - 1;
46825+ int num = atomic_inc_return_unchecked(instance) - 1;
46826 int len = strlen(basename);
46827
46828 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
46829diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
46830index d15e167..337f374 100644
46831--- a/drivers/media/v4l2-core/v4l2-ioctl.c
46832+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
46833@@ -2142,7 +2142,8 @@ struct v4l2_ioctl_info {
46834 struct file *file, void *fh, void *p);
46835 } u;
46836 void (*debug)(const void *arg, bool write_only);
46837-};
46838+} __do_const;
46839+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
46840
46841 /* This control needs a priority check */
46842 #define INFO_FL_PRIO (1 << 0)
46843@@ -2326,7 +2327,7 @@ static long __video_do_ioctl(struct file *file,
46844 struct video_device *vfd = video_devdata(file);
46845 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
46846 bool write_only = false;
46847- struct v4l2_ioctl_info default_info;
46848+ v4l2_ioctl_info_no_const default_info;
46849 const struct v4l2_ioctl_info *info;
46850 void *fh = file->private_data;
46851 struct v4l2_fh *vfh = NULL;
46852@@ -2413,7 +2414,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46853 ret = -EINVAL;
46854 break;
46855 }
46856- *user_ptr = (void __user *)buf->m.planes;
46857+ *user_ptr = (void __force_user *)buf->m.planes;
46858 *kernel_ptr = (void **)&buf->m.planes;
46859 *array_size = sizeof(struct v4l2_plane) * buf->length;
46860 ret = 1;
46861@@ -2430,7 +2431,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46862 ret = -EINVAL;
46863 break;
46864 }
46865- *user_ptr = (void __user *)edid->edid;
46866+ *user_ptr = (void __force_user *)edid->edid;
46867 *kernel_ptr = (void **)&edid->edid;
46868 *array_size = edid->blocks * 128;
46869 ret = 1;
46870@@ -2448,7 +2449,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46871 ret = -EINVAL;
46872 break;
46873 }
46874- *user_ptr = (void __user *)ctrls->controls;
46875+ *user_ptr = (void __force_user *)ctrls->controls;
46876 *kernel_ptr = (void **)&ctrls->controls;
46877 *array_size = sizeof(struct v4l2_ext_control)
46878 * ctrls->count;
46879@@ -2549,7 +2550,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
46880 }
46881
46882 if (has_array_args) {
46883- *kernel_ptr = (void __force *)user_ptr;
46884+ *kernel_ptr = (void __force_kernel *)user_ptr;
46885 if (copy_to_user(user_ptr, mbuf, array_size))
46886 err = -EFAULT;
46887 goto out_array_args;
46888diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
46889index a896d94..a5d56b1 100644
46890--- a/drivers/message/fusion/mptbase.c
46891+++ b/drivers/message/fusion/mptbase.c
46892@@ -6752,8 +6752,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46893 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
46894 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
46895
46896+#ifdef CONFIG_GRKERNSEC_HIDESYM
46897+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
46898+#else
46899 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
46900 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
46901+#endif
46902+
46903 /*
46904 * Rounding UP to nearest 4-kB boundary here...
46905 */
46906@@ -6766,7 +6771,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46907 ioc->facts.GlobalCredits);
46908
46909 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
46910+#ifdef CONFIG_GRKERNSEC_HIDESYM
46911+ NULL, NULL);
46912+#else
46913 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
46914+#endif
46915 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
46916 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
46917 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
46918diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
46919index 0707fa2..70ca794 100644
46920--- a/drivers/message/fusion/mptsas.c
46921+++ b/drivers/message/fusion/mptsas.c
46922@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
46923 return 0;
46924 }
46925
46926+static inline void
46927+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46928+{
46929+ if (phy_info->port_details) {
46930+ phy_info->port_details->rphy = rphy;
46931+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46932+ ioc->name, rphy));
46933+ }
46934+
46935+ if (rphy) {
46936+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46937+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46938+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46939+ ioc->name, rphy, rphy->dev.release));
46940+ }
46941+}
46942+
46943 /* no mutex */
46944 static void
46945 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
46946@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
46947 return NULL;
46948 }
46949
46950-static inline void
46951-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46952-{
46953- if (phy_info->port_details) {
46954- phy_info->port_details->rphy = rphy;
46955- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46956- ioc->name, rphy));
46957- }
46958-
46959- if (rphy) {
46960- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46961- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46962- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46963- ioc->name, rphy, rphy->dev.release));
46964- }
46965-}
46966-
46967 static inline struct sas_port *
46968 mptsas_get_port(struct mptsas_phyinfo *phy_info)
46969 {
46970diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
46971index b7d87cd..3fb36da 100644
46972--- a/drivers/message/i2o/i2o_proc.c
46973+++ b/drivers/message/i2o/i2o_proc.c
46974@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
46975 "Array Controller Device"
46976 };
46977
46978-static char *chtostr(char *tmp, u8 *chars, int n)
46979-{
46980- tmp[0] = 0;
46981- return strncat(tmp, (char *)chars, n);
46982-}
46983-
46984 static int i2o_report_query_status(struct seq_file *seq, int block_status,
46985 char *group)
46986 {
46987@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
46988 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
46989 {
46990 struct i2o_controller *c = (struct i2o_controller *)seq->private;
46991- static u32 work32[5];
46992- static u8 *work8 = (u8 *) work32;
46993- static u16 *work16 = (u16 *) work32;
46994+ u32 work32[5];
46995+ u8 *work8 = (u8 *) work32;
46996+ u16 *work16 = (u16 *) work32;
46997 int token;
46998 u32 hwcap;
46999
47000@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
47001 } *result;
47002
47003 i2o_exec_execute_ddm_table ddm_table;
47004- char tmp[28 + 1];
47005
47006 result = kmalloc(sizeof(*result), GFP_KERNEL);
47007 if (!result)
47008@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
47009
47010 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
47011 seq_printf(seq, "%-#8x", ddm_table.module_id);
47012- seq_printf(seq, "%-29s",
47013- chtostr(tmp, ddm_table.module_name_version, 28));
47014+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
47015 seq_printf(seq, "%9d ", ddm_table.data_size);
47016 seq_printf(seq, "%8d", ddm_table.code_size);
47017
47018@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
47019
47020 i2o_driver_result_table *result;
47021 i2o_driver_store_table *dst;
47022- char tmp[28 + 1];
47023
47024 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
47025 if (result == NULL)
47026@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
47027
47028 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
47029 seq_printf(seq, "%-#8x", dst->module_id);
47030- seq_printf(seq, "%-29s",
47031- chtostr(tmp, dst->module_name_version, 28));
47032- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
47033+ seq_printf(seq, "%-.28s", dst->module_name_version);
47034+ seq_printf(seq, "%-.8s", dst->date);
47035 seq_printf(seq, "%8d ", dst->module_size);
47036 seq_printf(seq, "%8d ", dst->mpb_size);
47037 seq_printf(seq, "0x%04x", dst->module_flags);
47038@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
47039 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
47040 {
47041 struct i2o_device *d = (struct i2o_device *)seq->private;
47042- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
47043+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
47044 // == (allow) 512d bytes (max)
47045- static u16 *work16 = (u16 *) work32;
47046+ u16 *work16 = (u16 *) work32;
47047 int token;
47048- char tmp[16 + 1];
47049
47050 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
47051
47052@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
47053 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
47054 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
47055 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
47056- seq_printf(seq, "Vendor info : %s\n",
47057- chtostr(tmp, (u8 *) (work32 + 2), 16));
47058- seq_printf(seq, "Product info : %s\n",
47059- chtostr(tmp, (u8 *) (work32 + 6), 16));
47060- seq_printf(seq, "Description : %s\n",
47061- chtostr(tmp, (u8 *) (work32 + 10), 16));
47062- seq_printf(seq, "Product rev. : %s\n",
47063- chtostr(tmp, (u8 *) (work32 + 14), 8));
47064+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
47065+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
47066+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
47067+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
47068
47069 seq_printf(seq, "Serial number : ");
47070 print_serial_number(seq, (u8 *) (work32 + 16),
47071@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
47072 u8 pad[256]; // allow up to 256 byte (max) serial number
47073 } result;
47074
47075- char tmp[24 + 1];
47076-
47077 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
47078
47079 if (token < 0) {
47080@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
47081 }
47082
47083 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
47084- seq_printf(seq, "Module name : %s\n",
47085- chtostr(tmp, result.module_name, 24));
47086- seq_printf(seq, "Module revision : %s\n",
47087- chtostr(tmp, result.module_rev, 8));
47088+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
47089+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
47090
47091 seq_printf(seq, "Serial number : ");
47092 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
47093@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
47094 u8 instance_number[4];
47095 } result;
47096
47097- char tmp[64 + 1];
47098-
47099 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
47100
47101 if (token < 0) {
47102@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
47103 return 0;
47104 }
47105
47106- seq_printf(seq, "Device name : %s\n",
47107- chtostr(tmp, result.device_name, 64));
47108- seq_printf(seq, "Service name : %s\n",
47109- chtostr(tmp, result.service_name, 64));
47110- seq_printf(seq, "Physical name : %s\n",
47111- chtostr(tmp, result.physical_location, 64));
47112- seq_printf(seq, "Instance number : %s\n",
47113- chtostr(tmp, result.instance_number, 4));
47114+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
47115+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
47116+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
47117+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
47118
47119 return 0;
47120 }
47121@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
47122 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
47123 {
47124 struct i2o_device *d = (struct i2o_device *)seq->private;
47125- static u32 work32[12];
47126- static u16 *work16 = (u16 *) work32;
47127- static u8 *work8 = (u8 *) work32;
47128+ u32 work32[12];
47129+ u16 *work16 = (u16 *) work32;
47130+ u8 *work8 = (u8 *) work32;
47131 int token;
47132
47133 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
47134diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
47135index 92752fb..a7494f6 100644
47136--- a/drivers/message/i2o/iop.c
47137+++ b/drivers/message/i2o/iop.c
47138@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
47139
47140 spin_lock_irqsave(&c->context_list_lock, flags);
47141
47142- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
47143- atomic_inc(&c->context_list_counter);
47144+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
47145+ atomic_inc_unchecked(&c->context_list_counter);
47146
47147- entry->context = atomic_read(&c->context_list_counter);
47148+ entry->context = atomic_read_unchecked(&c->context_list_counter);
47149
47150 list_add(&entry->list, &c->context_list);
47151
47152@@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
47153
47154 #if BITS_PER_LONG == 64
47155 spin_lock_init(&c->context_list_lock);
47156- atomic_set(&c->context_list_counter, 0);
47157+ atomic_set_unchecked(&c->context_list_counter, 0);
47158 INIT_LIST_HEAD(&c->context_list);
47159 #endif
47160
47161diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
47162index b2c7e3b..85aa4764 100644
47163--- a/drivers/mfd/ab8500-debugfs.c
47164+++ b/drivers/mfd/ab8500-debugfs.c
47165@@ -100,7 +100,7 @@ static int irq_last;
47166 static u32 *irq_count;
47167 static int num_irqs;
47168
47169-static struct device_attribute **dev_attr;
47170+static device_attribute_no_const **dev_attr;
47171 static char **event_name;
47172
47173 static u8 avg_sample = SAMPLE_16;
47174diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
47175index ecbe78e..b2ca870 100644
47176--- a/drivers/mfd/max8925-i2c.c
47177+++ b/drivers/mfd/max8925-i2c.c
47178@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
47179 const struct i2c_device_id *id)
47180 {
47181 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
47182- static struct max8925_chip *chip;
47183+ struct max8925_chip *chip;
47184 struct device_node *node = client->dev.of_node;
47185
47186 if (node && !pdata) {
47187diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
47188index f243e75..322176c 100644
47189--- a/drivers/mfd/tps65910.c
47190+++ b/drivers/mfd/tps65910.c
47191@@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
47192 struct tps65910_platform_data *pdata)
47193 {
47194 int ret = 0;
47195- static struct regmap_irq_chip *tps6591x_irqs_chip;
47196+ struct regmap_irq_chip *tps6591x_irqs_chip;
47197
47198 if (!irq) {
47199 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
47200diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
47201index b1dabba..24a88f2 100644
47202--- a/drivers/mfd/twl4030-irq.c
47203+++ b/drivers/mfd/twl4030-irq.c
47204@@ -34,6 +34,7 @@
47205 #include <linux/of.h>
47206 #include <linux/irqdomain.h>
47207 #include <linux/i2c/twl.h>
47208+#include <asm/pgtable.h>
47209
47210 #include "twl-core.h"
47211
47212@@ -725,10 +726,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
47213 * Install an irq handler for each of the SIH modules;
47214 * clone dummy irq_chip since PIH can't *do* anything
47215 */
47216- twl4030_irq_chip = dummy_irq_chip;
47217- twl4030_irq_chip.name = "twl4030";
47218+ pax_open_kernel();
47219+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
47220+ *(const char **)&twl4030_irq_chip.name = "twl4030";
47221
47222- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
47223+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
47224+ pax_close_kernel();
47225
47226 for (i = irq_base; i < irq_end; i++) {
47227 irq_set_chip_and_handler(i, &twl4030_irq_chip,
47228diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
47229index 464419b..64bae8d 100644
47230--- a/drivers/misc/c2port/core.c
47231+++ b/drivers/misc/c2port/core.c
47232@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
47233 goto error_idr_alloc;
47234 c2dev->id = ret;
47235
47236- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
47237+ pax_open_kernel();
47238+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
47239+ pax_close_kernel();
47240
47241 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
47242 "c2port%d", c2dev->id);
47243diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
47244index 3f2b625..945e179 100644
47245--- a/drivers/misc/eeprom/sunxi_sid.c
47246+++ b/drivers/misc/eeprom/sunxi_sid.c
47247@@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
47248
47249 platform_set_drvdata(pdev, sid_data);
47250
47251- sid_bin_attr.size = sid_data->keysize;
47252+ pax_open_kernel();
47253+ *(size_t *)&sid_bin_attr.size = sid_data->keysize;
47254+ pax_close_kernel();
47255 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
47256 return -ENODEV;
47257
47258diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
47259index 36f5d52..32311c3 100644
47260--- a/drivers/misc/kgdbts.c
47261+++ b/drivers/misc/kgdbts.c
47262@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
47263 char before[BREAK_INSTR_SIZE];
47264 char after[BREAK_INSTR_SIZE];
47265
47266- probe_kernel_read(before, (char *)kgdbts_break_test,
47267+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
47268 BREAK_INSTR_SIZE);
47269 init_simple_test();
47270 ts.tst = plant_and_detach_test;
47271@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
47272 /* Activate test with initial breakpoint */
47273 if (!is_early)
47274 kgdb_breakpoint();
47275- probe_kernel_read(after, (char *)kgdbts_break_test,
47276+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
47277 BREAK_INSTR_SIZE);
47278 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
47279 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
47280diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
47281index 3ef4627..8d00486 100644
47282--- a/drivers/misc/lis3lv02d/lis3lv02d.c
47283+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
47284@@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
47285 * the lid is closed. This leads to interrupts as soon as a little move
47286 * is done.
47287 */
47288- atomic_inc(&lis3->count);
47289+ atomic_inc_unchecked(&lis3->count);
47290
47291 wake_up_interruptible(&lis3->misc_wait);
47292 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
47293@@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
47294 if (lis3->pm_dev)
47295 pm_runtime_get_sync(lis3->pm_dev);
47296
47297- atomic_set(&lis3->count, 0);
47298+ atomic_set_unchecked(&lis3->count, 0);
47299 return 0;
47300 }
47301
47302@@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
47303 add_wait_queue(&lis3->misc_wait, &wait);
47304 while (true) {
47305 set_current_state(TASK_INTERRUPTIBLE);
47306- data = atomic_xchg(&lis3->count, 0);
47307+ data = atomic_xchg_unchecked(&lis3->count, 0);
47308 if (data)
47309 break;
47310
47311@@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
47312 struct lis3lv02d, miscdev);
47313
47314 poll_wait(file, &lis3->misc_wait, wait);
47315- if (atomic_read(&lis3->count))
47316+ if (atomic_read_unchecked(&lis3->count))
47317 return POLLIN | POLLRDNORM;
47318 return 0;
47319 }
47320diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
47321index c439c82..1f20f57 100644
47322--- a/drivers/misc/lis3lv02d/lis3lv02d.h
47323+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
47324@@ -297,7 +297,7 @@ struct lis3lv02d {
47325 struct input_polled_dev *idev; /* input device */
47326 struct platform_device *pdev; /* platform device */
47327 struct regulator_bulk_data regulators[2];
47328- atomic_t count; /* interrupt count after last read */
47329+ atomic_unchecked_t count; /* interrupt count after last read */
47330 union axis_conversion ac; /* hw -> logical axis */
47331 int mapped_btns[3];
47332
47333diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
47334index 2f30bad..c4c13d0 100644
47335--- a/drivers/misc/sgi-gru/gruhandles.c
47336+++ b/drivers/misc/sgi-gru/gruhandles.c
47337@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
47338 unsigned long nsec;
47339
47340 nsec = CLKS2NSEC(clks);
47341- atomic_long_inc(&mcs_op_statistics[op].count);
47342- atomic_long_add(nsec, &mcs_op_statistics[op].total);
47343+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
47344+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
47345 if (mcs_op_statistics[op].max < nsec)
47346 mcs_op_statistics[op].max = nsec;
47347 }
47348diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
47349index 4f76359..cdfcb2e 100644
47350--- a/drivers/misc/sgi-gru/gruprocfs.c
47351+++ b/drivers/misc/sgi-gru/gruprocfs.c
47352@@ -32,9 +32,9 @@
47353
47354 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
47355
47356-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
47357+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
47358 {
47359- unsigned long val = atomic_long_read(v);
47360+ unsigned long val = atomic_long_read_unchecked(v);
47361
47362 seq_printf(s, "%16lu %s\n", val, id);
47363 }
47364@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
47365
47366 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
47367 for (op = 0; op < mcsop_last; op++) {
47368- count = atomic_long_read(&mcs_op_statistics[op].count);
47369- total = atomic_long_read(&mcs_op_statistics[op].total);
47370+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
47371+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
47372 max = mcs_op_statistics[op].max;
47373 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
47374 count ? total / count : 0, max);
47375diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
47376index 5c3ce24..4915ccb 100644
47377--- a/drivers/misc/sgi-gru/grutables.h
47378+++ b/drivers/misc/sgi-gru/grutables.h
47379@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
47380 * GRU statistics.
47381 */
47382 struct gru_stats_s {
47383- atomic_long_t vdata_alloc;
47384- atomic_long_t vdata_free;
47385- atomic_long_t gts_alloc;
47386- atomic_long_t gts_free;
47387- atomic_long_t gms_alloc;
47388- atomic_long_t gms_free;
47389- atomic_long_t gts_double_allocate;
47390- atomic_long_t assign_context;
47391- atomic_long_t assign_context_failed;
47392- atomic_long_t free_context;
47393- atomic_long_t load_user_context;
47394- atomic_long_t load_kernel_context;
47395- atomic_long_t lock_kernel_context;
47396- atomic_long_t unlock_kernel_context;
47397- atomic_long_t steal_user_context;
47398- atomic_long_t steal_kernel_context;
47399- atomic_long_t steal_context_failed;
47400- atomic_long_t nopfn;
47401- atomic_long_t asid_new;
47402- atomic_long_t asid_next;
47403- atomic_long_t asid_wrap;
47404- atomic_long_t asid_reuse;
47405- atomic_long_t intr;
47406- atomic_long_t intr_cbr;
47407- atomic_long_t intr_tfh;
47408- atomic_long_t intr_spurious;
47409- atomic_long_t intr_mm_lock_failed;
47410- atomic_long_t call_os;
47411- atomic_long_t call_os_wait_queue;
47412- atomic_long_t user_flush_tlb;
47413- atomic_long_t user_unload_context;
47414- atomic_long_t user_exception;
47415- atomic_long_t set_context_option;
47416- atomic_long_t check_context_retarget_intr;
47417- atomic_long_t check_context_unload;
47418- atomic_long_t tlb_dropin;
47419- atomic_long_t tlb_preload_page;
47420- atomic_long_t tlb_dropin_fail_no_asid;
47421- atomic_long_t tlb_dropin_fail_upm;
47422- atomic_long_t tlb_dropin_fail_invalid;
47423- atomic_long_t tlb_dropin_fail_range_active;
47424- atomic_long_t tlb_dropin_fail_idle;
47425- atomic_long_t tlb_dropin_fail_fmm;
47426- atomic_long_t tlb_dropin_fail_no_exception;
47427- atomic_long_t tfh_stale_on_fault;
47428- atomic_long_t mmu_invalidate_range;
47429- atomic_long_t mmu_invalidate_page;
47430- atomic_long_t flush_tlb;
47431- atomic_long_t flush_tlb_gru;
47432- atomic_long_t flush_tlb_gru_tgh;
47433- atomic_long_t flush_tlb_gru_zero_asid;
47434+ atomic_long_unchecked_t vdata_alloc;
47435+ atomic_long_unchecked_t vdata_free;
47436+ atomic_long_unchecked_t gts_alloc;
47437+ atomic_long_unchecked_t gts_free;
47438+ atomic_long_unchecked_t gms_alloc;
47439+ atomic_long_unchecked_t gms_free;
47440+ atomic_long_unchecked_t gts_double_allocate;
47441+ atomic_long_unchecked_t assign_context;
47442+ atomic_long_unchecked_t assign_context_failed;
47443+ atomic_long_unchecked_t free_context;
47444+ atomic_long_unchecked_t load_user_context;
47445+ atomic_long_unchecked_t load_kernel_context;
47446+ atomic_long_unchecked_t lock_kernel_context;
47447+ atomic_long_unchecked_t unlock_kernel_context;
47448+ atomic_long_unchecked_t steal_user_context;
47449+ atomic_long_unchecked_t steal_kernel_context;
47450+ atomic_long_unchecked_t steal_context_failed;
47451+ atomic_long_unchecked_t nopfn;
47452+ atomic_long_unchecked_t asid_new;
47453+ atomic_long_unchecked_t asid_next;
47454+ atomic_long_unchecked_t asid_wrap;
47455+ atomic_long_unchecked_t asid_reuse;
47456+ atomic_long_unchecked_t intr;
47457+ atomic_long_unchecked_t intr_cbr;
47458+ atomic_long_unchecked_t intr_tfh;
47459+ atomic_long_unchecked_t intr_spurious;
47460+ atomic_long_unchecked_t intr_mm_lock_failed;
47461+ atomic_long_unchecked_t call_os;
47462+ atomic_long_unchecked_t call_os_wait_queue;
47463+ atomic_long_unchecked_t user_flush_tlb;
47464+ atomic_long_unchecked_t user_unload_context;
47465+ atomic_long_unchecked_t user_exception;
47466+ atomic_long_unchecked_t set_context_option;
47467+ atomic_long_unchecked_t check_context_retarget_intr;
47468+ atomic_long_unchecked_t check_context_unload;
47469+ atomic_long_unchecked_t tlb_dropin;
47470+ atomic_long_unchecked_t tlb_preload_page;
47471+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
47472+ atomic_long_unchecked_t tlb_dropin_fail_upm;
47473+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
47474+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
47475+ atomic_long_unchecked_t tlb_dropin_fail_idle;
47476+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
47477+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
47478+ atomic_long_unchecked_t tfh_stale_on_fault;
47479+ atomic_long_unchecked_t mmu_invalidate_range;
47480+ atomic_long_unchecked_t mmu_invalidate_page;
47481+ atomic_long_unchecked_t flush_tlb;
47482+ atomic_long_unchecked_t flush_tlb_gru;
47483+ atomic_long_unchecked_t flush_tlb_gru_tgh;
47484+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
47485
47486- atomic_long_t copy_gpa;
47487- atomic_long_t read_gpa;
47488+ atomic_long_unchecked_t copy_gpa;
47489+ atomic_long_unchecked_t read_gpa;
47490
47491- atomic_long_t mesq_receive;
47492- atomic_long_t mesq_receive_none;
47493- atomic_long_t mesq_send;
47494- atomic_long_t mesq_send_failed;
47495- atomic_long_t mesq_noop;
47496- atomic_long_t mesq_send_unexpected_error;
47497- atomic_long_t mesq_send_lb_overflow;
47498- atomic_long_t mesq_send_qlimit_reached;
47499- atomic_long_t mesq_send_amo_nacked;
47500- atomic_long_t mesq_send_put_nacked;
47501- atomic_long_t mesq_page_overflow;
47502- atomic_long_t mesq_qf_locked;
47503- atomic_long_t mesq_qf_noop_not_full;
47504- atomic_long_t mesq_qf_switch_head_failed;
47505- atomic_long_t mesq_qf_unexpected_error;
47506- atomic_long_t mesq_noop_unexpected_error;
47507- atomic_long_t mesq_noop_lb_overflow;
47508- atomic_long_t mesq_noop_qlimit_reached;
47509- atomic_long_t mesq_noop_amo_nacked;
47510- atomic_long_t mesq_noop_put_nacked;
47511- atomic_long_t mesq_noop_page_overflow;
47512+ atomic_long_unchecked_t mesq_receive;
47513+ atomic_long_unchecked_t mesq_receive_none;
47514+ atomic_long_unchecked_t mesq_send;
47515+ atomic_long_unchecked_t mesq_send_failed;
47516+ atomic_long_unchecked_t mesq_noop;
47517+ atomic_long_unchecked_t mesq_send_unexpected_error;
47518+ atomic_long_unchecked_t mesq_send_lb_overflow;
47519+ atomic_long_unchecked_t mesq_send_qlimit_reached;
47520+ atomic_long_unchecked_t mesq_send_amo_nacked;
47521+ atomic_long_unchecked_t mesq_send_put_nacked;
47522+ atomic_long_unchecked_t mesq_page_overflow;
47523+ atomic_long_unchecked_t mesq_qf_locked;
47524+ atomic_long_unchecked_t mesq_qf_noop_not_full;
47525+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
47526+ atomic_long_unchecked_t mesq_qf_unexpected_error;
47527+ atomic_long_unchecked_t mesq_noop_unexpected_error;
47528+ atomic_long_unchecked_t mesq_noop_lb_overflow;
47529+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
47530+ atomic_long_unchecked_t mesq_noop_amo_nacked;
47531+ atomic_long_unchecked_t mesq_noop_put_nacked;
47532+ atomic_long_unchecked_t mesq_noop_page_overflow;
47533
47534 };
47535
47536@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
47537 tghop_invalidate, mcsop_last};
47538
47539 struct mcs_op_statistic {
47540- atomic_long_t count;
47541- atomic_long_t total;
47542+ atomic_long_unchecked_t count;
47543+ atomic_long_unchecked_t total;
47544 unsigned long max;
47545 };
47546
47547@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
47548
47549 #define STAT(id) do { \
47550 if (gru_options & OPT_STATS) \
47551- atomic_long_inc(&gru_stats.id); \
47552+ atomic_long_inc_unchecked(&gru_stats.id); \
47553 } while (0)
47554
47555 #ifdef CONFIG_SGI_GRU_DEBUG
47556diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
47557index c862cd4..0d176fe 100644
47558--- a/drivers/misc/sgi-xp/xp.h
47559+++ b/drivers/misc/sgi-xp/xp.h
47560@@ -288,7 +288,7 @@ struct xpc_interface {
47561 xpc_notify_func, void *);
47562 void (*received) (short, int, void *);
47563 enum xp_retval (*partid_to_nasids) (short, void *);
47564-};
47565+} __no_const;
47566
47567 extern struct xpc_interface xpc_interface;
47568
47569diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
47570index 01be66d..e3a0c7e 100644
47571--- a/drivers/misc/sgi-xp/xp_main.c
47572+++ b/drivers/misc/sgi-xp/xp_main.c
47573@@ -78,13 +78,13 @@ xpc_notloaded(void)
47574 }
47575
47576 struct xpc_interface xpc_interface = {
47577- (void (*)(int))xpc_notloaded,
47578- (void (*)(int))xpc_notloaded,
47579- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
47580- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
47581+ .connect = (void (*)(int))xpc_notloaded,
47582+ .disconnect = (void (*)(int))xpc_notloaded,
47583+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
47584+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
47585 void *))xpc_notloaded,
47586- (void (*)(short, int, void *))xpc_notloaded,
47587- (enum xp_retval(*)(short, void *))xpc_notloaded
47588+ .received = (void (*)(short, int, void *))xpc_notloaded,
47589+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
47590 };
47591 EXPORT_SYMBOL_GPL(xpc_interface);
47592
47593diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
47594index b94d5f7..7f494c5 100644
47595--- a/drivers/misc/sgi-xp/xpc.h
47596+++ b/drivers/misc/sgi-xp/xpc.h
47597@@ -835,6 +835,7 @@ struct xpc_arch_operations {
47598 void (*received_payload) (struct xpc_channel *, void *);
47599 void (*notify_senders_of_disconnect) (struct xpc_channel *);
47600 };
47601+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
47602
47603 /* struct xpc_partition act_state values (for XPC HB) */
47604
47605@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
47606 /* found in xpc_main.c */
47607 extern struct device *xpc_part;
47608 extern struct device *xpc_chan;
47609-extern struct xpc_arch_operations xpc_arch_ops;
47610+extern xpc_arch_operations_no_const xpc_arch_ops;
47611 extern int xpc_disengage_timelimit;
47612 extern int xpc_disengage_timedout;
47613 extern int xpc_activate_IRQ_rcvd;
47614diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
47615index 82dc574..8539ab2 100644
47616--- a/drivers/misc/sgi-xp/xpc_main.c
47617+++ b/drivers/misc/sgi-xp/xpc_main.c
47618@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
47619 .notifier_call = xpc_system_die,
47620 };
47621
47622-struct xpc_arch_operations xpc_arch_ops;
47623+xpc_arch_operations_no_const xpc_arch_ops;
47624
47625 /*
47626 * Timer function to enforce the timelimit on the partition disengage.
47627@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
47628
47629 if (((die_args->trapnr == X86_TRAP_MF) ||
47630 (die_args->trapnr == X86_TRAP_XF)) &&
47631- !user_mode_vm(die_args->regs))
47632+ !user_mode(die_args->regs))
47633 xpc_die_deactivate();
47634
47635 break;
47636diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
47637index ede41f0..744fbd9 100644
47638--- a/drivers/mmc/card/block.c
47639+++ b/drivers/mmc/card/block.c
47640@@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
47641 if (idata->ic.postsleep_min_us)
47642 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
47643
47644- if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
47645+ if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
47646 err = -EFAULT;
47647 goto cmd_rel_host;
47648 }
47649diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
47650index f51b5ba..86614a7 100644
47651--- a/drivers/mmc/core/mmc_ops.c
47652+++ b/drivers/mmc/core/mmc_ops.c
47653@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
47654 void *data_buf;
47655 int is_on_stack;
47656
47657- is_on_stack = object_is_on_stack(buf);
47658+ is_on_stack = object_starts_on_stack(buf);
47659 if (is_on_stack) {
47660 /*
47661 * dma onto stack is unsafe/nonportable, but callers to this
47662diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
47663index 08fd956..370487a 100644
47664--- a/drivers/mmc/host/dw_mmc.h
47665+++ b/drivers/mmc/host/dw_mmc.h
47666@@ -262,5 +262,5 @@ struct dw_mci_drv_data {
47667 int (*parse_dt)(struct dw_mci *host);
47668 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
47669 struct dw_mci_tuning_data *tuning_data);
47670-};
47671+} __do_const;
47672 #endif /* _DW_MMC_H_ */
47673diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
47674index e4d4707..28262a3 100644
47675--- a/drivers/mmc/host/mmci.c
47676+++ b/drivers/mmc/host/mmci.c
47677@@ -1612,7 +1612,9 @@ static int mmci_probe(struct amba_device *dev,
47678 mmc->caps |= MMC_CAP_CMD23;
47679
47680 if (variant->busy_detect) {
47681- mmci_ops.card_busy = mmci_card_busy;
47682+ pax_open_kernel();
47683+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
47684+ pax_close_kernel();
47685 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
47686 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
47687 mmc->max_busy_timeout = 0;
47688diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
47689index ccec0e3..199f9ce 100644
47690--- a/drivers/mmc/host/sdhci-esdhc-imx.c
47691+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
47692@@ -1034,9 +1034,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
47693 host->mmc->caps |= MMC_CAP_1_8V_DDR;
47694 }
47695
47696- if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
47697- sdhci_esdhc_ops.platform_execute_tuning =
47698+ if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
47699+ pax_open_kernel();
47700+ *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
47701 esdhc_executing_tuning;
47702+ pax_close_kernel();
47703+ }
47704
47705 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
47706 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
47707diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
47708index 1e47903..7683916 100644
47709--- a/drivers/mmc/host/sdhci-s3c.c
47710+++ b/drivers/mmc/host/sdhci-s3c.c
47711@@ -584,9 +584,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
47712 * we can use overriding functions instead of default.
47713 */
47714 if (sc->no_divider) {
47715- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47716- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47717- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47718+ pax_open_kernel();
47719+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47720+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47721+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47722+ pax_close_kernel();
47723 }
47724
47725 /* It supports additional host capabilities if needed */
47726diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
47727index 423666b..81ff5eb 100644
47728--- a/drivers/mtd/chips/cfi_cmdset_0020.c
47729+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
47730@@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
47731 size_t totlen = 0, thislen;
47732 int ret = 0;
47733 size_t buflen = 0;
47734- static char *buffer;
47735+ char *buffer;
47736
47737 if (!ECCBUF_SIZE) {
47738 /* We should fall back to a general writev implementation.
47739diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
47740index 0b071a3..8ec3d5b 100644
47741--- a/drivers/mtd/nand/denali.c
47742+++ b/drivers/mtd/nand/denali.c
47743@@ -24,6 +24,7 @@
47744 #include <linux/slab.h>
47745 #include <linux/mtd/mtd.h>
47746 #include <linux/module.h>
47747+#include <linux/slab.h>
47748
47749 #include "denali.h"
47750
47751diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47752index 959cb9b..8520fe5 100644
47753--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47754+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47755@@ -386,7 +386,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
47756
47757 /* first try to map the upper buffer directly */
47758 if (virt_addr_valid(this->upper_buf) &&
47759- !object_is_on_stack(this->upper_buf)) {
47760+ !object_starts_on_stack(this->upper_buf)) {
47761 sg_init_one(sgl, this->upper_buf, this->upper_len);
47762 ret = dma_map_sg(this->dev, sgl, 1, dr);
47763 if (ret == 0)
47764diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
47765index 51b9d6a..52af9a7 100644
47766--- a/drivers/mtd/nftlmount.c
47767+++ b/drivers/mtd/nftlmount.c
47768@@ -24,6 +24,7 @@
47769 #include <asm/errno.h>
47770 #include <linux/delay.h>
47771 #include <linux/slab.h>
47772+#include <linux/sched.h>
47773 #include <linux/mtd/mtd.h>
47774 #include <linux/mtd/nand.h>
47775 #include <linux/mtd/nftl.h>
47776diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
47777index cf49c22..971b133 100644
47778--- a/drivers/mtd/sm_ftl.c
47779+++ b/drivers/mtd/sm_ftl.c
47780@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
47781 #define SM_CIS_VENDOR_OFFSET 0x59
47782 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
47783 {
47784- struct attribute_group *attr_group;
47785+ attribute_group_no_const *attr_group;
47786 struct attribute **attributes;
47787 struct sm_sysfs_attribute *vendor_attribute;
47788 char *vendor;
47789diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
47790index d163e11..f517018 100644
47791--- a/drivers/net/bonding/bond_netlink.c
47792+++ b/drivers/net/bonding/bond_netlink.c
47793@@ -548,7 +548,7 @@ nla_put_failure:
47794 return -EMSGSIZE;
47795 }
47796
47797-struct rtnl_link_ops bond_link_ops __read_mostly = {
47798+struct rtnl_link_ops bond_link_ops = {
47799 .kind = "bond",
47800 .priv_size = sizeof(struct bonding),
47801 .setup = bond_setup,
47802diff --git a/drivers/net/caif/caif_hsi.c b/drivers/net/caif/caif_hsi.c
47803index 5e40a8b..126bfda 100644
47804--- a/drivers/net/caif/caif_hsi.c
47805+++ b/drivers/net/caif/caif_hsi.c
47806@@ -1445,7 +1445,7 @@ err:
47807 return -ENODEV;
47808 }
47809
47810-static struct rtnl_link_ops caif_hsi_link_ops __read_mostly = {
47811+static struct rtnl_link_ops caif_hsi_link_ops = {
47812 .kind = "cfhsi",
47813 .priv_size = sizeof(struct cfhsi),
47814 .setup = cfhsi_setup,
47815diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
47816index 4168822..f38eeddf 100644
47817--- a/drivers/net/can/Kconfig
47818+++ b/drivers/net/can/Kconfig
47819@@ -98,7 +98,7 @@ config CAN_JANZ_ICAN3
47820
47821 config CAN_FLEXCAN
47822 tristate "Support for Freescale FLEXCAN based chips"
47823- depends on ARM || PPC
47824+ depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
47825 ---help---
47826 Say Y here if you want to support for Freescale FlexCAN.
47827
47828diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
47829index 6403503..a0c8bb6 100644
47830--- a/drivers/net/can/dev.c
47831+++ b/drivers/net/can/dev.c
47832@@ -869,7 +869,7 @@ static int can_newlink(struct net *src_net, struct net_device *dev,
47833 return -EOPNOTSUPP;
47834 }
47835
47836-static struct rtnl_link_ops can_link_ops __read_mostly = {
47837+static struct rtnl_link_ops can_link_ops = {
47838 .kind = "can",
47839 .maxtype = IFLA_CAN_MAX,
47840 .policy = can_policy,
47841diff --git a/drivers/net/can/vcan.c b/drivers/net/can/vcan.c
47842index 4e94057..32032ff 100644
47843--- a/drivers/net/can/vcan.c
47844+++ b/drivers/net/can/vcan.c
47845@@ -166,7 +166,7 @@ static void vcan_setup(struct net_device *dev)
47846 dev->destructor = free_netdev;
47847 }
47848
47849-static struct rtnl_link_ops vcan_link_ops __read_mostly = {
47850+static struct rtnl_link_ops vcan_link_ops = {
47851 .kind = "vcan",
47852 .setup = vcan_setup,
47853 };
47854diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
47855index ff435fb..d408b1f 100644
47856--- a/drivers/net/dummy.c
47857+++ b/drivers/net/dummy.c
47858@@ -149,7 +149,7 @@ static int dummy_validate(struct nlattr *tb[], struct nlattr *data[])
47859 return 0;
47860 }
47861
47862-static struct rtnl_link_ops dummy_link_ops __read_mostly = {
47863+static struct rtnl_link_ops dummy_link_ops = {
47864 .kind = "dummy",
47865 .setup = dummy_setup,
47866 .validate = dummy_validate,
47867diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
47868index 1d162cc..b546a75 100644
47869--- a/drivers/net/ethernet/8390/ax88796.c
47870+++ b/drivers/net/ethernet/8390/ax88796.c
47871@@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
47872 if (ax->plat->reg_offsets)
47873 ei_local->reg_offset = ax->plat->reg_offsets;
47874 else {
47875+ resource_size_t _mem_size = mem_size;
47876+ do_div(_mem_size, 0x18);
47877 ei_local->reg_offset = ax->reg_offsets;
47878 for (ret = 0; ret < 0x18; ret++)
47879- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
47880+ ax->reg_offsets[ret] = _mem_size * ret;
47881 }
47882
47883 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
47884diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
47885index 7330681..7e9e463 100644
47886--- a/drivers/net/ethernet/altera/altera_tse_main.c
47887+++ b/drivers/net/ethernet/altera/altera_tse_main.c
47888@@ -1182,7 +1182,7 @@ static int tse_shutdown(struct net_device *dev)
47889 return 0;
47890 }
47891
47892-static struct net_device_ops altera_tse_netdev_ops = {
47893+static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
47894 .ndo_open = tse_open,
47895 .ndo_stop = tse_shutdown,
47896 .ndo_start_xmit = tse_start_xmit,
47897@@ -1439,11 +1439,13 @@ static int altera_tse_probe(struct platform_device *pdev)
47898 ndev->netdev_ops = &altera_tse_netdev_ops;
47899 altera_tse_set_ethtool_ops(ndev);
47900
47901+ pax_open_kernel();
47902 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
47903
47904 if (priv->hash_filter)
47905 altera_tse_netdev_ops.ndo_set_rx_mode =
47906 tse_set_rx_mode_hashfilter;
47907+ pax_close_kernel();
47908
47909 /* Scatter/gather IO is not supported,
47910 * so it is turned off
47911diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-common.h b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47912index cc25a3a..c8d72d3 100644
47913--- a/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47914+++ b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47915@@ -1083,14 +1083,14 @@ do { \
47916 * operations, everything works on mask values.
47917 */
47918 #define XMDIO_READ(_pdata, _mmd, _reg) \
47919- ((_pdata)->hw_if.read_mmd_regs((_pdata), 0, \
47920+ ((_pdata)->hw_if->read_mmd_regs((_pdata), 0, \
47921 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff)))
47922
47923 #define XMDIO_READ_BITS(_pdata, _mmd, _reg, _mask) \
47924 (XMDIO_READ((_pdata), _mmd, _reg) & _mask)
47925
47926 #define XMDIO_WRITE(_pdata, _mmd, _reg, _val) \
47927- ((_pdata)->hw_if.write_mmd_regs((_pdata), 0, \
47928+ ((_pdata)->hw_if->write_mmd_regs((_pdata), 0, \
47929 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff), (_val)))
47930
47931 #define XMDIO_WRITE_BITS(_pdata, _mmd, _reg, _mask, _val) \
47932diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47933index 7d6a49b..e6d403b 100644
47934--- a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47935+++ b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47936@@ -188,7 +188,7 @@ static int xgbe_dcb_ieee_setets(struct net_device *netdev,
47937
47938 memcpy(pdata->ets, ets, sizeof(*pdata->ets));
47939
47940- pdata->hw_if.config_dcb_tc(pdata);
47941+ pdata->hw_if->config_dcb_tc(pdata);
47942
47943 return 0;
47944 }
47945@@ -227,7 +227,7 @@ static int xgbe_dcb_ieee_setpfc(struct net_device *netdev,
47946
47947 memcpy(pdata->pfc, pfc, sizeof(*pdata->pfc));
47948
47949- pdata->hw_if.config_dcb_pfc(pdata);
47950+ pdata->hw_if->config_dcb_pfc(pdata);
47951
47952 return 0;
47953 }
47954diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47955index 1c5d62e..8e14d54 100644
47956--- a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47957+++ b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47958@@ -236,7 +236,7 @@ err_ring:
47959
47960 static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47961 {
47962- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47963+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47964 struct xgbe_channel *channel;
47965 struct xgbe_ring *ring;
47966 struct xgbe_ring_data *rdata;
47967@@ -277,7 +277,7 @@ static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47968
47969 static void xgbe_wrapper_rx_descriptor_init(struct xgbe_prv_data *pdata)
47970 {
47971- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47972+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47973 struct xgbe_channel *channel;
47974 struct xgbe_ring *ring;
47975 struct xgbe_ring_desc *rdesc;
47976@@ -506,7 +506,7 @@ err_out:
47977 static void xgbe_realloc_skb(struct xgbe_channel *channel)
47978 {
47979 struct xgbe_prv_data *pdata = channel->pdata;
47980- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47981+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47982 struct xgbe_ring *ring = channel->rx_ring;
47983 struct xgbe_ring_data *rdata;
47984 struct sk_buff *skb = NULL;
47985@@ -550,17 +550,12 @@ static void xgbe_realloc_skb(struct xgbe_channel *channel)
47986 DBGPR("<--xgbe_realloc_skb\n");
47987 }
47988
47989-void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *desc_if)
47990-{
47991- DBGPR("-->xgbe_init_function_ptrs_desc\n");
47992-
47993- desc_if->alloc_ring_resources = xgbe_alloc_ring_resources;
47994- desc_if->free_ring_resources = xgbe_free_ring_resources;
47995- desc_if->map_tx_skb = xgbe_map_tx_skb;
47996- desc_if->realloc_skb = xgbe_realloc_skb;
47997- desc_if->unmap_skb = xgbe_unmap_skb;
47998- desc_if->wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init;
47999- desc_if->wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init;
48000-
48001- DBGPR("<--xgbe_init_function_ptrs_desc\n");
48002-}
48003+const struct xgbe_desc_if default_xgbe_desc_if = {
48004+ .alloc_ring_resources = xgbe_alloc_ring_resources,
48005+ .free_ring_resources = xgbe_free_ring_resources,
48006+ .map_tx_skb = xgbe_map_tx_skb,
48007+ .realloc_skb = xgbe_realloc_skb,
48008+ .unmap_skb = xgbe_unmap_skb,
48009+ .wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init,
48010+ .wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init,
48011+};
48012diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
48013index ea27383..faa8936 100644
48014--- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
48015+++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
48016@@ -2463,7 +2463,7 @@ static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
48017
48018 static int xgbe_init(struct xgbe_prv_data *pdata)
48019 {
48020- struct xgbe_desc_if *desc_if = &pdata->desc_if;
48021+ struct xgbe_desc_if *desc_if = pdata->desc_if;
48022 int ret;
48023
48024 DBGPR("-->xgbe_init\n");
48025@@ -2525,101 +2525,96 @@ static int xgbe_init(struct xgbe_prv_data *pdata)
48026 return 0;
48027 }
48028
48029-void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
48030-{
48031- DBGPR("-->xgbe_init_function_ptrs\n");
48032-
48033- hw_if->tx_complete = xgbe_tx_complete;
48034-
48035- hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
48036- hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
48037- hw_if->add_mac_addresses = xgbe_add_mac_addresses;
48038- hw_if->set_mac_address = xgbe_set_mac_address;
48039-
48040- hw_if->enable_rx_csum = xgbe_enable_rx_csum;
48041- hw_if->disable_rx_csum = xgbe_disable_rx_csum;
48042-
48043- hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
48044- hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
48045- hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
48046- hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
48047- hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
48048-
48049- hw_if->read_mmd_regs = xgbe_read_mmd_regs;
48050- hw_if->write_mmd_regs = xgbe_write_mmd_regs;
48051-
48052- hw_if->set_gmii_speed = xgbe_set_gmii_speed;
48053- hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
48054- hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
48055-
48056- hw_if->enable_tx = xgbe_enable_tx;
48057- hw_if->disable_tx = xgbe_disable_tx;
48058- hw_if->enable_rx = xgbe_enable_rx;
48059- hw_if->disable_rx = xgbe_disable_rx;
48060-
48061- hw_if->powerup_tx = xgbe_powerup_tx;
48062- hw_if->powerdown_tx = xgbe_powerdown_tx;
48063- hw_if->powerup_rx = xgbe_powerup_rx;
48064- hw_if->powerdown_rx = xgbe_powerdown_rx;
48065-
48066- hw_if->pre_xmit = xgbe_pre_xmit;
48067- hw_if->dev_read = xgbe_dev_read;
48068- hw_if->enable_int = xgbe_enable_int;
48069- hw_if->disable_int = xgbe_disable_int;
48070- hw_if->init = xgbe_init;
48071- hw_if->exit = xgbe_exit;
48072+const struct xgbe_hw_if default_xgbe_hw_if = {
48073+ .tx_complete = xgbe_tx_complete,
48074+
48075+ .set_promiscuous_mode = xgbe_set_promiscuous_mode,
48076+ .set_all_multicast_mode = xgbe_set_all_multicast_mode,
48077+ .add_mac_addresses = xgbe_add_mac_addresses,
48078+ .set_mac_address = xgbe_set_mac_address,
48079+
48080+ .enable_rx_csum = xgbe_enable_rx_csum,
48081+ .disable_rx_csum = xgbe_disable_rx_csum,
48082+
48083+ .enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping,
48084+ .disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping,
48085+ .enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering,
48086+ .disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering,
48087+ .update_vlan_hash_table = xgbe_update_vlan_hash_table,
48088+
48089+ .read_mmd_regs = xgbe_read_mmd_regs,
48090+ .write_mmd_regs = xgbe_write_mmd_regs,
48091+
48092+ .set_gmii_speed = xgbe_set_gmii_speed,
48093+ .set_gmii_2500_speed = xgbe_set_gmii_2500_speed,
48094+ .set_xgmii_speed = xgbe_set_xgmii_speed,
48095+
48096+ .enable_tx = xgbe_enable_tx,
48097+ .disable_tx = xgbe_disable_tx,
48098+ .enable_rx = xgbe_enable_rx,
48099+ .disable_rx = xgbe_disable_rx,
48100+
48101+ .powerup_tx = xgbe_powerup_tx,
48102+ .powerdown_tx = xgbe_powerdown_tx,
48103+ .powerup_rx = xgbe_powerup_rx,
48104+ .powerdown_rx = xgbe_powerdown_rx,
48105+
48106+ .pre_xmit = xgbe_pre_xmit,
48107+ .dev_read = xgbe_dev_read,
48108+ .enable_int = xgbe_enable_int,
48109+ .disable_int = xgbe_disable_int,
48110+ .init = xgbe_init,
48111+ .exit = xgbe_exit,
48112
48113 /* Descriptor related Sequences have to be initialized here */
48114- hw_if->tx_desc_init = xgbe_tx_desc_init;
48115- hw_if->rx_desc_init = xgbe_rx_desc_init;
48116- hw_if->tx_desc_reset = xgbe_tx_desc_reset;
48117- hw_if->rx_desc_reset = xgbe_rx_desc_reset;
48118- hw_if->is_last_desc = xgbe_is_last_desc;
48119- hw_if->is_context_desc = xgbe_is_context_desc;
48120+ .tx_desc_init = xgbe_tx_desc_init,
48121+ .rx_desc_init = xgbe_rx_desc_init,
48122+ .tx_desc_reset = xgbe_tx_desc_reset,
48123+ .rx_desc_reset = xgbe_rx_desc_reset,
48124+ .is_last_desc = xgbe_is_last_desc,
48125+ .is_context_desc = xgbe_is_context_desc,
48126
48127 /* For FLOW ctrl */
48128- hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
48129- hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
48130+ .config_tx_flow_control = xgbe_config_tx_flow_control,
48131+ .config_rx_flow_control = xgbe_config_rx_flow_control,
48132
48133 /* For RX coalescing */
48134- hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
48135- hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
48136- hw_if->usec_to_riwt = xgbe_usec_to_riwt;
48137- hw_if->riwt_to_usec = xgbe_riwt_to_usec;
48138+ .config_rx_coalesce = xgbe_config_rx_coalesce,
48139+ .config_tx_coalesce = xgbe_config_tx_coalesce,
48140+ .usec_to_riwt = xgbe_usec_to_riwt,
48141+ .riwt_to_usec = xgbe_riwt_to_usec,
48142
48143 /* For RX and TX threshold config */
48144- hw_if->config_rx_threshold = xgbe_config_rx_threshold;
48145- hw_if->config_tx_threshold = xgbe_config_tx_threshold;
48146+ .config_rx_threshold = xgbe_config_rx_threshold,
48147+ .config_tx_threshold = xgbe_config_tx_threshold,
48148
48149 /* For RX and TX Store and Forward Mode config */
48150- hw_if->config_rsf_mode = xgbe_config_rsf_mode;
48151- hw_if->config_tsf_mode = xgbe_config_tsf_mode;
48152+ .config_rsf_mode = xgbe_config_rsf_mode,
48153+ .config_tsf_mode = xgbe_config_tsf_mode,
48154
48155 /* For TX DMA Operating on Second Frame config */
48156- hw_if->config_osp_mode = xgbe_config_osp_mode;
48157+ .config_osp_mode = xgbe_config_osp_mode,
48158
48159 /* For RX and TX PBL config */
48160- hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
48161- hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
48162- hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
48163- hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
48164- hw_if->config_pblx8 = xgbe_config_pblx8;
48165+ .config_rx_pbl_val = xgbe_config_rx_pbl_val,
48166+ .get_rx_pbl_val = xgbe_get_rx_pbl_val,
48167+ .config_tx_pbl_val = xgbe_config_tx_pbl_val,
48168+ .get_tx_pbl_val = xgbe_get_tx_pbl_val,
48169+ .config_pblx8 = xgbe_config_pblx8,
48170
48171 /* For MMC statistics support */
48172- hw_if->tx_mmc_int = xgbe_tx_mmc_int;
48173- hw_if->rx_mmc_int = xgbe_rx_mmc_int;
48174- hw_if->read_mmc_stats = xgbe_read_mmc_stats;
48175+ .tx_mmc_int = xgbe_tx_mmc_int,
48176+ .rx_mmc_int = xgbe_rx_mmc_int,
48177+ .read_mmc_stats = xgbe_read_mmc_stats,
48178
48179 /* For PTP config */
48180- hw_if->config_tstamp = xgbe_config_tstamp;
48181- hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
48182- hw_if->set_tstamp_time = xgbe_set_tstamp_time;
48183- hw_if->get_tstamp_time = xgbe_get_tstamp_time;
48184- hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
48185+ .config_tstamp = xgbe_config_tstamp,
48186+ .update_tstamp_addend = xgbe_update_tstamp_addend,
48187+ .set_tstamp_time = xgbe_set_tstamp_time,
48188+ .get_tstamp_time = xgbe_get_tstamp_time,
48189+ .get_tx_tstamp = xgbe_get_tx_tstamp,
48190
48191 /* For Data Center Bridging config */
48192- hw_if->config_dcb_tc = xgbe_config_dcb_tc;
48193- hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
48194-
48195- DBGPR("<--xgbe_init_function_ptrs\n");
48196-}
48197+ .config_dcb_tc = xgbe_config_dcb_tc,
48198+ .config_dcb_pfc = xgbe_config_dcb_pfc,
48199+};
48200diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
48201index b26d758..b0d1c3b 100644
48202--- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
48203+++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
48204@@ -155,7 +155,7 @@ static int xgbe_calc_rx_buf_size(struct net_device *netdev, unsigned int mtu)
48205
48206 static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
48207 {
48208- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48209+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48210 struct xgbe_channel *channel;
48211 enum xgbe_int int_id;
48212 unsigned int i;
48213@@ -177,7 +177,7 @@ static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
48214
48215 static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
48216 {
48217- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48218+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48219 struct xgbe_channel *channel;
48220 enum xgbe_int int_id;
48221 unsigned int i;
48222@@ -200,7 +200,7 @@ static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
48223 static irqreturn_t xgbe_isr(int irq, void *data)
48224 {
48225 struct xgbe_prv_data *pdata = data;
48226- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48227+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48228 struct xgbe_channel *channel;
48229 unsigned int dma_isr, dma_ch_isr;
48230 unsigned int mac_isr, mac_tssr;
48231@@ -447,7 +447,7 @@ static void xgbe_napi_disable(struct xgbe_prv_data *pdata, unsigned int del)
48232
48233 void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
48234 {
48235- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48236+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48237
48238 DBGPR("-->xgbe_init_tx_coalesce\n");
48239
48240@@ -461,7 +461,7 @@ void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
48241
48242 void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
48243 {
48244- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48245+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48246
48247 DBGPR("-->xgbe_init_rx_coalesce\n");
48248
48249@@ -475,7 +475,7 @@ void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
48250
48251 static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
48252 {
48253- struct xgbe_desc_if *desc_if = &pdata->desc_if;
48254+ struct xgbe_desc_if *desc_if = pdata->desc_if;
48255 struct xgbe_channel *channel;
48256 struct xgbe_ring *ring;
48257 struct xgbe_ring_data *rdata;
48258@@ -500,7 +500,7 @@ static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
48259
48260 static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
48261 {
48262- struct xgbe_desc_if *desc_if = &pdata->desc_if;
48263+ struct xgbe_desc_if *desc_if = pdata->desc_if;
48264 struct xgbe_channel *channel;
48265 struct xgbe_ring *ring;
48266 struct xgbe_ring_data *rdata;
48267@@ -526,7 +526,7 @@ static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
48268 static void xgbe_adjust_link(struct net_device *netdev)
48269 {
48270 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48271- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48272+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48273 struct phy_device *phydev = pdata->phydev;
48274 int new_state = 0;
48275
48276@@ -634,7 +634,7 @@ static void xgbe_phy_exit(struct xgbe_prv_data *pdata)
48277 int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
48278 {
48279 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48280- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48281+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48282 unsigned long flags;
48283
48284 DBGPR("-->xgbe_powerdown\n");
48285@@ -672,7 +672,7 @@ int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
48286 int xgbe_powerup(struct net_device *netdev, unsigned int caller)
48287 {
48288 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48289- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48290+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48291 unsigned long flags;
48292
48293 DBGPR("-->xgbe_powerup\n");
48294@@ -709,7 +709,7 @@ int xgbe_powerup(struct net_device *netdev, unsigned int caller)
48295
48296 static int xgbe_start(struct xgbe_prv_data *pdata)
48297 {
48298- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48299+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48300 struct net_device *netdev = pdata->netdev;
48301
48302 DBGPR("-->xgbe_start\n");
48303@@ -735,7 +735,7 @@ static int xgbe_start(struct xgbe_prv_data *pdata)
48304
48305 static void xgbe_stop(struct xgbe_prv_data *pdata)
48306 {
48307- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48308+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48309 struct net_device *netdev = pdata->netdev;
48310
48311 DBGPR("-->xgbe_stop\n");
48312@@ -755,7 +755,7 @@ static void xgbe_stop(struct xgbe_prv_data *pdata)
48313
48314 static void xgbe_restart_dev(struct xgbe_prv_data *pdata, unsigned int reset)
48315 {
48316- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48317+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48318
48319 DBGPR("-->xgbe_restart_dev\n");
48320
48321@@ -952,7 +952,7 @@ static int xgbe_set_hwtstamp_settings(struct xgbe_prv_data *pdata,
48322 return -ERANGE;
48323 }
48324
48325- pdata->hw_if.config_tstamp(pdata, mac_tscr);
48326+ pdata->hw_if->config_tstamp(pdata, mac_tscr);
48327
48328 memcpy(&pdata->tstamp_config, &config, sizeof(config));
48329
48330@@ -1090,8 +1090,8 @@ static void xgbe_packet_info(struct xgbe_prv_data *pdata,
48331 static int xgbe_open(struct net_device *netdev)
48332 {
48333 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48334- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48335- struct xgbe_desc_if *desc_if = &pdata->desc_if;
48336+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48337+ struct xgbe_desc_if *desc_if = pdata->desc_if;
48338 int ret;
48339
48340 DBGPR("-->xgbe_open\n");
48341@@ -1171,8 +1171,8 @@ err_phy_init:
48342 static int xgbe_close(struct net_device *netdev)
48343 {
48344 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48345- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48346- struct xgbe_desc_if *desc_if = &pdata->desc_if;
48347+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48348+ struct xgbe_desc_if *desc_if = pdata->desc_if;
48349
48350 DBGPR("-->xgbe_close\n");
48351
48352@@ -1206,8 +1206,8 @@ static int xgbe_close(struct net_device *netdev)
48353 static int xgbe_xmit(struct sk_buff *skb, struct net_device *netdev)
48354 {
48355 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48356- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48357- struct xgbe_desc_if *desc_if = &pdata->desc_if;
48358+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48359+ struct xgbe_desc_if *desc_if = pdata->desc_if;
48360 struct xgbe_channel *channel;
48361 struct xgbe_ring *ring;
48362 struct xgbe_packet_data *packet;
48363@@ -1276,7 +1276,7 @@ tx_netdev_return:
48364 static void xgbe_set_rx_mode(struct net_device *netdev)
48365 {
48366 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48367- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48368+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48369 unsigned int pr_mode, am_mode;
48370
48371 DBGPR("-->xgbe_set_rx_mode\n");
48372@@ -1295,7 +1295,7 @@ static void xgbe_set_rx_mode(struct net_device *netdev)
48373 static int xgbe_set_mac_address(struct net_device *netdev, void *addr)
48374 {
48375 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48376- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48377+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48378 struct sockaddr *saddr = addr;
48379
48380 DBGPR("-->xgbe_set_mac_address\n");
48381@@ -1362,7 +1362,7 @@ static struct rtnl_link_stats64 *xgbe_get_stats64(struct net_device *netdev,
48382
48383 DBGPR("-->%s\n", __func__);
48384
48385- pdata->hw_if.read_mmc_stats(pdata);
48386+ pdata->hw_if->read_mmc_stats(pdata);
48387
48388 s->rx_packets = pstats->rxframecount_gb;
48389 s->rx_bytes = pstats->rxoctetcount_gb;
48390@@ -1389,7 +1389,7 @@ static int xgbe_vlan_rx_add_vid(struct net_device *netdev, __be16 proto,
48391 u16 vid)
48392 {
48393 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48394- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48395+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48396
48397 DBGPR("-->%s\n", __func__);
48398
48399@@ -1405,7 +1405,7 @@ static int xgbe_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto,
48400 u16 vid)
48401 {
48402 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48403- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48404+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48405
48406 DBGPR("-->%s\n", __func__);
48407
48408@@ -1465,7 +1465,7 @@ static int xgbe_set_features(struct net_device *netdev,
48409 netdev_features_t features)
48410 {
48411 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48412- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48413+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48414 unsigned int rxcsum, rxvlan, rxvlan_filter;
48415
48416 rxcsum = pdata->netdev_features & NETIF_F_RXCSUM;
48417@@ -1521,7 +1521,7 @@ struct net_device_ops *xgbe_get_netdev_ops(void)
48418 static void xgbe_rx_refresh(struct xgbe_channel *channel)
48419 {
48420 struct xgbe_prv_data *pdata = channel->pdata;
48421- struct xgbe_desc_if *desc_if = &pdata->desc_if;
48422+ struct xgbe_desc_if *desc_if = pdata->desc_if;
48423 struct xgbe_ring *ring = channel->rx_ring;
48424 struct xgbe_ring_data *rdata;
48425
48426@@ -1537,8 +1537,8 @@ static void xgbe_rx_refresh(struct xgbe_channel *channel)
48427 static int xgbe_tx_poll(struct xgbe_channel *channel)
48428 {
48429 struct xgbe_prv_data *pdata = channel->pdata;
48430- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48431- struct xgbe_desc_if *desc_if = &pdata->desc_if;
48432+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48433+ struct xgbe_desc_if *desc_if = pdata->desc_if;
48434 struct xgbe_ring *ring = channel->tx_ring;
48435 struct xgbe_ring_data *rdata;
48436 struct xgbe_ring_desc *rdesc;
48437@@ -1590,7 +1590,7 @@ static int xgbe_tx_poll(struct xgbe_channel *channel)
48438 static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
48439 {
48440 struct xgbe_prv_data *pdata = channel->pdata;
48441- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48442+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48443 struct xgbe_ring *ring = channel->rx_ring;
48444 struct xgbe_ring_data *rdata;
48445 struct xgbe_packet_data *packet;
48446diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48447index 46f6130..f37dde3 100644
48448--- a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48449+++ b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48450@@ -203,7 +203,7 @@ static void xgbe_get_ethtool_stats(struct net_device *netdev,
48451
48452 DBGPR("-->%s\n", __func__);
48453
48454- pdata->hw_if.read_mmc_stats(pdata);
48455+ pdata->hw_if->read_mmc_stats(pdata);
48456 for (i = 0; i < XGBE_STATS_COUNT; i++) {
48457 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
48458 *data++ = *(u64 *)stat;
48459@@ -378,7 +378,7 @@ static int xgbe_get_coalesce(struct net_device *netdev,
48460 struct ethtool_coalesce *ec)
48461 {
48462 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48463- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48464+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48465 unsigned int riwt;
48466
48467 DBGPR("-->xgbe_get_coalesce\n");
48468@@ -401,7 +401,7 @@ static int xgbe_set_coalesce(struct net_device *netdev,
48469 struct ethtool_coalesce *ec)
48470 {
48471 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48472- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48473+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48474 unsigned int rx_frames, rx_riwt, rx_usecs;
48475 unsigned int tx_frames, tx_usecs;
48476
48477diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48478index bdf9cfa..340aea1 100644
48479--- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48480+++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48481@@ -210,12 +210,6 @@ static void xgbe_default_config(struct xgbe_prv_data *pdata)
48482 DBGPR("<--xgbe_default_config\n");
48483 }
48484
48485-static void xgbe_init_all_fptrs(struct xgbe_prv_data *pdata)
48486-{
48487- xgbe_init_function_ptrs_dev(&pdata->hw_if);
48488- xgbe_init_function_ptrs_desc(&pdata->desc_if);
48489-}
48490-
48491 static int xgbe_probe(struct platform_device *pdev)
48492 {
48493 struct xgbe_prv_data *pdata;
48494@@ -328,9 +322,8 @@ static int xgbe_probe(struct platform_device *pdev)
48495 netdev->base_addr = (unsigned long)pdata->xgmac_regs;
48496
48497 /* Set all the function pointers */
48498- xgbe_init_all_fptrs(pdata);
48499- hw_if = &pdata->hw_if;
48500- desc_if = &pdata->desc_if;
48501+ hw_if = pdata->hw_if = &default_xgbe_hw_if;
48502+ desc_if = pdata->desc_if = &default_xgbe_desc_if;
48503
48504 /* Issue software reset to device */
48505 hw_if->exit(pdata);
48506diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48507index 6d2221e..47d1325 100644
48508--- a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48509+++ b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48510@@ -127,7 +127,7 @@
48511 static int xgbe_mdio_read(struct mii_bus *mii, int prtad, int mmd_reg)
48512 {
48513 struct xgbe_prv_data *pdata = mii->priv;
48514- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48515+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48516 int mmd_data;
48517
48518 DBGPR_MDIO("-->xgbe_mdio_read: prtad=%#x mmd_reg=%#x\n",
48519@@ -144,7 +144,7 @@ static int xgbe_mdio_write(struct mii_bus *mii, int prtad, int mmd_reg,
48520 u16 mmd_val)
48521 {
48522 struct xgbe_prv_data *pdata = mii->priv;
48523- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48524+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48525 int mmd_data = mmd_val;
48526
48527 DBGPR_MDIO("-->xgbe_mdio_write: prtad=%#x mmd_reg=%#x mmd_data=%#x\n",
48528diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
48529index 37e64cf..c3b61cf 100644
48530--- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
48531+++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
48532@@ -130,7 +130,7 @@ static cycle_t xgbe_cc_read(const struct cyclecounter *cc)
48533 tstamp_cc);
48534 u64 nsec;
48535
48536- nsec = pdata->hw_if.get_tstamp_time(pdata);
48537+ nsec = pdata->hw_if->get_tstamp_time(pdata);
48538
48539 return nsec;
48540 }
48541@@ -159,7 +159,7 @@ static int xgbe_adjfreq(struct ptp_clock_info *info, s32 delta)
48542
48543 spin_lock_irqsave(&pdata->tstamp_lock, flags);
48544
48545- pdata->hw_if.update_tstamp_addend(pdata, addend);
48546+ pdata->hw_if->update_tstamp_addend(pdata, addend);
48547
48548 spin_unlock_irqrestore(&pdata->tstamp_lock, flags);
48549
48550diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h
48551index e9fe6e6..875fbaf 100644
48552--- a/drivers/net/ethernet/amd/xgbe/xgbe.h
48553+++ b/drivers/net/ethernet/amd/xgbe/xgbe.h
48554@@ -585,8 +585,8 @@ struct xgbe_prv_data {
48555
48556 int irq_number;
48557
48558- struct xgbe_hw_if hw_if;
48559- struct xgbe_desc_if desc_if;
48560+ const struct xgbe_hw_if *hw_if;
48561+ const struct xgbe_desc_if *desc_if;
48562
48563 /* AXI DMA settings */
48564 unsigned int axdomain;
48565@@ -699,6 +699,9 @@ struct xgbe_prv_data {
48566 #endif
48567 };
48568
48569+extern const struct xgbe_hw_if default_xgbe_hw_if;
48570+extern const struct xgbe_desc_if default_xgbe_desc_if;
48571+
48572 /* Function prototypes*/
48573
48574 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
48575diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48576index 571427c..e9fe9e7 100644
48577--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48578+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48579@@ -1058,7 +1058,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
48580 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
48581 {
48582 /* RX_MODE controlling object */
48583- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
48584+ bnx2x_init_rx_mode_obj(bp);
48585
48586 /* multicast configuration controlling object */
48587 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
48588diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48589index b193604..8873bfd 100644
48590--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48591+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48592@@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
48593 return rc;
48594 }
48595
48596-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48597- struct bnx2x_rx_mode_obj *o)
48598+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
48599 {
48600 if (CHIP_IS_E1x(bp)) {
48601- o->wait_comp = bnx2x_empty_rx_mode_wait;
48602- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
48603+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
48604+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
48605 } else {
48606- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
48607- o->config_rx_mode = bnx2x_set_rx_mode_e2;
48608+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
48609+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
48610 }
48611 }
48612
48613diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48614index 718ecd2..2183b2f 100644
48615--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48616+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48617@@ -1340,8 +1340,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
48618
48619 /********************* RX MODE ****************/
48620
48621-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48622- struct bnx2x_rx_mode_obj *o);
48623+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
48624
48625 /**
48626 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
48627diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
48628index 31c9f82..e65e986 100644
48629--- a/drivers/net/ethernet/broadcom/tg3.h
48630+++ b/drivers/net/ethernet/broadcom/tg3.h
48631@@ -150,6 +150,7 @@
48632 #define CHIPREV_ID_5750_A0 0x4000
48633 #define CHIPREV_ID_5750_A1 0x4001
48634 #define CHIPREV_ID_5750_A3 0x4003
48635+#define CHIPREV_ID_5750_C1 0x4201
48636 #define CHIPREV_ID_5750_C2 0x4202
48637 #define CHIPREV_ID_5752_A0_HW 0x5000
48638 #define CHIPREV_ID_5752_A0 0x6000
48639diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
48640index 13f9636..228040f 100644
48641--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
48642+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
48643@@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
48644 }
48645
48646 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
48647- bna_cb_ioceth_enable,
48648- bna_cb_ioceth_disable,
48649- bna_cb_ioceth_hbfail,
48650- bna_cb_ioceth_reset
48651+ .enable_cbfn = bna_cb_ioceth_enable,
48652+ .disable_cbfn = bna_cb_ioceth_disable,
48653+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
48654+ .reset_cbfn = bna_cb_ioceth_reset
48655 };
48656
48657 static void bna_attr_init(struct bna_ioceth *ioceth)
48658diff --git a/drivers/net/ethernet/brocade/bna/bnad.c b/drivers/net/ethernet/brocade/bna/bnad.c
48659index ffc92a4..40edc77 100644
48660--- a/drivers/net/ethernet/brocade/bna/bnad.c
48661+++ b/drivers/net/ethernet/brocade/bna/bnad.c
48662@@ -552,6 +552,7 @@ bnad_cq_setup_skb_frags(struct bna_rcb *rcb, struct sk_buff *skb,
48663
48664 len = (vec == nvecs) ?
48665 last_fraglen : unmap->vector.len;
48666+ skb->truesize += unmap->vector.len;
48667 totlen += len;
48668
48669 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
48670@@ -563,7 +564,6 @@ bnad_cq_setup_skb_frags(struct bna_rcb *rcb, struct sk_buff *skb,
48671
48672 skb->len += totlen;
48673 skb->data_len += totlen;
48674- skb->truesize += totlen;
48675 }
48676
48677 static inline void
48678diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48679index 8cffcdf..aadf043 100644
48680--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48681+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48682@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
48683 */
48684 struct l2t_skb_cb {
48685 arp_failure_handler_func arp_failure_handler;
48686-};
48687+} __no_const;
48688
48689 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
48690
48691diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48692index 9f5f3c3..86d21a6 100644
48693--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48694+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48695@@ -2359,7 +2359,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
48696
48697 int i;
48698 struct adapter *ap = netdev2adap(dev);
48699- static const unsigned int *reg_ranges;
48700+ const unsigned int *reg_ranges;
48701 int arr_size = 0, buf_size = 0;
48702
48703 if (is_t4(ap->params.chip)) {
48704diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
48705index cf8b6ff..274271e 100644
48706--- a/drivers/net/ethernet/dec/tulip/de4x5.c
48707+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
48708@@ -5387,7 +5387,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48709 for (i=0; i<ETH_ALEN; i++) {
48710 tmp.addr[i] = dev->dev_addr[i];
48711 }
48712- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48713+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48714 break;
48715
48716 case DE4X5_SET_HWADDR: /* Set the hardware address */
48717@@ -5427,7 +5427,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48718 spin_lock_irqsave(&lp->lock, flags);
48719 memcpy(&statbuf, &lp->pktStats, ioc->len);
48720 spin_unlock_irqrestore(&lp->lock, flags);
48721- if (copy_to_user(ioc->data, &statbuf, ioc->len))
48722+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
48723 return -EFAULT;
48724 break;
48725 }
48726diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
48727index 93ff8ef..39c64dd 100644
48728--- a/drivers/net/ethernet/emulex/benet/be_main.c
48729+++ b/drivers/net/ethernet/emulex/benet/be_main.c
48730@@ -533,7 +533,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
48731
48732 if (wrapped)
48733 newacc += 65536;
48734- ACCESS_ONCE(*acc) = newacc;
48735+ ACCESS_ONCE_RW(*acc) = newacc;
48736 }
48737
48738 static void populate_erx_stats(struct be_adapter *adapter,
48739@@ -4286,6 +4286,9 @@ static int be_ndo_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh)
48740 if (nla_type(attr) != IFLA_BRIDGE_MODE)
48741 continue;
48742
48743+ if (nla_len(attr) < sizeof(mode))
48744+ return -EINVAL;
48745+
48746 mode = nla_get_u16(attr);
48747 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB)
48748 return -EINVAL;
48749diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
48750index c77fa4a..7fd42fc 100644
48751--- a/drivers/net/ethernet/faraday/ftgmac100.c
48752+++ b/drivers/net/ethernet/faraday/ftgmac100.c
48753@@ -30,6 +30,8 @@
48754 #include <linux/netdevice.h>
48755 #include <linux/phy.h>
48756 #include <linux/platform_device.h>
48757+#include <linux/interrupt.h>
48758+#include <linux/irqreturn.h>
48759 #include <net/ip.h>
48760
48761 #include "ftgmac100.h"
48762diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
48763index 4ff1adc..0ea6bf4 100644
48764--- a/drivers/net/ethernet/faraday/ftmac100.c
48765+++ b/drivers/net/ethernet/faraday/ftmac100.c
48766@@ -31,6 +31,8 @@
48767 #include <linux/module.h>
48768 #include <linux/netdevice.h>
48769 #include <linux/platform_device.h>
48770+#include <linux/interrupt.h>
48771+#include <linux/irqreturn.h>
48772
48773 #include "ftmac100.h"
48774
48775diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48776index 537b621..07f87ce 100644
48777--- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48778+++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48779@@ -401,7 +401,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
48780 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
48781
48782 /* Update the base adjustement value. */
48783- ACCESS_ONCE(pf->ptp_base_adj) = incval;
48784+ ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
48785 smp_mb(); /* Force the above update. */
48786 }
48787
48788diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
48789index e82821f..c7dd0af 100644
48790--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
48791+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
48792@@ -7789,6 +7789,9 @@ static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
48793 if (nla_type(attr) != IFLA_BRIDGE_MODE)
48794 continue;
48795
48796+ if (nla_len(attr) < sizeof(mode))
48797+ return -EINVAL;
48798+
48799 mode = nla_get_u16(attr);
48800 if (mode == BRIDGE_MODE_VEPA) {
48801 reg = 0;
48802diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48803index 5fd4b52..87aa34b 100644
48804--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48805+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48806@@ -794,7 +794,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
48807 }
48808
48809 /* update the base incval used to calculate frequency adjustment */
48810- ACCESS_ONCE(adapter->base_incval) = incval;
48811+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
48812 smp_mb();
48813
48814 /* need lock to prevent incorrect read while modifying cyclecounter */
48815diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
48816index c14d4d8..66da603 100644
48817--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
48818+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
48819@@ -1259,6 +1259,9 @@ int ixgbe_ndo_set_vf_spoofchk(struct net_device *netdev, int vf, bool setting)
48820 struct ixgbe_hw *hw = &adapter->hw;
48821 u32 regval;
48822
48823+ if (vf >= adapter->num_vfs)
48824+ return -EINVAL;
48825+
48826 adapter->vfinfo[vf].spoofchk_enabled = setting;
48827
48828 regval = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
48829diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48830index 2bbd01f..e8baa64 100644
48831--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
48832+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48833@@ -3457,7 +3457,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48834 struct __vxge_hw_fifo *fifo;
48835 struct vxge_hw_fifo_config *config;
48836 u32 txdl_size, txdl_per_memblock;
48837- struct vxge_hw_mempool_cbs fifo_mp_callback;
48838+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
48839+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
48840+ };
48841+
48842 struct __vxge_hw_virtualpath *vpath;
48843
48844 if ((vp == NULL) || (attr == NULL)) {
48845@@ -3540,8 +3543,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48846 goto exit;
48847 }
48848
48849- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
48850-
48851 fifo->mempool =
48852 __vxge_hw_mempool_create(vpath->hldev,
48853 fifo->config->memblock_size,
48854diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48855index 3172cdf..d01ab34 100644
48856--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48857+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48858@@ -2190,7 +2190,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
48859 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
48860 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
48861 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
48862- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48863+ pax_open_kernel();
48864+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48865+ pax_close_kernel();
48866 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48867 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
48868 max_tx_rings = QLCNIC_MAX_TX_RINGS;
48869diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48870index be7d7a6..a8983f8 100644
48871--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48872+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48873@@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
48874 case QLCNIC_NON_PRIV_FUNC:
48875 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
48876 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48877- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48878+ pax_open_kernel();
48879+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48880+ pax_close_kernel();
48881 break;
48882 case QLCNIC_PRIV_FUNC:
48883 ahw->op_mode = QLCNIC_PRIV_FUNC;
48884 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
48885- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48886+ pax_open_kernel();
48887+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48888+ pax_close_kernel();
48889 break;
48890 case QLCNIC_MGMT_FUNC:
48891 ahw->op_mode = QLCNIC_MGMT_FUNC;
48892 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48893- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48894+ pax_open_kernel();
48895+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48896+ pax_close_kernel();
48897 break;
48898 default:
48899 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
48900diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48901index c9f57fb..208bdc1 100644
48902--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48903+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48904@@ -1285,7 +1285,7 @@ flash_temp:
48905 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
48906 {
48907 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
48908- static const struct qlcnic_dump_operations *fw_dump_ops;
48909+ const struct qlcnic_dump_operations *fw_dump_ops;
48910 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
48911 u32 entry_offset, dump, no_entries, buf_offset = 0;
48912 int i, k, ops_cnt, ops_index, dump_size = 0;
48913diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
48914index 0921302..927f761 100644
48915--- a/drivers/net/ethernet/realtek/r8169.c
48916+++ b/drivers/net/ethernet/realtek/r8169.c
48917@@ -744,22 +744,22 @@ struct rtl8169_private {
48918 struct mdio_ops {
48919 void (*write)(struct rtl8169_private *, int, int);
48920 int (*read)(struct rtl8169_private *, int);
48921- } mdio_ops;
48922+ } __no_const mdio_ops;
48923
48924 struct pll_power_ops {
48925 void (*down)(struct rtl8169_private *);
48926 void (*up)(struct rtl8169_private *);
48927- } pll_power_ops;
48928+ } __no_const pll_power_ops;
48929
48930 struct jumbo_ops {
48931 void (*enable)(struct rtl8169_private *);
48932 void (*disable)(struct rtl8169_private *);
48933- } jumbo_ops;
48934+ } __no_const jumbo_ops;
48935
48936 struct csi_ops {
48937 void (*write)(struct rtl8169_private *, int, int);
48938 u32 (*read)(struct rtl8169_private *, int);
48939- } csi_ops;
48940+ } __no_const csi_ops;
48941
48942 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
48943 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
48944diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
48945index 6b861e3..204ac86 100644
48946--- a/drivers/net/ethernet/sfc/ptp.c
48947+++ b/drivers/net/ethernet/sfc/ptp.c
48948@@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
48949 ptp->start.dma_addr);
48950
48951 /* Clear flag that signals MC ready */
48952- ACCESS_ONCE(*start) = 0;
48953+ ACCESS_ONCE_RW(*start) = 0;
48954 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
48955 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
48956 EFX_BUG_ON_PARANOID(rc);
48957diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48958index 08c483b..2c4a553 100644
48959--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48960+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48961@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
48962
48963 writel(value, ioaddr + MMC_CNTRL);
48964
48965- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48966- MMC_CNTRL, value);
48967+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48968+// MMC_CNTRL, value);
48969 }
48970
48971 /* To mask all all interrupts.*/
48972diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
48973index d5e07de..e3bf20a 100644
48974--- a/drivers/net/hyperv/hyperv_net.h
48975+++ b/drivers/net/hyperv/hyperv_net.h
48976@@ -171,7 +171,7 @@ struct rndis_device {
48977 enum rndis_device_state state;
48978 bool link_state;
48979 bool link_change;
48980- atomic_t new_req_id;
48981+ atomic_unchecked_t new_req_id;
48982
48983 spinlock_t request_lock;
48984 struct list_head req_list;
48985diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
48986index 2b86f0b..ecc996f 100644
48987--- a/drivers/net/hyperv/rndis_filter.c
48988+++ b/drivers/net/hyperv/rndis_filter.c
48989@@ -102,7 +102,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
48990 * template
48991 */
48992 set = &rndis_msg->msg.set_req;
48993- set->req_id = atomic_inc_return(&dev->new_req_id);
48994+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48995
48996 /* Add to the request list */
48997 spin_lock_irqsave(&dev->request_lock, flags);
48998@@ -911,7 +911,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
48999
49000 /* Setup the rndis set */
49001 halt = &request->request_msg.msg.halt_req;
49002- halt->req_id = atomic_inc_return(&dev->new_req_id);
49003+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
49004
49005 /* Ignore return since this msg is optional. */
49006 rndis_filter_send_request(dev, request);
49007diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
49008index 6cbc56a..5f7e6c8 100644
49009--- a/drivers/net/ieee802154/fakehard.c
49010+++ b/drivers/net/ieee802154/fakehard.c
49011@@ -365,7 +365,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
49012 phy->transmit_power = 0xbf;
49013
49014 dev->netdev_ops = &fake_ops;
49015- dev->ml_priv = &fake_mlme;
49016+ dev->ml_priv = (void *)&fake_mlme;
49017
49018 priv = netdev_priv(dev);
49019 priv->phy = phy;
49020diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
49021index d2d4a3d..8b7a1be 100644
49022--- a/drivers/net/ifb.c
49023+++ b/drivers/net/ifb.c
49024@@ -252,7 +252,7 @@ static int ifb_validate(struct nlattr *tb[], struct nlattr *data[])
49025 return 0;
49026 }
49027
49028-static struct rtnl_link_ops ifb_link_ops __read_mostly = {
49029+static struct rtnl_link_ops ifb_link_ops = {
49030 .kind = "ifb",
49031 .priv_size = sizeof(struct ifb_private),
49032 .setup = ifb_setup,
49033diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
49034index 5f17ad0..e0463c8 100644
49035--- a/drivers/net/macvlan.c
49036+++ b/drivers/net/macvlan.c
49037@@ -264,7 +264,7 @@ static void macvlan_broadcast_enqueue(struct macvlan_port *port,
49038 free_nskb:
49039 kfree_skb(nskb);
49040 err:
49041- atomic_long_inc(&skb->dev->rx_dropped);
49042+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
49043 }
49044
49045 /* called under rcu_read_lock() from netif_receive_skb */
49046@@ -1150,13 +1150,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
49047 int macvlan_link_register(struct rtnl_link_ops *ops)
49048 {
49049 /* common fields */
49050- ops->priv_size = sizeof(struct macvlan_dev);
49051- ops->validate = macvlan_validate;
49052- ops->maxtype = IFLA_MACVLAN_MAX;
49053- ops->policy = macvlan_policy;
49054- ops->changelink = macvlan_changelink;
49055- ops->get_size = macvlan_get_size;
49056- ops->fill_info = macvlan_fill_info;
49057+ pax_open_kernel();
49058+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
49059+ *(void **)&ops->validate = macvlan_validate;
49060+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
49061+ *(const void **)&ops->policy = macvlan_policy;
49062+ *(void **)&ops->changelink = macvlan_changelink;
49063+ *(void **)&ops->get_size = macvlan_get_size;
49064+ *(void **)&ops->fill_info = macvlan_fill_info;
49065+ pax_close_kernel();
49066
49067 return rtnl_link_register(ops);
49068 };
49069@@ -1236,7 +1238,7 @@ static int macvlan_device_event(struct notifier_block *unused,
49070 return NOTIFY_DONE;
49071 }
49072
49073-static struct notifier_block macvlan_notifier_block __read_mostly = {
49074+static struct notifier_block macvlan_notifier_block = {
49075 .notifier_call = macvlan_device_event,
49076 };
49077
49078diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
49079index 07c942b..bce8b8a 100644
49080--- a/drivers/net/macvtap.c
49081+++ b/drivers/net/macvtap.c
49082@@ -422,7 +422,7 @@ static void macvtap_setup(struct net_device *dev)
49083 dev->tx_queue_len = TUN_READQ_SIZE;
49084 }
49085
49086-static struct rtnl_link_ops macvtap_link_ops __read_mostly = {
49087+static struct rtnl_link_ops macvtap_link_ops = {
49088 .kind = "macvtap",
49089 .setup = macvtap_setup,
49090 .newlink = macvtap_newlink,
49091@@ -1023,7 +1023,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
49092 }
49093
49094 ret = 0;
49095- if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
49096+ if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
49097 put_user(q->flags, &ifr->ifr_flags))
49098 ret = -EFAULT;
49099 macvtap_put_vlan(vlan);
49100@@ -1193,7 +1193,7 @@ static int macvtap_device_event(struct notifier_block *unused,
49101 return NOTIFY_DONE;
49102 }
49103
49104-static struct notifier_block macvtap_notifier_block __read_mostly = {
49105+static struct notifier_block macvtap_notifier_block = {
49106 .notifier_call = macvtap_device_event,
49107 };
49108
49109diff --git a/drivers/net/nlmon.c b/drivers/net/nlmon.c
49110index 34924df..a747360 100644
49111--- a/drivers/net/nlmon.c
49112+++ b/drivers/net/nlmon.c
49113@@ -154,7 +154,7 @@ static int nlmon_validate(struct nlattr *tb[], struct nlattr *data[])
49114 return 0;
49115 }
49116
49117-static struct rtnl_link_ops nlmon_link_ops __read_mostly = {
49118+static struct rtnl_link_ops nlmon_link_ops = {
49119 .kind = "nlmon",
49120 .priv_size = sizeof(struct nlmon),
49121 .setup = nlmon_setup,
49122diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
49123index 17ecdd6..79ad848 100644
49124--- a/drivers/net/ppp/ppp_generic.c
49125+++ b/drivers/net/ppp/ppp_generic.c
49126@@ -1020,7 +1020,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
49127 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
49128 struct ppp_stats stats;
49129 struct ppp_comp_stats cstats;
49130- char *vers;
49131
49132 switch (cmd) {
49133 case SIOCGPPPSTATS:
49134@@ -1042,8 +1041,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
49135 break;
49136
49137 case SIOCGPPPVER:
49138- vers = PPP_VERSION;
49139- if (copy_to_user(addr, vers, strlen(vers) + 1))
49140+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
49141 break;
49142 err = 0;
49143 break;
49144diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
49145index 079f7ad..b2a2bfa7 100644
49146--- a/drivers/net/slip/slhc.c
49147+++ b/drivers/net/slip/slhc.c
49148@@ -487,7 +487,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
49149 register struct tcphdr *thp;
49150 register struct iphdr *ip;
49151 register struct cstate *cs;
49152- int len, hdrlen;
49153+ long len, hdrlen;
49154 unsigned char *cp = icp;
49155
49156 /* We've got a compressed packet; read the change byte */
49157diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
49158index 1f76c2ea..997760b 100644
49159--- a/drivers/net/team/team.c
49160+++ b/drivers/net/team/team.c
49161@@ -2072,7 +2072,7 @@ static unsigned int team_get_num_rx_queues(void)
49162 return TEAM_DEFAULT_NUM_RX_QUEUES;
49163 }
49164
49165-static struct rtnl_link_ops team_link_ops __read_mostly = {
49166+static struct rtnl_link_ops team_link_ops = {
49167 .kind = DRV_NAME,
49168 .priv_size = sizeof(struct team),
49169 .setup = team_setup,
49170@@ -2862,7 +2862,7 @@ static int team_device_event(struct notifier_block *unused,
49171 return NOTIFY_DONE;
49172 }
49173
49174-static struct notifier_block team_notifier_block __read_mostly = {
49175+static struct notifier_block team_notifier_block = {
49176 .notifier_call = team_device_event,
49177 };
49178
49179diff --git a/drivers/net/tun.c b/drivers/net/tun.c
49180index d965e8a..6226000 100644
49181--- a/drivers/net/tun.c
49182+++ b/drivers/net/tun.c
49183@@ -1414,7 +1414,7 @@ static int tun_validate(struct nlattr *tb[], struct nlattr *data[])
49184 return -EINVAL;
49185 }
49186
49187-static struct rtnl_link_ops tun_link_ops __read_mostly = {
49188+static struct rtnl_link_ops tun_link_ops = {
49189 .kind = DRV_NAME,
49190 .priv_size = sizeof(struct tun_struct),
49191 .setup = tun_setup,
49192@@ -1861,7 +1861,7 @@ unlock:
49193 }
49194
49195 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
49196- unsigned long arg, int ifreq_len)
49197+ unsigned long arg, size_t ifreq_len)
49198 {
49199 struct tun_file *tfile = file->private_data;
49200 struct tun_struct *tun;
49201@@ -1874,6 +1874,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
49202 unsigned int ifindex;
49203 int ret;
49204
49205+ if (ifreq_len > sizeof ifr)
49206+ return -EFAULT;
49207+
49208 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
49209 if (copy_from_user(&ifr, argp, ifreq_len))
49210 return -EFAULT;
49211diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
49212index babda7d..e40c90a 100644
49213--- a/drivers/net/usb/hso.c
49214+++ b/drivers/net/usb/hso.c
49215@@ -71,7 +71,7 @@
49216 #include <asm/byteorder.h>
49217 #include <linux/serial_core.h>
49218 #include <linux/serial.h>
49219-
49220+#include <asm/local.h>
49221
49222 #define MOD_AUTHOR "Option Wireless"
49223 #define MOD_DESCRIPTION "USB High Speed Option driver"
49224@@ -1178,7 +1178,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
49225 struct urb *urb;
49226
49227 urb = serial->rx_urb[0];
49228- if (serial->port.count > 0) {
49229+ if (atomic_read(&serial->port.count) > 0) {
49230 count = put_rxbuf_data(urb, serial);
49231 if (count == -1)
49232 return;
49233@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
49234 DUMP1(urb->transfer_buffer, urb->actual_length);
49235
49236 /* Anyone listening? */
49237- if (serial->port.count == 0)
49238+ if (atomic_read(&serial->port.count) == 0)
49239 return;
49240
49241 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
49242@@ -1278,8 +1278,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
49243 tty_port_tty_set(&serial->port, tty);
49244
49245 /* check for port already opened, if not set the termios */
49246- serial->port.count++;
49247- if (serial->port.count == 1) {
49248+ if (atomic_inc_return(&serial->port.count) == 1) {
49249 serial->rx_state = RX_IDLE;
49250 /* Force default termio settings */
49251 _hso_serial_set_termios(tty, NULL);
49252@@ -1289,7 +1288,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
49253 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
49254 if (result) {
49255 hso_stop_serial_device(serial->parent);
49256- serial->port.count--;
49257+ atomic_dec(&serial->port.count);
49258 kref_put(&serial->parent->ref, hso_serial_ref_free);
49259 }
49260 } else {
49261@@ -1326,10 +1325,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
49262
49263 /* reset the rts and dtr */
49264 /* do the actual close */
49265- serial->port.count--;
49266+ atomic_dec(&serial->port.count);
49267
49268- if (serial->port.count <= 0) {
49269- serial->port.count = 0;
49270+ if (atomic_read(&serial->port.count) <= 0) {
49271+ atomic_set(&serial->port.count, 0);
49272 tty_port_tty_set(&serial->port, NULL);
49273 if (!usb_gone)
49274 hso_stop_serial_device(serial->parent);
49275@@ -1404,7 +1403,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
49276
49277 /* the actual setup */
49278 spin_lock_irqsave(&serial->serial_lock, flags);
49279- if (serial->port.count)
49280+ if (atomic_read(&serial->port.count))
49281 _hso_serial_set_termios(tty, old);
49282 else
49283 tty->termios = *old;
49284@@ -1873,7 +1872,7 @@ static void intr_callback(struct urb *urb)
49285 D1("Pending read interrupt on port %d\n", i);
49286 spin_lock(&serial->serial_lock);
49287 if (serial->rx_state == RX_IDLE &&
49288- serial->port.count > 0) {
49289+ atomic_read(&serial->port.count) > 0) {
49290 /* Setup and send a ctrl req read on
49291 * port i */
49292 if (!serial->rx_urb_filled[0]) {
49293@@ -3047,7 +3046,7 @@ static int hso_resume(struct usb_interface *iface)
49294 /* Start all serial ports */
49295 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
49296 if (serial_table[i] && (serial_table[i]->interface == iface)) {
49297- if (dev2ser(serial_table[i])->port.count) {
49298+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
49299 result =
49300 hso_start_serial_device(serial_table[i], GFP_NOIO);
49301 hso_kick_transmit(dev2ser(serial_table[i]));
49302diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
49303index 604ef21..d1f49a1 100644
49304--- a/drivers/net/usb/r8152.c
49305+++ b/drivers/net/usb/r8152.c
49306@@ -575,7 +575,7 @@ struct r8152 {
49307 void (*up)(struct r8152 *);
49308 void (*down)(struct r8152 *);
49309 void (*unload)(struct r8152 *);
49310- } rtl_ops;
49311+ } __no_const rtl_ops;
49312
49313 int intr_interval;
49314 u32 saved_wolopts;
49315diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
49316index a2515887..6d13233 100644
49317--- a/drivers/net/usb/sierra_net.c
49318+++ b/drivers/net/usb/sierra_net.c
49319@@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
49320 /* atomic counter partially included in MAC address to make sure 2 devices
49321 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
49322 */
49323-static atomic_t iface_counter = ATOMIC_INIT(0);
49324+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
49325
49326 /*
49327 * SYNC Timer Delay definition used to set the expiry time
49328@@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
49329 dev->net->netdev_ops = &sierra_net_device_ops;
49330
49331 /* change MAC addr to include, ifacenum, and to be unique */
49332- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
49333+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
49334 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
49335
49336 /* we will have to manufacture ethernet headers, prepare template */
49337diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
49338index 59caa06..de191b3 100644
49339--- a/drivers/net/virtio_net.c
49340+++ b/drivers/net/virtio_net.c
49341@@ -48,7 +48,7 @@ module_param(gso, bool, 0444);
49342 #define RECEIVE_AVG_WEIGHT 64
49343
49344 /* Minimum alignment for mergeable packet buffers. */
49345-#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
49346+#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
49347
49348 #define VIRTNET_DRIVER_VERSION "1.0.0"
49349
49350diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
49351index 81a8a29..ae60a58 100644
49352--- a/drivers/net/vxlan.c
49353+++ b/drivers/net/vxlan.c
49354@@ -2762,7 +2762,7 @@ nla_put_failure:
49355 return -EMSGSIZE;
49356 }
49357
49358-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
49359+static struct rtnl_link_ops vxlan_link_ops = {
49360 .kind = "vxlan",
49361 .maxtype = IFLA_VXLAN_MAX,
49362 .policy = vxlan_policy,
49363@@ -2809,7 +2809,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
49364 return NOTIFY_DONE;
49365 }
49366
49367-static struct notifier_block vxlan_notifier_block __read_mostly = {
49368+static struct notifier_block vxlan_notifier_block = {
49369 .notifier_call = vxlan_lowerdev_event,
49370 };
49371
49372diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
49373index 5920c99..ff2e4a5 100644
49374--- a/drivers/net/wan/lmc/lmc_media.c
49375+++ b/drivers/net/wan/lmc/lmc_media.c
49376@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
49377 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
49378
49379 lmc_media_t lmc_ds3_media = {
49380- lmc_ds3_init, /* special media init stuff */
49381- lmc_ds3_default, /* reset to default state */
49382- lmc_ds3_set_status, /* reset status to state provided */
49383- lmc_dummy_set_1, /* set clock source */
49384- lmc_dummy_set2_1, /* set line speed */
49385- lmc_ds3_set_100ft, /* set cable length */
49386- lmc_ds3_set_scram, /* set scrambler */
49387- lmc_ds3_get_link_status, /* get link status */
49388- lmc_dummy_set_1, /* set link status */
49389- lmc_ds3_set_crc_length, /* set CRC length */
49390- lmc_dummy_set_1, /* set T1 or E1 circuit type */
49391- lmc_ds3_watchdog
49392+ .init = lmc_ds3_init, /* special media init stuff */
49393+ .defaults = lmc_ds3_default, /* reset to default state */
49394+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
49395+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
49396+ .set_speed = lmc_dummy_set2_1, /* set line speed */
49397+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
49398+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
49399+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
49400+ .set_link_status = lmc_dummy_set_1, /* set link status */
49401+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
49402+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49403+ .watchdog = lmc_ds3_watchdog
49404 };
49405
49406 lmc_media_t lmc_hssi_media = {
49407- lmc_hssi_init, /* special media init stuff */
49408- lmc_hssi_default, /* reset to default state */
49409- lmc_hssi_set_status, /* reset status to state provided */
49410- lmc_hssi_set_clock, /* set clock source */
49411- lmc_dummy_set2_1, /* set line speed */
49412- lmc_dummy_set_1, /* set cable length */
49413- lmc_dummy_set_1, /* set scrambler */
49414- lmc_hssi_get_link_status, /* get link status */
49415- lmc_hssi_set_link_status, /* set link status */
49416- lmc_hssi_set_crc_length, /* set CRC length */
49417- lmc_dummy_set_1, /* set T1 or E1 circuit type */
49418- lmc_hssi_watchdog
49419+ .init = lmc_hssi_init, /* special media init stuff */
49420+ .defaults = lmc_hssi_default, /* reset to default state */
49421+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
49422+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
49423+ .set_speed = lmc_dummy_set2_1, /* set line speed */
49424+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
49425+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49426+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
49427+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
49428+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
49429+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49430+ .watchdog = lmc_hssi_watchdog
49431 };
49432
49433-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
49434- lmc_ssi_default, /* reset to default state */
49435- lmc_ssi_set_status, /* reset status to state provided */
49436- lmc_ssi_set_clock, /* set clock source */
49437- lmc_ssi_set_speed, /* set line speed */
49438- lmc_dummy_set_1, /* set cable length */
49439- lmc_dummy_set_1, /* set scrambler */
49440- lmc_ssi_get_link_status, /* get link status */
49441- lmc_ssi_set_link_status, /* set link status */
49442- lmc_ssi_set_crc_length, /* set CRC length */
49443- lmc_dummy_set_1, /* set T1 or E1 circuit type */
49444- lmc_ssi_watchdog
49445+lmc_media_t lmc_ssi_media = {
49446+ .init = lmc_ssi_init, /* special media init stuff */
49447+ .defaults = lmc_ssi_default, /* reset to default state */
49448+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
49449+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
49450+ .set_speed = lmc_ssi_set_speed, /* set line speed */
49451+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
49452+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49453+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
49454+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
49455+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
49456+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49457+ .watchdog = lmc_ssi_watchdog
49458 };
49459
49460 lmc_media_t lmc_t1_media = {
49461- lmc_t1_init, /* special media init stuff */
49462- lmc_t1_default, /* reset to default state */
49463- lmc_t1_set_status, /* reset status to state provided */
49464- lmc_t1_set_clock, /* set clock source */
49465- lmc_dummy_set2_1, /* set line speed */
49466- lmc_dummy_set_1, /* set cable length */
49467- lmc_dummy_set_1, /* set scrambler */
49468- lmc_t1_get_link_status, /* get link status */
49469- lmc_dummy_set_1, /* set link status */
49470- lmc_t1_set_crc_length, /* set CRC length */
49471- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
49472- lmc_t1_watchdog
49473+ .init = lmc_t1_init, /* special media init stuff */
49474+ .defaults = lmc_t1_default, /* reset to default state */
49475+ .set_status = lmc_t1_set_status, /* reset status to state provided */
49476+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
49477+ .set_speed = lmc_dummy_set2_1, /* set line speed */
49478+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
49479+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49480+ .get_link_status = lmc_t1_get_link_status, /* get link status */
49481+ .set_link_status = lmc_dummy_set_1, /* set link status */
49482+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
49483+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
49484+ .watchdog = lmc_t1_watchdog
49485 };
49486
49487 static void
49488diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
49489index feacc3b..5bac0de 100644
49490--- a/drivers/net/wan/z85230.c
49491+++ b/drivers/net/wan/z85230.c
49492@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
49493
49494 struct z8530_irqhandler z8530_sync =
49495 {
49496- z8530_rx,
49497- z8530_tx,
49498- z8530_status
49499+ .rx = z8530_rx,
49500+ .tx = z8530_tx,
49501+ .status = z8530_status
49502 };
49503
49504 EXPORT_SYMBOL(z8530_sync);
49505@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
49506 }
49507
49508 static struct z8530_irqhandler z8530_dma_sync = {
49509- z8530_dma_rx,
49510- z8530_dma_tx,
49511- z8530_dma_status
49512+ .rx = z8530_dma_rx,
49513+ .tx = z8530_dma_tx,
49514+ .status = z8530_dma_status
49515 };
49516
49517 static struct z8530_irqhandler z8530_txdma_sync = {
49518- z8530_rx,
49519- z8530_dma_tx,
49520- z8530_dma_status
49521+ .rx = z8530_rx,
49522+ .tx = z8530_dma_tx,
49523+ .status = z8530_dma_status
49524 };
49525
49526 /**
49527@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
49528
49529 struct z8530_irqhandler z8530_nop=
49530 {
49531- z8530_rx_clear,
49532- z8530_tx_clear,
49533- z8530_status_clear
49534+ .rx = z8530_rx_clear,
49535+ .tx = z8530_tx_clear,
49536+ .status = z8530_status_clear
49537 };
49538
49539
49540diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
49541index 0b60295..b8bfa5b 100644
49542--- a/drivers/net/wimax/i2400m/rx.c
49543+++ b/drivers/net/wimax/i2400m/rx.c
49544@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
49545 if (i2400m->rx_roq == NULL)
49546 goto error_roq_alloc;
49547
49548- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
49549+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
49550 GFP_KERNEL);
49551 if (rd == NULL) {
49552 result = -ENOMEM;
49553diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
49554index e71a2ce..2268d61 100644
49555--- a/drivers/net/wireless/airo.c
49556+++ b/drivers/net/wireless/airo.c
49557@@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
49558 struct airo_info *ai = dev->ml_priv;
49559 int ridcode;
49560 int enabled;
49561- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
49562+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
49563 unsigned char *iobuf;
49564
49565 /* Only super-user can write RIDs */
49566diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
49567index da92bfa..5a9001a 100644
49568--- a/drivers/net/wireless/at76c50x-usb.c
49569+++ b/drivers/net/wireless/at76c50x-usb.c
49570@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
49571 }
49572
49573 /* Convert timeout from the DFU status to jiffies */
49574-static inline unsigned long at76_get_timeout(struct dfu_status *s)
49575+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
49576 {
49577 return msecs_to_jiffies((s->poll_timeout[2] << 16)
49578 | (s->poll_timeout[1] << 8)
49579diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
49580index 5fdc40d..3975205 100644
49581--- a/drivers/net/wireless/ath/ath10k/htc.c
49582+++ b/drivers/net/wireless/ath/ath10k/htc.c
49583@@ -856,7 +856,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
49584 /* registered target arrival callback from the HIF layer */
49585 int ath10k_htc_init(struct ath10k *ar)
49586 {
49587- struct ath10k_hif_cb htc_callbacks;
49588+ static struct ath10k_hif_cb htc_callbacks = {
49589+ .rx_completion = ath10k_htc_rx_completion_handler,
49590+ .tx_completion = ath10k_htc_tx_completion_handler,
49591+ };
49592 struct ath10k_htc_ep *ep = NULL;
49593 struct ath10k_htc *htc = &ar->htc;
49594
49595@@ -866,8 +869,6 @@ int ath10k_htc_init(struct ath10k *ar)
49596 ath10k_htc_reset_endpoint_states(htc);
49597
49598 /* setup HIF layer callbacks */
49599- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
49600- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
49601 htc->ar = ar;
49602
49603 /* Get HIF default pipe for HTC message exchange */
49604diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
49605index 4716d33..a688310 100644
49606--- a/drivers/net/wireless/ath/ath10k/htc.h
49607+++ b/drivers/net/wireless/ath/ath10k/htc.h
49608@@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
49609
49610 struct ath10k_htc_ops {
49611 void (*target_send_suspend_complete)(struct ath10k *ar);
49612-};
49613+} __no_const;
49614
49615 struct ath10k_htc_ep_ops {
49616 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
49617 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
49618 void (*ep_tx_credits)(struct ath10k *);
49619-};
49620+} __no_const;
49621
49622 /* service connection information */
49623 struct ath10k_htc_svc_conn_req {
49624diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49625index 59af9f9..5f3564f 100644
49626--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49627+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49628@@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49629 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
49630 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
49631
49632- ACCESS_ONCE(ads->ds_link) = i->link;
49633- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
49634+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
49635+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
49636
49637 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
49638 ctl6 = SM(i->keytype, AR_EncrType);
49639@@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49640
49641 if ((i->is_first || i->is_last) &&
49642 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
49643- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
49644+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
49645 | set11nTries(i->rates, 1)
49646 | set11nTries(i->rates, 2)
49647 | set11nTries(i->rates, 3)
49648 | (i->dur_update ? AR_DurUpdateEna : 0)
49649 | SM(0, AR_BurstDur);
49650
49651- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
49652+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
49653 | set11nRate(i->rates, 1)
49654 | set11nRate(i->rates, 2)
49655 | set11nRate(i->rates, 3);
49656 } else {
49657- ACCESS_ONCE(ads->ds_ctl2) = 0;
49658- ACCESS_ONCE(ads->ds_ctl3) = 0;
49659+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
49660+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
49661 }
49662
49663 if (!i->is_first) {
49664- ACCESS_ONCE(ads->ds_ctl0) = 0;
49665- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
49666- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
49667+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
49668+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
49669+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
49670 return;
49671 }
49672
49673@@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49674 break;
49675 }
49676
49677- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
49678+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
49679 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49680 | SM(i->txpower, AR_XmitPower0)
49681 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49682@@ -289,27 +289,27 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49683 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
49684 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
49685
49686- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
49687- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
49688+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
49689+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
49690
49691 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
49692 return;
49693
49694- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
49695+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
49696 | set11nPktDurRTSCTS(i->rates, 1);
49697
49698- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
49699+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
49700 | set11nPktDurRTSCTS(i->rates, 3);
49701
49702- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49703+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49704 | set11nRateFlags(i->rates, 1)
49705 | set11nRateFlags(i->rates, 2)
49706 | set11nRateFlags(i->rates, 3)
49707 | SM(i->rtscts_rate, AR_RTSCTSRate);
49708
49709- ACCESS_ONCE(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49710- ACCESS_ONCE(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49711- ACCESS_ONCE(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49712+ ACCESS_ONCE_RW(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49713+ ACCESS_ONCE_RW(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49714+ ACCESS_ONCE_RW(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49715 }
49716
49717 static int ar9002_hw_proc_txdesc(struct ath_hw *ah, void *ds,
49718diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49719index 71e38e8..5ac96ca 100644
49720--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49721+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49722@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49723 (i->qcu << AR_TxQcuNum_S) | desc_len;
49724
49725 checksum += val;
49726- ACCESS_ONCE(ads->info) = val;
49727+ ACCESS_ONCE_RW(ads->info) = val;
49728
49729 checksum += i->link;
49730- ACCESS_ONCE(ads->link) = i->link;
49731+ ACCESS_ONCE_RW(ads->link) = i->link;
49732
49733 checksum += i->buf_addr[0];
49734- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
49735+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
49736 checksum += i->buf_addr[1];
49737- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
49738+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
49739 checksum += i->buf_addr[2];
49740- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
49741+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
49742 checksum += i->buf_addr[3];
49743- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
49744+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
49745
49746 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
49747- ACCESS_ONCE(ads->ctl3) = val;
49748+ ACCESS_ONCE_RW(ads->ctl3) = val;
49749 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
49750- ACCESS_ONCE(ads->ctl5) = val;
49751+ ACCESS_ONCE_RW(ads->ctl5) = val;
49752 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
49753- ACCESS_ONCE(ads->ctl7) = val;
49754+ ACCESS_ONCE_RW(ads->ctl7) = val;
49755 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
49756- ACCESS_ONCE(ads->ctl9) = val;
49757+ ACCESS_ONCE_RW(ads->ctl9) = val;
49758
49759 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
49760- ACCESS_ONCE(ads->ctl10) = checksum;
49761+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
49762
49763 if (i->is_first || i->is_last) {
49764- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
49765+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
49766 | set11nTries(i->rates, 1)
49767 | set11nTries(i->rates, 2)
49768 | set11nTries(i->rates, 3)
49769 | (i->dur_update ? AR_DurUpdateEna : 0)
49770 | SM(0, AR_BurstDur);
49771
49772- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
49773+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
49774 | set11nRate(i->rates, 1)
49775 | set11nRate(i->rates, 2)
49776 | set11nRate(i->rates, 3);
49777 } else {
49778- ACCESS_ONCE(ads->ctl13) = 0;
49779- ACCESS_ONCE(ads->ctl14) = 0;
49780+ ACCESS_ONCE_RW(ads->ctl13) = 0;
49781+ ACCESS_ONCE_RW(ads->ctl14) = 0;
49782 }
49783
49784 ads->ctl20 = 0;
49785@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49786
49787 ctl17 = SM(i->keytype, AR_EncrType);
49788 if (!i->is_first) {
49789- ACCESS_ONCE(ads->ctl11) = 0;
49790- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49791- ACCESS_ONCE(ads->ctl15) = 0;
49792- ACCESS_ONCE(ads->ctl16) = 0;
49793- ACCESS_ONCE(ads->ctl17) = ctl17;
49794- ACCESS_ONCE(ads->ctl18) = 0;
49795- ACCESS_ONCE(ads->ctl19) = 0;
49796+ ACCESS_ONCE_RW(ads->ctl11) = 0;
49797+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49798+ ACCESS_ONCE_RW(ads->ctl15) = 0;
49799+ ACCESS_ONCE_RW(ads->ctl16) = 0;
49800+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49801+ ACCESS_ONCE_RW(ads->ctl18) = 0;
49802+ ACCESS_ONCE_RW(ads->ctl19) = 0;
49803 return;
49804 }
49805
49806- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49807+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49808 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49809 | SM(i->txpower, AR_XmitPower0)
49810 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49811@@ -135,26 +135,26 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49812 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
49813 ctl12 |= SM(val, AR_PAPRDChainMask);
49814
49815- ACCESS_ONCE(ads->ctl12) = ctl12;
49816- ACCESS_ONCE(ads->ctl17) = ctl17;
49817+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
49818+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49819
49820- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49821+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49822 | set11nPktDurRTSCTS(i->rates, 1);
49823
49824- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49825+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49826 | set11nPktDurRTSCTS(i->rates, 3);
49827
49828- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
49829+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
49830 | set11nRateFlags(i->rates, 1)
49831 | set11nRateFlags(i->rates, 2)
49832 | set11nRateFlags(i->rates, 3)
49833 | SM(i->rtscts_rate, AR_RTSCTSRate);
49834
49835- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
49836+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
49837
49838- ACCESS_ONCE(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49839- ACCESS_ONCE(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49840- ACCESS_ONCE(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49841+ ACCESS_ONCE_RW(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49842+ ACCESS_ONCE_RW(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49843+ ACCESS_ONCE_RW(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49844 }
49845
49846 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
49847diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
49848index 51b4ebe..d1929dd 100644
49849--- a/drivers/net/wireless/ath/ath9k/hw.h
49850+++ b/drivers/net/wireless/ath/ath9k/hw.h
49851@@ -629,7 +629,7 @@ struct ath_hw_private_ops {
49852
49853 /* ANI */
49854 void (*ani_cache_ini_regs)(struct ath_hw *ah);
49855-};
49856+} __no_const;
49857
49858 /**
49859 * struct ath_spec_scan - parameters for Atheros spectral scan
49860@@ -706,7 +706,7 @@ struct ath_hw_ops {
49861 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
49862 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
49863 #endif
49864-};
49865+} __no_const;
49866
49867 struct ath_nf_limits {
49868 s16 max;
49869diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
49870index 4b148bb..ac738fa 100644
49871--- a/drivers/net/wireless/ath/ath9k/main.c
49872+++ b/drivers/net/wireless/ath/ath9k/main.c
49873@@ -2592,16 +2592,18 @@ void ath9k_fill_chanctx_ops(void)
49874 if (!ath9k_use_chanctx)
49875 return;
49876
49877- ath9k_ops.hw_scan = ath9k_hw_scan;
49878- ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49879- ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49880- ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49881- ath9k_ops.add_chanctx = ath9k_add_chanctx;
49882- ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49883- ath9k_ops.change_chanctx = ath9k_change_chanctx;
49884- ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49885- ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49886- ath9k_ops.mgd_prepare_tx = ath9k_chanctx_force_active;
49887+ pax_open_kernel();
49888+ *(void **)&ath9k_ops.hw_scan = ath9k_hw_scan;
49889+ *(void **)&ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49890+ *(void **)&ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49891+ *(void **)&ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49892+ *(void **)&ath9k_ops.add_chanctx = ath9k_add_chanctx;
49893+ *(void **)&ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49894+ *(void **)&ath9k_ops.change_chanctx = ath9k_change_chanctx;
49895+ *(void **)&ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49896+ *(void **)&ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49897+ *(void **)&ath9k_ops.mgd_prepare_tx = ath9k_chanctx_force_active;
49898+ pax_close_kernel();
49899 }
49900
49901 struct ieee80211_ops ath9k_ops = {
49902diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
49903index 92190da..f3a4c4c 100644
49904--- a/drivers/net/wireless/b43/phy_lp.c
49905+++ b/drivers/net/wireless/b43/phy_lp.c
49906@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
49907 {
49908 struct ssb_bus *bus = dev->dev->sdev->bus;
49909
49910- static const struct b206x_channel *chandata = NULL;
49911+ const struct b206x_channel *chandata = NULL;
49912 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
49913 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
49914 u16 old_comm15, scale;
49915diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
49916index dc1d20c..f7a4f06 100644
49917--- a/drivers/net/wireless/iwlegacy/3945-mac.c
49918+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
49919@@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
49920 */
49921 if (il3945_mod_params.disable_hw_scan) {
49922 D_INFO("Disabling hw_scan\n");
49923- il3945_mac_ops.hw_scan = NULL;
49924+ pax_open_kernel();
49925+ *(void **)&il3945_mac_ops.hw_scan = NULL;
49926+ pax_close_kernel();
49927 }
49928
49929 D_INFO("*** LOAD DRIVER ***\n");
49930diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49931index 0ffb6ff..c0b7f0e 100644
49932--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49933+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49934@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
49935 {
49936 struct iwl_priv *priv = file->private_data;
49937 char buf[64];
49938- int buf_size;
49939+ size_t buf_size;
49940 u32 offset, len;
49941
49942 memset(buf, 0, sizeof(buf));
49943@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
49944 struct iwl_priv *priv = file->private_data;
49945
49946 char buf[8];
49947- int buf_size;
49948+ size_t buf_size;
49949 u32 reset_flag;
49950
49951 memset(buf, 0, sizeof(buf));
49952@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
49953 {
49954 struct iwl_priv *priv = file->private_data;
49955 char buf[8];
49956- int buf_size;
49957+ size_t buf_size;
49958 int ht40;
49959
49960 memset(buf, 0, sizeof(buf));
49961@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
49962 {
49963 struct iwl_priv *priv = file->private_data;
49964 char buf[8];
49965- int buf_size;
49966+ size_t buf_size;
49967 int value;
49968
49969 memset(buf, 0, sizeof(buf));
49970@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
49971 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
49972 DEBUGFS_READ_FILE_OPS(current_sleep_command);
49973
49974-static const char *fmt_value = " %-30s %10u\n";
49975-static const char *fmt_hex = " %-30s 0x%02X\n";
49976-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
49977-static const char *fmt_header =
49978+static const char fmt_value[] = " %-30s %10u\n";
49979+static const char fmt_hex[] = " %-30s 0x%02X\n";
49980+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
49981+static const char fmt_header[] =
49982 "%-32s current cumulative delta max\n";
49983
49984 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
49985@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
49986 {
49987 struct iwl_priv *priv = file->private_data;
49988 char buf[8];
49989- int buf_size;
49990+ size_t buf_size;
49991 int clear;
49992
49993 memset(buf, 0, sizeof(buf));
49994@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
49995 {
49996 struct iwl_priv *priv = file->private_data;
49997 char buf[8];
49998- int buf_size;
49999+ size_t buf_size;
50000 int trace;
50001
50002 memset(buf, 0, sizeof(buf));
50003@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
50004 {
50005 struct iwl_priv *priv = file->private_data;
50006 char buf[8];
50007- int buf_size;
50008+ size_t buf_size;
50009 int missed;
50010
50011 memset(buf, 0, sizeof(buf));
50012@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
50013
50014 struct iwl_priv *priv = file->private_data;
50015 char buf[8];
50016- int buf_size;
50017+ size_t buf_size;
50018 int plcp;
50019
50020 memset(buf, 0, sizeof(buf));
50021@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
50022
50023 struct iwl_priv *priv = file->private_data;
50024 char buf[8];
50025- int buf_size;
50026+ size_t buf_size;
50027 int flush;
50028
50029 memset(buf, 0, sizeof(buf));
50030@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
50031
50032 struct iwl_priv *priv = file->private_data;
50033 char buf[8];
50034- int buf_size;
50035+ size_t buf_size;
50036 int rts;
50037
50038 if (!priv->cfg->ht_params)
50039@@ -2204,7 +2204,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
50040 {
50041 struct iwl_priv *priv = file->private_data;
50042 char buf[8];
50043- int buf_size;
50044+ size_t buf_size;
50045
50046 memset(buf, 0, sizeof(buf));
50047 buf_size = min(count, sizeof(buf) - 1);
50048@@ -2238,7 +2238,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
50049 struct iwl_priv *priv = file->private_data;
50050 u32 event_log_flag;
50051 char buf[8];
50052- int buf_size;
50053+ size_t buf_size;
50054
50055 /* check that the interface is up */
50056 if (!iwl_is_ready(priv))
50057@@ -2292,7 +2292,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
50058 struct iwl_priv *priv = file->private_data;
50059 char buf[8];
50060 u32 calib_disabled;
50061- int buf_size;
50062+ size_t buf_size;
50063
50064 memset(buf, 0, sizeof(buf));
50065 buf_size = min(count, sizeof(buf) - 1);
50066diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
50067index bb36d67..a43451e 100644
50068--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
50069+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
50070@@ -1686,7 +1686,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
50071 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
50072
50073 char buf[8];
50074- int buf_size;
50075+ size_t buf_size;
50076 u32 reset_flag;
50077
50078 memset(buf, 0, sizeof(buf));
50079@@ -1707,7 +1707,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
50080 {
50081 struct iwl_trans *trans = file->private_data;
50082 char buf[8];
50083- int buf_size;
50084+ size_t buf_size;
50085 int csr;
50086
50087 memset(buf, 0, sizeof(buf));
50088diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
50089index 6b48c865..19646a7 100644
50090--- a/drivers/net/wireless/mac80211_hwsim.c
50091+++ b/drivers/net/wireless/mac80211_hwsim.c
50092@@ -2577,20 +2577,20 @@ static int __init init_mac80211_hwsim(void)
50093 if (channels < 1)
50094 return -EINVAL;
50095
50096- mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
50097- mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
50098- mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
50099- mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
50100- mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
50101- mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
50102- mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
50103- mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
50104- mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
50105- mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
50106- mac80211_hwsim_mchan_ops.assign_vif_chanctx =
50107- mac80211_hwsim_assign_vif_chanctx;
50108- mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
50109- mac80211_hwsim_unassign_vif_chanctx;
50110+ pax_open_kernel();
50111+ memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
50112+ *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
50113+ *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
50114+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
50115+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
50116+ *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
50117+ *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
50118+ *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
50119+ *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
50120+ *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
50121+ *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
50122+ *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
50123+ pax_close_kernel();
50124
50125 spin_lock_init(&hwsim_radio_lock);
50126 INIT_LIST_HEAD(&hwsim_radios);
50127diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
50128index d2a9a08..0cb175d 100644
50129--- a/drivers/net/wireless/rndis_wlan.c
50130+++ b/drivers/net/wireless/rndis_wlan.c
50131@@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
50132
50133 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
50134
50135- if (rts_threshold < 0 || rts_threshold > 2347)
50136+ if (rts_threshold > 2347)
50137 rts_threshold = 2347;
50138
50139 tmp = cpu_to_le32(rts_threshold);
50140diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
50141index d13f25c..2573994 100644
50142--- a/drivers/net/wireless/rt2x00/rt2x00.h
50143+++ b/drivers/net/wireless/rt2x00/rt2x00.h
50144@@ -375,7 +375,7 @@ struct rt2x00_intf {
50145 * for hardware which doesn't support hardware
50146 * sequence counting.
50147 */
50148- atomic_t seqno;
50149+ atomic_unchecked_t seqno;
50150 };
50151
50152 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
50153diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
50154index 66ff364..3ce34f7 100644
50155--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
50156+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
50157@@ -224,9 +224,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
50158 * sequence counter given by mac80211.
50159 */
50160 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
50161- seqno = atomic_add_return(0x10, &intf->seqno);
50162+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
50163 else
50164- seqno = atomic_read(&intf->seqno);
50165+ seqno = atomic_read_unchecked(&intf->seqno);
50166
50167 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
50168 hdr->seq_ctrl |= cpu_to_le16(seqno);
50169diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
50170index b661f896..ddf7d2b 100644
50171--- a/drivers/net/wireless/ti/wl1251/sdio.c
50172+++ b/drivers/net/wireless/ti/wl1251/sdio.c
50173@@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
50174
50175 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
50176
50177- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
50178- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
50179+ pax_open_kernel();
50180+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
50181+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
50182+ pax_close_kernel();
50183
50184 wl1251_info("using dedicated interrupt line");
50185 } else {
50186- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
50187- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
50188+ pax_open_kernel();
50189+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
50190+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
50191+ pax_close_kernel();
50192
50193 wl1251_info("using SDIO interrupt");
50194 }
50195diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
50196index 0bccf12..3d95068 100644
50197--- a/drivers/net/wireless/ti/wl12xx/main.c
50198+++ b/drivers/net/wireless/ti/wl12xx/main.c
50199@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
50200 sizeof(wl->conf.mem));
50201
50202 /* read data preparation is only needed by wl127x */
50203- wl->ops->prepare_read = wl127x_prepare_read;
50204+ pax_open_kernel();
50205+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
50206+ pax_close_kernel();
50207
50208 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
50209 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
50210@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
50211 sizeof(wl->conf.mem));
50212
50213 /* read data preparation is only needed by wl127x */
50214- wl->ops->prepare_read = wl127x_prepare_read;
50215+ pax_open_kernel();
50216+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
50217+ pax_close_kernel();
50218
50219 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
50220 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
50221diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
50222index 7af1936..128bb35 100644
50223--- a/drivers/net/wireless/ti/wl18xx/main.c
50224+++ b/drivers/net/wireless/ti/wl18xx/main.c
50225@@ -1916,8 +1916,10 @@ static int wl18xx_setup(struct wl1271 *wl)
50226 }
50227
50228 if (!checksum_param) {
50229- wl18xx_ops.set_rx_csum = NULL;
50230- wl18xx_ops.init_vif = NULL;
50231+ pax_open_kernel();
50232+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
50233+ *(void **)&wl18xx_ops.init_vif = NULL;
50234+ pax_close_kernel();
50235 }
50236
50237 /* Enable 11a Band only if we have 5G antennas */
50238diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
50239index a912dc0..a8225ba 100644
50240--- a/drivers/net/wireless/zd1211rw/zd_usb.c
50241+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
50242@@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
50243 {
50244 struct zd_usb *usb = urb->context;
50245 struct zd_usb_interrupt *intr = &usb->intr;
50246- int len;
50247+ unsigned int len;
50248 u16 int_num;
50249
50250 ZD_ASSERT(in_interrupt());
50251diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
50252index ca82f54..3767771 100644
50253--- a/drivers/net/xen-netfront.c
50254+++ b/drivers/net/xen-netfront.c
50255@@ -496,9 +496,6 @@ static void xennet_make_frags(struct sk_buff *skb, struct netfront_queue *queue,
50256 len = skb_frag_size(frag);
50257 offset = frag->page_offset;
50258
50259- /* Data must not cross a page boundary. */
50260- BUG_ON(len + offset > PAGE_SIZE<<compound_order(page));
50261-
50262 /* Skip unused frames from start of page */
50263 page += offset >> PAGE_SHIFT;
50264 offset &= ~PAGE_MASK;
50265@@ -506,8 +503,6 @@ static void xennet_make_frags(struct sk_buff *skb, struct netfront_queue *queue,
50266 while (len > 0) {
50267 unsigned long bytes;
50268
50269- BUG_ON(offset >= PAGE_SIZE);
50270-
50271 bytes = PAGE_SIZE - offset;
50272 if (bytes > len)
50273 bytes = len;
50274diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
50275index 683671a..4519fc2 100644
50276--- a/drivers/nfc/nfcwilink.c
50277+++ b/drivers/nfc/nfcwilink.c
50278@@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
50279
50280 static int nfcwilink_probe(struct platform_device *pdev)
50281 {
50282- static struct nfcwilink *drv;
50283+ struct nfcwilink *drv;
50284 int rc;
50285 __u32 protocols;
50286
50287diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
50288index d93b2b6..ae50401 100644
50289--- a/drivers/oprofile/buffer_sync.c
50290+++ b/drivers/oprofile/buffer_sync.c
50291@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
50292 if (cookie == NO_COOKIE)
50293 offset = pc;
50294 if (cookie == INVALID_COOKIE) {
50295- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
50296+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
50297 offset = pc;
50298 }
50299 if (cookie != last_cookie) {
50300@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
50301 /* add userspace sample */
50302
50303 if (!mm) {
50304- atomic_inc(&oprofile_stats.sample_lost_no_mm);
50305+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
50306 return 0;
50307 }
50308
50309 cookie = lookup_dcookie(mm, s->eip, &offset);
50310
50311 if (cookie == INVALID_COOKIE) {
50312- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
50313+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
50314 return 0;
50315 }
50316
50317@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
50318 /* ignore backtraces if failed to add a sample */
50319 if (state == sb_bt_start) {
50320 state = sb_bt_ignore;
50321- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
50322+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
50323 }
50324 }
50325 release_mm(mm);
50326diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
50327index c0cc4e7..44d4e54 100644
50328--- a/drivers/oprofile/event_buffer.c
50329+++ b/drivers/oprofile/event_buffer.c
50330@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
50331 }
50332
50333 if (buffer_pos == buffer_size) {
50334- atomic_inc(&oprofile_stats.event_lost_overflow);
50335+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
50336 return;
50337 }
50338
50339diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
50340index ed2c3ec..deda85a 100644
50341--- a/drivers/oprofile/oprof.c
50342+++ b/drivers/oprofile/oprof.c
50343@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
50344 if (oprofile_ops.switch_events())
50345 return;
50346
50347- atomic_inc(&oprofile_stats.multiplex_counter);
50348+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
50349 start_switch_worker();
50350 }
50351
50352diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
50353index ee2cfce..7f8f699 100644
50354--- a/drivers/oprofile/oprofile_files.c
50355+++ b/drivers/oprofile/oprofile_files.c
50356@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
50357
50358 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
50359
50360-static ssize_t timeout_read(struct file *file, char __user *buf,
50361+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
50362 size_t count, loff_t *offset)
50363 {
50364 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
50365diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
50366index 59659ce..6c860a0 100644
50367--- a/drivers/oprofile/oprofile_stats.c
50368+++ b/drivers/oprofile/oprofile_stats.c
50369@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
50370 cpu_buf->sample_invalid_eip = 0;
50371 }
50372
50373- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
50374- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
50375- atomic_set(&oprofile_stats.event_lost_overflow, 0);
50376- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
50377- atomic_set(&oprofile_stats.multiplex_counter, 0);
50378+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
50379+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
50380+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
50381+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
50382+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
50383 }
50384
50385
50386diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
50387index 1fc622b..8c48fc3 100644
50388--- a/drivers/oprofile/oprofile_stats.h
50389+++ b/drivers/oprofile/oprofile_stats.h
50390@@ -13,11 +13,11 @@
50391 #include <linux/atomic.h>
50392
50393 struct oprofile_stat_struct {
50394- atomic_t sample_lost_no_mm;
50395- atomic_t sample_lost_no_mapping;
50396- atomic_t bt_lost_no_mapping;
50397- atomic_t event_lost_overflow;
50398- atomic_t multiplex_counter;
50399+ atomic_unchecked_t sample_lost_no_mm;
50400+ atomic_unchecked_t sample_lost_no_mapping;
50401+ atomic_unchecked_t bt_lost_no_mapping;
50402+ atomic_unchecked_t event_lost_overflow;
50403+ atomic_unchecked_t multiplex_counter;
50404 };
50405
50406 extern struct oprofile_stat_struct oprofile_stats;
50407diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
50408index 3f49345..c750d0b 100644
50409--- a/drivers/oprofile/oprofilefs.c
50410+++ b/drivers/oprofile/oprofilefs.c
50411@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
50412
50413 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
50414 {
50415- atomic_t *val = file->private_data;
50416- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
50417+ atomic_unchecked_t *val = file->private_data;
50418+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
50419 }
50420
50421
50422@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
50423
50424
50425 int oprofilefs_create_ro_atomic(struct dentry *root,
50426- char const *name, atomic_t *val)
50427+ char const *name, atomic_unchecked_t *val)
50428 {
50429 return __oprofilefs_create_file(root, name,
50430 &atomic_ro_fops, 0444, val);
50431diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
50432index 61be1d9..dec05d7 100644
50433--- a/drivers/oprofile/timer_int.c
50434+++ b/drivers/oprofile/timer_int.c
50435@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
50436 return NOTIFY_OK;
50437 }
50438
50439-static struct notifier_block __refdata oprofile_cpu_notifier = {
50440+static struct notifier_block oprofile_cpu_notifier = {
50441 .notifier_call = oprofile_cpu_notify,
50442 };
50443
50444diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
50445index 3b47080..6cd05dd 100644
50446--- a/drivers/parport/procfs.c
50447+++ b/drivers/parport/procfs.c
50448@@ -64,7 +64,7 @@ static int do_active_device(struct ctl_table *table, int write,
50449
50450 *ppos += len;
50451
50452- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
50453+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
50454 }
50455
50456 #ifdef CONFIG_PARPORT_1284
50457@@ -106,7 +106,7 @@ static int do_autoprobe(struct ctl_table *table, int write,
50458
50459 *ppos += len;
50460
50461- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
50462+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
50463 }
50464 #endif /* IEEE1284.3 support. */
50465
50466diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
50467index 8dcccff..35d701d 100644
50468--- a/drivers/pci/hotplug/acpiphp_ibm.c
50469+++ b/drivers/pci/hotplug/acpiphp_ibm.c
50470@@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
50471 goto init_cleanup;
50472 }
50473
50474- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
50475+ pax_open_kernel();
50476+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
50477+ pax_close_kernel();
50478 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
50479
50480 return retval;
50481diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
50482index 04fcd78..39e83f1 100644
50483--- a/drivers/pci/hotplug/cpcihp_generic.c
50484+++ b/drivers/pci/hotplug/cpcihp_generic.c
50485@@ -73,7 +73,6 @@ static u16 port;
50486 static unsigned int enum_bit;
50487 static u8 enum_mask;
50488
50489-static struct cpci_hp_controller_ops generic_hpc_ops;
50490 static struct cpci_hp_controller generic_hpc;
50491
50492 static int __init validate_parameters(void)
50493@@ -139,6 +138,10 @@ static int query_enum(void)
50494 return ((value & enum_mask) == enum_mask);
50495 }
50496
50497+static struct cpci_hp_controller_ops generic_hpc_ops = {
50498+ .query_enum = query_enum,
50499+};
50500+
50501 static int __init cpcihp_generic_init(void)
50502 {
50503 int status;
50504@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
50505 pci_dev_put(dev);
50506
50507 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
50508- generic_hpc_ops.query_enum = query_enum;
50509 generic_hpc.ops = &generic_hpc_ops;
50510
50511 status = cpci_hp_register_controller(&generic_hpc);
50512diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
50513index 6757b3e..d3bad62 100644
50514--- a/drivers/pci/hotplug/cpcihp_zt5550.c
50515+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
50516@@ -59,7 +59,6 @@
50517 /* local variables */
50518 static bool debug;
50519 static bool poll;
50520-static struct cpci_hp_controller_ops zt5550_hpc_ops;
50521 static struct cpci_hp_controller zt5550_hpc;
50522
50523 /* Primary cPCI bus bridge device */
50524@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
50525 return 0;
50526 }
50527
50528+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
50529+ .query_enum = zt5550_hc_query_enum,
50530+};
50531+
50532 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
50533 {
50534 int status;
50535@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
50536 dbg("returned from zt5550_hc_config");
50537
50538 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
50539- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
50540 zt5550_hpc.ops = &zt5550_hpc_ops;
50541 if(!poll) {
50542 zt5550_hpc.irq = hc_dev->irq;
50543 zt5550_hpc.irq_flags = IRQF_SHARED;
50544 zt5550_hpc.dev_id = hc_dev;
50545
50546- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
50547- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
50548- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
50549+ pax_open_kernel();
50550+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
50551+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
50552+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
50553+ pax_open_kernel();
50554 } else {
50555 info("using ENUM# polling mode");
50556 }
50557diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
50558index 0968a9b..5a00edf 100644
50559--- a/drivers/pci/hotplug/cpqphp_nvram.c
50560+++ b/drivers/pci/hotplug/cpqphp_nvram.c
50561@@ -427,9 +427,13 @@ static u32 store_HRT (void __iomem *rom_start)
50562
50563 void compaq_nvram_init (void __iomem *rom_start)
50564 {
50565+
50566+#ifndef CONFIG_PAX_KERNEXEC
50567 if (rom_start) {
50568 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
50569 }
50570+#endif
50571+
50572 dbg("int15 entry = %p\n", compaq_int15_entry_point);
50573
50574 /* initialize our int15 lock */
50575diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
50576index 56d8486..f26113f 100644
50577--- a/drivers/pci/hotplug/pci_hotplug_core.c
50578+++ b/drivers/pci/hotplug/pci_hotplug_core.c
50579@@ -436,8 +436,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
50580 return -EINVAL;
50581 }
50582
50583- slot->ops->owner = owner;
50584- slot->ops->mod_name = mod_name;
50585+ pax_open_kernel();
50586+ *(struct module **)&slot->ops->owner = owner;
50587+ *(const char **)&slot->ops->mod_name = mod_name;
50588+ pax_close_kernel();
50589
50590 mutex_lock(&pci_hp_mutex);
50591 /*
50592diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
50593index 07aa722..84514b4 100644
50594--- a/drivers/pci/hotplug/pciehp_core.c
50595+++ b/drivers/pci/hotplug/pciehp_core.c
50596@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
50597 struct slot *slot = ctrl->slot;
50598 struct hotplug_slot *hotplug = NULL;
50599 struct hotplug_slot_info *info = NULL;
50600- struct hotplug_slot_ops *ops = NULL;
50601+ hotplug_slot_ops_no_const *ops = NULL;
50602 char name[SLOT_NAME_SIZE];
50603 int retval = -ENOMEM;
50604
50605diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
50606index 6807edd..086a7dc 100644
50607--- a/drivers/pci/msi.c
50608+++ b/drivers/pci/msi.c
50609@@ -507,8 +507,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
50610 {
50611 struct attribute **msi_attrs;
50612 struct attribute *msi_attr;
50613- struct device_attribute *msi_dev_attr;
50614- struct attribute_group *msi_irq_group;
50615+ device_attribute_no_const *msi_dev_attr;
50616+ attribute_group_no_const *msi_irq_group;
50617 const struct attribute_group **msi_irq_groups;
50618 struct msi_desc *entry;
50619 int ret = -ENOMEM;
50620@@ -568,7 +568,7 @@ error_attrs:
50621 count = 0;
50622 msi_attr = msi_attrs[count];
50623 while (msi_attr) {
50624- msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
50625+ msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
50626 kfree(msi_attr->name);
50627 kfree(msi_dev_attr);
50628 ++count;
50629diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
50630index 6d04771..4126004 100644
50631--- a/drivers/pci/pci-sysfs.c
50632+++ b/drivers/pci/pci-sysfs.c
50633@@ -1134,7 +1134,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
50634 {
50635 /* allocate attribute structure, piggyback attribute name */
50636 int name_len = write_combine ? 13 : 10;
50637- struct bin_attribute *res_attr;
50638+ bin_attribute_no_const *res_attr;
50639 int retval;
50640
50641 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
50642@@ -1311,7 +1311,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
50643 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
50644 {
50645 int retval;
50646- struct bin_attribute *attr;
50647+ bin_attribute_no_const *attr;
50648
50649 /* If the device has VPD, try to expose it in sysfs. */
50650 if (dev->vpd) {
50651@@ -1358,7 +1358,7 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
50652 {
50653 int retval;
50654 int rom_size = 0;
50655- struct bin_attribute *attr;
50656+ bin_attribute_no_const *attr;
50657
50658 if (!sysfs_initialized)
50659 return -EACCES;
50660diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
50661index 0601890..dc15007 100644
50662--- a/drivers/pci/pci.h
50663+++ b/drivers/pci/pci.h
50664@@ -91,7 +91,7 @@ struct pci_vpd_ops {
50665 struct pci_vpd {
50666 unsigned int len;
50667 const struct pci_vpd_ops *ops;
50668- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
50669+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
50670 };
50671
50672 int pci_vpd_pci22_init(struct pci_dev *dev);
50673diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
50674index e1e7026..d28dd33 100644
50675--- a/drivers/pci/pcie/aspm.c
50676+++ b/drivers/pci/pcie/aspm.c
50677@@ -27,9 +27,9 @@
50678 #define MODULE_PARAM_PREFIX "pcie_aspm."
50679
50680 /* Note: those are not register definitions */
50681-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
50682-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
50683-#define ASPM_STATE_L1 (4) /* L1 state */
50684+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
50685+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
50686+#define ASPM_STATE_L1 (4U) /* L1 state */
50687 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
50688 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
50689
50690diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
50691index 9cce960..7c530f4 100644
50692--- a/drivers/pci/probe.c
50693+++ b/drivers/pci/probe.c
50694@@ -176,7 +176,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
50695 struct pci_bus_region region, inverted_region;
50696 bool bar_too_big = false, bar_too_high = false, bar_invalid = false;
50697
50698- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
50699+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
50700
50701 /* No printks while decoding is disabled! */
50702 if (!dev->mmio_always_on) {
50703diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
50704index 3f155e7..0f4b1f0 100644
50705--- a/drivers/pci/proc.c
50706+++ b/drivers/pci/proc.c
50707@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
50708 static int __init pci_proc_init(void)
50709 {
50710 struct pci_dev *dev = NULL;
50711+
50712+#ifdef CONFIG_GRKERNSEC_PROC_ADD
50713+#ifdef CONFIG_GRKERNSEC_PROC_USER
50714+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
50715+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50716+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
50717+#endif
50718+#else
50719 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
50720+#endif
50721 proc_create("devices", 0, proc_bus_pci_dir,
50722 &proc_bus_pci_dev_operations);
50723 proc_initialized = 1;
50724diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
50725index d866db8..c827d1f 100644
50726--- a/drivers/platform/chrome/chromeos_laptop.c
50727+++ b/drivers/platform/chrome/chromeos_laptop.c
50728@@ -479,7 +479,7 @@ static struct chromeos_laptop cr48 = {
50729 .callback = chromeos_laptop_dmi_matched, \
50730 .driver_data = (void *)&board_
50731
50732-static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
50733+static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
50734 {
50735 .ident = "Samsung Series 5 550",
50736 .matches = {
50737diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
50738index c5af23b..3d62d5e 100644
50739--- a/drivers/platform/x86/alienware-wmi.c
50740+++ b/drivers/platform/x86/alienware-wmi.c
50741@@ -150,7 +150,7 @@ struct wmax_led_args {
50742 } __packed;
50743
50744 static struct platform_device *platform_device;
50745-static struct device_attribute *zone_dev_attrs;
50746+static device_attribute_no_const *zone_dev_attrs;
50747 static struct attribute **zone_attrs;
50748 static struct platform_zone *zone_data;
50749
50750@@ -161,7 +161,7 @@ static struct platform_driver platform_driver = {
50751 }
50752 };
50753
50754-static struct attribute_group zone_attribute_group = {
50755+static attribute_group_no_const zone_attribute_group = {
50756 .name = "rgb_zones",
50757 };
50758
50759diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
50760index 21fc932..ee9394a 100644
50761--- a/drivers/platform/x86/asus-wmi.c
50762+++ b/drivers/platform/x86/asus-wmi.c
50763@@ -1590,6 +1590,10 @@ static int show_dsts(struct seq_file *m, void *data)
50764 int err;
50765 u32 retval = -1;
50766
50767+#ifdef CONFIG_GRKERNSEC_KMEM
50768+ return -EPERM;
50769+#endif
50770+
50771 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
50772
50773 if (err < 0)
50774@@ -1606,6 +1610,10 @@ static int show_devs(struct seq_file *m, void *data)
50775 int err;
50776 u32 retval = -1;
50777
50778+#ifdef CONFIG_GRKERNSEC_KMEM
50779+ return -EPERM;
50780+#endif
50781+
50782 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
50783 &retval);
50784
50785@@ -1630,6 +1638,10 @@ static int show_call(struct seq_file *m, void *data)
50786 union acpi_object *obj;
50787 acpi_status status;
50788
50789+#ifdef CONFIG_GRKERNSEC_KMEM
50790+ return -EPERM;
50791+#endif
50792+
50793 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
50794 1, asus->debug.method_id,
50795 &input, &output);
50796diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
50797index 62f8030..c7f2a45 100644
50798--- a/drivers/platform/x86/msi-laptop.c
50799+++ b/drivers/platform/x86/msi-laptop.c
50800@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
50801
50802 if (!quirks->ec_read_only) {
50803 /* allow userland write sysfs file */
50804- dev_attr_bluetooth.store = store_bluetooth;
50805- dev_attr_wlan.store = store_wlan;
50806- dev_attr_threeg.store = store_threeg;
50807- dev_attr_bluetooth.attr.mode |= S_IWUSR;
50808- dev_attr_wlan.attr.mode |= S_IWUSR;
50809- dev_attr_threeg.attr.mode |= S_IWUSR;
50810+ pax_open_kernel();
50811+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
50812+ *(void **)&dev_attr_wlan.store = store_wlan;
50813+ *(void **)&dev_attr_threeg.store = store_threeg;
50814+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
50815+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
50816+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
50817+ pax_close_kernel();
50818 }
50819
50820 /* disable hardware control by fn key */
50821diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
50822index 70222f2..8c8ce66 100644
50823--- a/drivers/platform/x86/msi-wmi.c
50824+++ b/drivers/platform/x86/msi-wmi.c
50825@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
50826 static void msi_wmi_notify(u32 value, void *context)
50827 {
50828 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
50829- static struct key_entry *key;
50830+ struct key_entry *key;
50831 union acpi_object *obj;
50832 acpi_status status;
50833
50834diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
50835index 26ad9ff..7c52909 100644
50836--- a/drivers/platform/x86/sony-laptop.c
50837+++ b/drivers/platform/x86/sony-laptop.c
50838@@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
50839 }
50840
50841 /* High speed charging function */
50842-static struct device_attribute *hsc_handle;
50843+static device_attribute_no_const *hsc_handle;
50844
50845 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
50846 struct device_attribute *attr,
50847@@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
50848 }
50849
50850 /* low battery function */
50851-static struct device_attribute *lowbatt_handle;
50852+static device_attribute_no_const *lowbatt_handle;
50853
50854 static ssize_t sony_nc_lowbatt_store(struct device *dev,
50855 struct device_attribute *attr,
50856@@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
50857 }
50858
50859 /* fan speed function */
50860-static struct device_attribute *fan_handle, *hsf_handle;
50861+static device_attribute_no_const *fan_handle, *hsf_handle;
50862
50863 static ssize_t sony_nc_hsfan_store(struct device *dev,
50864 struct device_attribute *attr,
50865@@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
50866 }
50867
50868 /* USB charge function */
50869-static struct device_attribute *uc_handle;
50870+static device_attribute_no_const *uc_handle;
50871
50872 static ssize_t sony_nc_usb_charge_store(struct device *dev,
50873 struct device_attribute *attr,
50874@@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
50875 }
50876
50877 /* Panel ID function */
50878-static struct device_attribute *panel_handle;
50879+static device_attribute_no_const *panel_handle;
50880
50881 static ssize_t sony_nc_panelid_show(struct device *dev,
50882 struct device_attribute *attr, char *buffer)
50883@@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
50884 }
50885
50886 /* smart connect function */
50887-static struct device_attribute *sc_handle;
50888+static device_attribute_no_const *sc_handle;
50889
50890 static ssize_t sony_nc_smart_conn_store(struct device *dev,
50891 struct device_attribute *attr,
50892diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
50893index 3bbc6eb..7760460 100644
50894--- a/drivers/platform/x86/thinkpad_acpi.c
50895+++ b/drivers/platform/x86/thinkpad_acpi.c
50896@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
50897 return 0;
50898 }
50899
50900-void static hotkey_mask_warn_incomplete_mask(void)
50901+static void hotkey_mask_warn_incomplete_mask(void)
50902 {
50903 /* log only what the user can fix... */
50904 const u32 wantedmask = hotkey_driver_mask &
50905@@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
50906 && !tp_features.bright_unkfw)
50907 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
50908 }
50909+}
50910
50911 #undef TPACPI_COMPARE_KEY
50912 #undef TPACPI_MAY_SEND_KEY
50913-}
50914
50915 /*
50916 * Polling driver
50917diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
50918index 438d4c7..ca8a2fb 100644
50919--- a/drivers/pnp/pnpbios/bioscalls.c
50920+++ b/drivers/pnp/pnpbios/bioscalls.c
50921@@ -59,7 +59,7 @@ do { \
50922 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
50923 } while(0)
50924
50925-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
50926+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
50927 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
50928
50929 /*
50930@@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50931
50932 cpu = get_cpu();
50933 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
50934+
50935+ pax_open_kernel();
50936 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
50937+ pax_close_kernel();
50938
50939 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
50940 spin_lock_irqsave(&pnp_bios_lock, flags);
50941@@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50942 :"memory");
50943 spin_unlock_irqrestore(&pnp_bios_lock, flags);
50944
50945+ pax_open_kernel();
50946 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
50947+ pax_close_kernel();
50948+
50949 put_cpu();
50950
50951 /* If we get here and this is set then the PnP BIOS faulted on us. */
50952@@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
50953 return status;
50954 }
50955
50956-void pnpbios_calls_init(union pnp_bios_install_struct *header)
50957+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
50958 {
50959 int i;
50960
50961@@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50962 pnp_bios_callpoint.offset = header->fields.pm16offset;
50963 pnp_bios_callpoint.segment = PNP_CS16;
50964
50965+ pax_open_kernel();
50966+
50967 for_each_possible_cpu(i) {
50968 struct desc_struct *gdt = get_cpu_gdt_table(i);
50969 if (!gdt)
50970@@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50971 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
50972 (unsigned long)__va(header->fields.pm16dseg));
50973 }
50974+
50975+ pax_close_kernel();
50976 }
50977diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
50978index 0c52e2a..3421ab7 100644
50979--- a/drivers/power/pda_power.c
50980+++ b/drivers/power/pda_power.c
50981@@ -37,7 +37,11 @@ static int polling;
50982
50983 #if IS_ENABLED(CONFIG_USB_PHY)
50984 static struct usb_phy *transceiver;
50985-static struct notifier_block otg_nb;
50986+static int otg_handle_notification(struct notifier_block *nb,
50987+ unsigned long event, void *unused);
50988+static struct notifier_block otg_nb = {
50989+ .notifier_call = otg_handle_notification
50990+};
50991 #endif
50992
50993 static struct regulator *ac_draw;
50994@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
50995
50996 #if IS_ENABLED(CONFIG_USB_PHY)
50997 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
50998- otg_nb.notifier_call = otg_handle_notification;
50999 ret = usb_register_notifier(transceiver, &otg_nb);
51000 if (ret) {
51001 dev_err(dev, "failure to register otg notifier\n");
51002diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
51003index cc439fd..8fa30df 100644
51004--- a/drivers/power/power_supply.h
51005+++ b/drivers/power/power_supply.h
51006@@ -16,12 +16,12 @@ struct power_supply;
51007
51008 #ifdef CONFIG_SYSFS
51009
51010-extern void power_supply_init_attrs(struct device_type *dev_type);
51011+extern void power_supply_init_attrs(void);
51012 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
51013
51014 #else
51015
51016-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
51017+static inline void power_supply_init_attrs(void) {}
51018 #define power_supply_uevent NULL
51019
51020 #endif /* CONFIG_SYSFS */
51021diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
51022index 078afd6..fbac9da 100644
51023--- a/drivers/power/power_supply_core.c
51024+++ b/drivers/power/power_supply_core.c
51025@@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
51026 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
51027 EXPORT_SYMBOL_GPL(power_supply_notifier);
51028
51029-static struct device_type power_supply_dev_type;
51030+extern const struct attribute_group *power_supply_attr_groups[];
51031+static struct device_type power_supply_dev_type = {
51032+ .groups = power_supply_attr_groups,
51033+};
51034
51035 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
51036 struct power_supply *supply)
51037@@ -640,7 +643,7 @@ static int __init power_supply_class_init(void)
51038 return PTR_ERR(power_supply_class);
51039
51040 power_supply_class->dev_uevent = power_supply_uevent;
51041- power_supply_init_attrs(&power_supply_dev_type);
51042+ power_supply_init_attrs();
51043
51044 return 0;
51045 }
51046diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
51047index 750a202..99c8f4b 100644
51048--- a/drivers/power/power_supply_sysfs.c
51049+++ b/drivers/power/power_supply_sysfs.c
51050@@ -234,17 +234,15 @@ static struct attribute_group power_supply_attr_group = {
51051 .is_visible = power_supply_attr_is_visible,
51052 };
51053
51054-static const struct attribute_group *power_supply_attr_groups[] = {
51055+const struct attribute_group *power_supply_attr_groups[] = {
51056 &power_supply_attr_group,
51057 NULL,
51058 };
51059
51060-void power_supply_init_attrs(struct device_type *dev_type)
51061+void power_supply_init_attrs(void)
51062 {
51063 int i;
51064
51065- dev_type->groups = power_supply_attr_groups;
51066-
51067 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
51068 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
51069 }
51070diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
51071index 84419af..268ede8 100644
51072--- a/drivers/powercap/powercap_sys.c
51073+++ b/drivers/powercap/powercap_sys.c
51074@@ -154,8 +154,77 @@ struct powercap_constraint_attr {
51075 struct device_attribute name_attr;
51076 };
51077
51078+static ssize_t show_constraint_name(struct device *dev,
51079+ struct device_attribute *dev_attr,
51080+ char *buf);
51081+
51082 static struct powercap_constraint_attr
51083- constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
51084+ constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
51085+ [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
51086+ .power_limit_attr = {
51087+ .attr = {
51088+ .name = NULL,
51089+ .mode = S_IWUSR | S_IRUGO
51090+ },
51091+ .show = show_constraint_power_limit_uw,
51092+ .store = store_constraint_power_limit_uw
51093+ },
51094+
51095+ .time_window_attr = {
51096+ .attr = {
51097+ .name = NULL,
51098+ .mode = S_IWUSR | S_IRUGO
51099+ },
51100+ .show = show_constraint_time_window_us,
51101+ .store = store_constraint_time_window_us
51102+ },
51103+
51104+ .max_power_attr = {
51105+ .attr = {
51106+ .name = NULL,
51107+ .mode = S_IRUGO
51108+ },
51109+ .show = show_constraint_max_power_uw,
51110+ .store = NULL
51111+ },
51112+
51113+ .min_power_attr = {
51114+ .attr = {
51115+ .name = NULL,
51116+ .mode = S_IRUGO
51117+ },
51118+ .show = show_constraint_min_power_uw,
51119+ .store = NULL
51120+ },
51121+
51122+ .max_time_window_attr = {
51123+ .attr = {
51124+ .name = NULL,
51125+ .mode = S_IRUGO
51126+ },
51127+ .show = show_constraint_max_time_window_us,
51128+ .store = NULL
51129+ },
51130+
51131+ .min_time_window_attr = {
51132+ .attr = {
51133+ .name = NULL,
51134+ .mode = S_IRUGO
51135+ },
51136+ .show = show_constraint_min_time_window_us,
51137+ .store = NULL
51138+ },
51139+
51140+ .name_attr = {
51141+ .attr = {
51142+ .name = NULL,
51143+ .mode = S_IRUGO
51144+ },
51145+ .show = show_constraint_name,
51146+ .store = NULL
51147+ }
51148+ }
51149+};
51150
51151 /* A list of powercap control_types */
51152 static LIST_HEAD(powercap_cntrl_list);
51153@@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
51154 }
51155
51156 static int create_constraint_attribute(int id, const char *name,
51157- int mode,
51158- struct device_attribute *dev_attr,
51159- ssize_t (*show)(struct device *,
51160- struct device_attribute *, char *),
51161- ssize_t (*store)(struct device *,
51162- struct device_attribute *,
51163- const char *, size_t)
51164- )
51165+ struct device_attribute *dev_attr)
51166 {
51167+ name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
51168
51169- dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
51170- id, name);
51171- if (!dev_attr->attr.name)
51172+ if (!name)
51173 return -ENOMEM;
51174- dev_attr->attr.mode = mode;
51175- dev_attr->show = show;
51176- dev_attr->store = store;
51177+
51178+ pax_open_kernel();
51179+ *(const char **)&dev_attr->attr.name = name;
51180+ pax_close_kernel();
51181
51182 return 0;
51183 }
51184@@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
51185
51186 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
51187 ret = create_constraint_attribute(i, "power_limit_uw",
51188- S_IWUSR | S_IRUGO,
51189- &constraint_attrs[i].power_limit_attr,
51190- show_constraint_power_limit_uw,
51191- store_constraint_power_limit_uw);
51192+ &constraint_attrs[i].power_limit_attr);
51193 if (ret)
51194 goto err_alloc;
51195 ret = create_constraint_attribute(i, "time_window_us",
51196- S_IWUSR | S_IRUGO,
51197- &constraint_attrs[i].time_window_attr,
51198- show_constraint_time_window_us,
51199- store_constraint_time_window_us);
51200+ &constraint_attrs[i].time_window_attr);
51201 if (ret)
51202 goto err_alloc;
51203- ret = create_constraint_attribute(i, "name", S_IRUGO,
51204- &constraint_attrs[i].name_attr,
51205- show_constraint_name,
51206- NULL);
51207+ ret = create_constraint_attribute(i, "name",
51208+ &constraint_attrs[i].name_attr);
51209 if (ret)
51210 goto err_alloc;
51211- ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
51212- &constraint_attrs[i].max_power_attr,
51213- show_constraint_max_power_uw,
51214- NULL);
51215+ ret = create_constraint_attribute(i, "max_power_uw",
51216+ &constraint_attrs[i].max_power_attr);
51217 if (ret)
51218 goto err_alloc;
51219- ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
51220- &constraint_attrs[i].min_power_attr,
51221- show_constraint_min_power_uw,
51222- NULL);
51223+ ret = create_constraint_attribute(i, "min_power_uw",
51224+ &constraint_attrs[i].min_power_attr);
51225 if (ret)
51226 goto err_alloc;
51227 ret = create_constraint_attribute(i, "max_time_window_us",
51228- S_IRUGO,
51229- &constraint_attrs[i].max_time_window_attr,
51230- show_constraint_max_time_window_us,
51231- NULL);
51232+ &constraint_attrs[i].max_time_window_attr);
51233 if (ret)
51234 goto err_alloc;
51235 ret = create_constraint_attribute(i, "min_time_window_us",
51236- S_IRUGO,
51237- &constraint_attrs[i].min_time_window_attr,
51238- show_constraint_min_time_window_us,
51239- NULL);
51240+ &constraint_attrs[i].min_time_window_attr);
51241 if (ret)
51242 goto err_alloc;
51243
51244@@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
51245 power_zone->zone_dev_attrs[count++] =
51246 &dev_attr_max_energy_range_uj.attr;
51247 if (power_zone->ops->get_energy_uj) {
51248+ pax_open_kernel();
51249 if (power_zone->ops->reset_energy_uj)
51250- dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
51251+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
51252 else
51253- dev_attr_energy_uj.attr.mode = S_IRUGO;
51254+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
51255+ pax_close_kernel();
51256 power_zone->zone_dev_attrs[count++] =
51257 &dev_attr_energy_uj.attr;
51258 }
51259diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
51260index 9c5d414..c7900ce 100644
51261--- a/drivers/ptp/ptp_private.h
51262+++ b/drivers/ptp/ptp_private.h
51263@@ -51,7 +51,7 @@ struct ptp_clock {
51264 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
51265 wait_queue_head_t tsev_wq;
51266 int defunct; /* tells readers to go away when clock is being removed */
51267- struct device_attribute *pin_dev_attr;
51268+ device_attribute_no_const *pin_dev_attr;
51269 struct attribute **pin_attr;
51270 struct attribute_group pin_attr_group;
51271 };
51272diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
51273index 302e626..12579af 100644
51274--- a/drivers/ptp/ptp_sysfs.c
51275+++ b/drivers/ptp/ptp_sysfs.c
51276@@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
51277 goto no_pin_attr;
51278
51279 for (i = 0; i < n_pins; i++) {
51280- struct device_attribute *da = &ptp->pin_dev_attr[i];
51281+ device_attribute_no_const *da = &ptp->pin_dev_attr[i];
51282 sysfs_attr_init(&da->attr);
51283 da->attr.name = info->pin_config[i].name;
51284 da->attr.mode = 0644;
51285diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
51286index a3c3785..c901e3a 100644
51287--- a/drivers/regulator/core.c
51288+++ b/drivers/regulator/core.c
51289@@ -3481,7 +3481,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
51290 {
51291 const struct regulation_constraints *constraints = NULL;
51292 const struct regulator_init_data *init_data;
51293- static atomic_t regulator_no = ATOMIC_INIT(0);
51294+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
51295 struct regulator_dev *rdev;
51296 struct device *dev;
51297 int ret, i;
51298@@ -3551,7 +3551,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
51299 rdev->dev.of_node = of_node_get(config->of_node);
51300 rdev->dev.parent = dev;
51301 dev_set_name(&rdev->dev, "regulator.%d",
51302- atomic_inc_return(&regulator_no) - 1);
51303+ atomic_inc_return_unchecked(&regulator_no) - 1);
51304 ret = device_register(&rdev->dev);
51305 if (ret != 0) {
51306 put_device(&rdev->dev);
51307diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
51308index 2fc4111..6aa88ca 100644
51309--- a/drivers/regulator/max8660.c
51310+++ b/drivers/regulator/max8660.c
51311@@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
51312 max8660->shadow_regs[MAX8660_OVER1] = 5;
51313 } else {
51314 /* Otherwise devices can be toggled via software */
51315- max8660_dcdc_ops.enable = max8660_dcdc_enable;
51316- max8660_dcdc_ops.disable = max8660_dcdc_disable;
51317+ pax_open_kernel();
51318+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
51319+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
51320+ pax_close_kernel();
51321 }
51322
51323 /*
51324diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
51325index dbedf17..18ff6b7 100644
51326--- a/drivers/regulator/max8973-regulator.c
51327+++ b/drivers/regulator/max8973-regulator.c
51328@@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
51329 if (!pdata || !pdata->enable_ext_control) {
51330 max->desc.enable_reg = MAX8973_VOUT;
51331 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
51332- max->ops.enable = regulator_enable_regmap;
51333- max->ops.disable = regulator_disable_regmap;
51334- max->ops.is_enabled = regulator_is_enabled_regmap;
51335+ pax_open_kernel();
51336+ *(void **)&max->ops.enable = regulator_enable_regmap;
51337+ *(void **)&max->ops.disable = regulator_disable_regmap;
51338+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
51339+ pax_close_kernel();
51340 }
51341
51342 if (pdata) {
51343diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
51344index f374fa5..26f0683 100644
51345--- a/drivers/regulator/mc13892-regulator.c
51346+++ b/drivers/regulator/mc13892-regulator.c
51347@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
51348 }
51349 mc13xxx_unlock(mc13892);
51350
51351- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
51352+ pax_open_kernel();
51353+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
51354 = mc13892_vcam_set_mode;
51355- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
51356+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
51357 = mc13892_vcam_get_mode;
51358+ pax_close_kernel();
51359
51360 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
51361 ARRAY_SIZE(mc13892_regulators));
51362diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
51363index 5b2e761..c8c8a4a 100644
51364--- a/drivers/rtc/rtc-cmos.c
51365+++ b/drivers/rtc/rtc-cmos.c
51366@@ -789,7 +789,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
51367 hpet_rtc_timer_init();
51368
51369 /* export at least the first block of NVRAM */
51370- nvram.size = address_space - NVRAM_OFFSET;
51371+ pax_open_kernel();
51372+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
51373+ pax_close_kernel();
51374 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
51375 if (retval < 0) {
51376 dev_dbg(dev, "can't create nvram file? %d\n", retval);
51377diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
51378index d049393..bb20be0 100644
51379--- a/drivers/rtc/rtc-dev.c
51380+++ b/drivers/rtc/rtc-dev.c
51381@@ -16,6 +16,7 @@
51382 #include <linux/module.h>
51383 #include <linux/rtc.h>
51384 #include <linux/sched.h>
51385+#include <linux/grsecurity.h>
51386 #include "rtc-core.h"
51387
51388 static dev_t rtc_devt;
51389@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
51390 if (copy_from_user(&tm, uarg, sizeof(tm)))
51391 return -EFAULT;
51392
51393+ gr_log_timechange();
51394+
51395 return rtc_set_time(rtc, &tm);
51396
51397 case RTC_PIE_ON:
51398diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
51399index f03d5ba..8325bf6 100644
51400--- a/drivers/rtc/rtc-ds1307.c
51401+++ b/drivers/rtc/rtc-ds1307.c
51402@@ -107,7 +107,7 @@ struct ds1307 {
51403 u8 offset; /* register's offset */
51404 u8 regs[11];
51405 u16 nvram_offset;
51406- struct bin_attribute *nvram;
51407+ bin_attribute_no_const *nvram;
51408 enum ds_type type;
51409 unsigned long flags;
51410 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
51411diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
51412index 11880c1..b823aa4 100644
51413--- a/drivers/rtc/rtc-m48t59.c
51414+++ b/drivers/rtc/rtc-m48t59.c
51415@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
51416 if (IS_ERR(m48t59->rtc))
51417 return PTR_ERR(m48t59->rtc);
51418
51419- m48t59_nvram_attr.size = pdata->offset;
51420+ pax_open_kernel();
51421+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
51422+ pax_close_kernel();
51423
51424 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
51425 if (ret)
51426diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
51427index e693af6..2e525b6 100644
51428--- a/drivers/scsi/bfa/bfa_fcpim.h
51429+++ b/drivers/scsi/bfa/bfa_fcpim.h
51430@@ -36,7 +36,7 @@ struct bfa_iotag_s {
51431
51432 struct bfa_itn_s {
51433 bfa_isr_func_t isr;
51434-};
51435+} __no_const;
51436
51437 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
51438 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
51439diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
51440index 0f19455..ef7adb5 100644
51441--- a/drivers/scsi/bfa/bfa_fcs.c
51442+++ b/drivers/scsi/bfa/bfa_fcs.c
51443@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
51444 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
51445
51446 static struct bfa_fcs_mod_s fcs_modules[] = {
51447- { bfa_fcs_port_attach, NULL, NULL },
51448- { bfa_fcs_uf_attach, NULL, NULL },
51449- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
51450- bfa_fcs_fabric_modexit },
51451+ {
51452+ .attach = bfa_fcs_port_attach,
51453+ .modinit = NULL,
51454+ .modexit = NULL
51455+ },
51456+ {
51457+ .attach = bfa_fcs_uf_attach,
51458+ .modinit = NULL,
51459+ .modexit = NULL
51460+ },
51461+ {
51462+ .attach = bfa_fcs_fabric_attach,
51463+ .modinit = bfa_fcs_fabric_modinit,
51464+ .modexit = bfa_fcs_fabric_modexit
51465+ },
51466 };
51467
51468 /*
51469diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
51470index ff75ef8..2dfe00a 100644
51471--- a/drivers/scsi/bfa/bfa_fcs_lport.c
51472+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
51473@@ -89,15 +89,26 @@ static struct {
51474 void (*offline) (struct bfa_fcs_lport_s *port);
51475 } __port_action[] = {
51476 {
51477- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
51478- bfa_fcs_lport_unknown_offline}, {
51479- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
51480- bfa_fcs_lport_fab_offline}, {
51481- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
51482- bfa_fcs_lport_n2n_offline}, {
51483- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
51484- bfa_fcs_lport_loop_offline},
51485- };
51486+ .init = bfa_fcs_lport_unknown_init,
51487+ .online = bfa_fcs_lport_unknown_online,
51488+ .offline = bfa_fcs_lport_unknown_offline
51489+ },
51490+ {
51491+ .init = bfa_fcs_lport_fab_init,
51492+ .online = bfa_fcs_lport_fab_online,
51493+ .offline = bfa_fcs_lport_fab_offline
51494+ },
51495+ {
51496+ .init = bfa_fcs_lport_n2n_init,
51497+ .online = bfa_fcs_lport_n2n_online,
51498+ .offline = bfa_fcs_lport_n2n_offline
51499+ },
51500+ {
51501+ .init = bfa_fcs_lport_loop_init,
51502+ .online = bfa_fcs_lport_loop_online,
51503+ .offline = bfa_fcs_lport_loop_offline
51504+ },
51505+};
51506
51507 /*
51508 * fcs_port_sm FCS logical port state machine
51509diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
51510index a38aafa0..fe8f03b 100644
51511--- a/drivers/scsi/bfa/bfa_ioc.h
51512+++ b/drivers/scsi/bfa/bfa_ioc.h
51513@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
51514 bfa_ioc_disable_cbfn_t disable_cbfn;
51515 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
51516 bfa_ioc_reset_cbfn_t reset_cbfn;
51517-};
51518+} __no_const;
51519
51520 /*
51521 * IOC event notification mechanism.
51522@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
51523 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
51524 enum bfi_ioc_state fwstate);
51525 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
51526-};
51527+} __no_const;
51528
51529 /*
51530 * Queue element to wait for room in request queue. FIFO order is
51531diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
51532index a14c784..6de6790 100644
51533--- a/drivers/scsi/bfa/bfa_modules.h
51534+++ b/drivers/scsi/bfa/bfa_modules.h
51535@@ -78,12 +78,12 @@ enum {
51536 \
51537 extern struct bfa_module_s hal_mod_ ## __mod; \
51538 struct bfa_module_s hal_mod_ ## __mod = { \
51539- bfa_ ## __mod ## _meminfo, \
51540- bfa_ ## __mod ## _attach, \
51541- bfa_ ## __mod ## _detach, \
51542- bfa_ ## __mod ## _start, \
51543- bfa_ ## __mod ## _stop, \
51544- bfa_ ## __mod ## _iocdisable, \
51545+ .meminfo = bfa_ ## __mod ## _meminfo, \
51546+ .attach = bfa_ ## __mod ## _attach, \
51547+ .detach = bfa_ ## __mod ## _detach, \
51548+ .start = bfa_ ## __mod ## _start, \
51549+ .stop = bfa_ ## __mod ## _stop, \
51550+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
51551 }
51552
51553 #define BFA_CACHELINE_SZ (256)
51554diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
51555index 045c4e1..13de803 100644
51556--- a/drivers/scsi/fcoe/fcoe_sysfs.c
51557+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
51558@@ -33,8 +33,8 @@
51559 */
51560 #include "libfcoe.h"
51561
51562-static atomic_t ctlr_num;
51563-static atomic_t fcf_num;
51564+static atomic_unchecked_t ctlr_num;
51565+static atomic_unchecked_t fcf_num;
51566
51567 /*
51568 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
51569@@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
51570 if (!ctlr)
51571 goto out;
51572
51573- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
51574+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
51575 ctlr->f = f;
51576 ctlr->mode = FIP_CONN_TYPE_FABRIC;
51577 INIT_LIST_HEAD(&ctlr->fcfs);
51578@@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
51579 fcf->dev.parent = &ctlr->dev;
51580 fcf->dev.bus = &fcoe_bus_type;
51581 fcf->dev.type = &fcoe_fcf_device_type;
51582- fcf->id = atomic_inc_return(&fcf_num) - 1;
51583+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
51584 fcf->state = FCOE_FCF_STATE_UNKNOWN;
51585
51586 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
51587@@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
51588 {
51589 int error;
51590
51591- atomic_set(&ctlr_num, 0);
51592- atomic_set(&fcf_num, 0);
51593+ atomic_set_unchecked(&ctlr_num, 0);
51594+ atomic_set_unchecked(&fcf_num, 0);
51595
51596 error = bus_register(&fcoe_bus_type);
51597 if (error)
51598diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
51599index 6de80e3..a11e0ac 100644
51600--- a/drivers/scsi/hosts.c
51601+++ b/drivers/scsi/hosts.c
51602@@ -42,7 +42,7 @@
51603 #include "scsi_logging.h"
51604
51605
51606-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
51607+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
51608
51609
51610 static void scsi_host_cls_release(struct device *dev)
51611@@ -392,7 +392,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
51612 * subtract one because we increment first then return, but we need to
51613 * know what the next host number was before increment
51614 */
51615- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
51616+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
51617 shost->dma_channel = 0xff;
51618
51619 /* These three are default values which can be overridden */
51620diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
51621index 6b35d0d..2880305 100644
51622--- a/drivers/scsi/hpsa.c
51623+++ b/drivers/scsi/hpsa.c
51624@@ -701,10 +701,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
51625 unsigned long flags;
51626
51627 if (h->transMethod & CFGTBL_Trans_io_accel1)
51628- return h->access.command_completed(h, q);
51629+ return h->access->command_completed(h, q);
51630
51631 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
51632- return h->access.command_completed(h, q);
51633+ return h->access->command_completed(h, q);
51634
51635 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
51636 a = rq->head[rq->current_entry];
51637@@ -5454,7 +5454,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
51638 while (!list_empty(&h->reqQ)) {
51639 c = list_entry(h->reqQ.next, struct CommandList, list);
51640 /* can't do anything if fifo is full */
51641- if ((h->access.fifo_full(h))) {
51642+ if ((h->access->fifo_full(h))) {
51643 h->fifo_recently_full = 1;
51644 dev_warn(&h->pdev->dev, "fifo full\n");
51645 break;
51646@@ -5476,7 +5476,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
51647
51648 /* Tell the controller execute command */
51649 spin_unlock_irqrestore(&h->lock, *flags);
51650- h->access.submit_command(h, c);
51651+ h->access->submit_command(h, c);
51652 spin_lock_irqsave(&h->lock, *flags);
51653 }
51654 }
51655@@ -5492,17 +5492,17 @@ static void lock_and_start_io(struct ctlr_info *h)
51656
51657 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
51658 {
51659- return h->access.command_completed(h, q);
51660+ return h->access->command_completed(h, q);
51661 }
51662
51663 static inline bool interrupt_pending(struct ctlr_info *h)
51664 {
51665- return h->access.intr_pending(h);
51666+ return h->access->intr_pending(h);
51667 }
51668
51669 static inline long interrupt_not_for_us(struct ctlr_info *h)
51670 {
51671- return (h->access.intr_pending(h) == 0) ||
51672+ return (h->access->intr_pending(h) == 0) ||
51673 (h->interrupts_enabled == 0);
51674 }
51675
51676@@ -6458,7 +6458,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
51677 if (prod_index < 0)
51678 return -ENODEV;
51679 h->product_name = products[prod_index].product_name;
51680- h->access = *(products[prod_index].access);
51681+ h->access = products[prod_index].access;
51682
51683 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
51684 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
51685@@ -6780,7 +6780,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
51686 unsigned long flags;
51687 u32 lockup_detected;
51688
51689- h->access.set_intr_mask(h, HPSA_INTR_OFF);
51690+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
51691 spin_lock_irqsave(&h->lock, flags);
51692 lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
51693 if (!lockup_detected) {
51694@@ -7027,7 +7027,7 @@ reinit_after_soft_reset:
51695 }
51696
51697 /* make sure the board interrupts are off */
51698- h->access.set_intr_mask(h, HPSA_INTR_OFF);
51699+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
51700
51701 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
51702 goto clean2;
51703@@ -7062,7 +7062,7 @@ reinit_after_soft_reset:
51704 * fake ones to scoop up any residual completions.
51705 */
51706 spin_lock_irqsave(&h->lock, flags);
51707- h->access.set_intr_mask(h, HPSA_INTR_OFF);
51708+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
51709 spin_unlock_irqrestore(&h->lock, flags);
51710 free_irqs(h);
51711 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
51712@@ -7081,9 +7081,9 @@ reinit_after_soft_reset:
51713 dev_info(&h->pdev->dev, "Board READY.\n");
51714 dev_info(&h->pdev->dev,
51715 "Waiting for stale completions to drain.\n");
51716- h->access.set_intr_mask(h, HPSA_INTR_ON);
51717+ h->access->set_intr_mask(h, HPSA_INTR_ON);
51718 msleep(10000);
51719- h->access.set_intr_mask(h, HPSA_INTR_OFF);
51720+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
51721
51722 rc = controller_reset_failed(h->cfgtable);
51723 if (rc)
51724@@ -7109,7 +7109,7 @@ reinit_after_soft_reset:
51725 h->drv_req_rescan = 0;
51726
51727 /* Turn the interrupts on so we can service requests */
51728- h->access.set_intr_mask(h, HPSA_INTR_ON);
51729+ h->access->set_intr_mask(h, HPSA_INTR_ON);
51730
51731 hpsa_hba_inquiry(h);
51732 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
51733@@ -7174,7 +7174,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
51734 * To write all data in the battery backed cache to disks
51735 */
51736 hpsa_flush_cache(h);
51737- h->access.set_intr_mask(h, HPSA_INTR_OFF);
51738+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
51739 hpsa_free_irqs_and_disable_msix(h);
51740 }
51741
51742@@ -7292,7 +7292,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51743 CFGTBL_Trans_enable_directed_msix |
51744 (trans_support & (CFGTBL_Trans_io_accel1 |
51745 CFGTBL_Trans_io_accel2));
51746- struct access_method access = SA5_performant_access;
51747+ struct access_method *access = &SA5_performant_access;
51748
51749 /* This is a bit complicated. There are 8 registers on
51750 * the controller which we write to to tell it 8 different
51751@@ -7334,7 +7334,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51752 * perform the superfluous readl() after each command submission.
51753 */
51754 if (trans_support & (CFGTBL_Trans_io_accel1 | CFGTBL_Trans_io_accel2))
51755- access = SA5_performant_access_no_read;
51756+ access = &SA5_performant_access_no_read;
51757
51758 /* Controller spec: zero out this buffer. */
51759 for (i = 0; i < h->nreply_queues; i++)
51760@@ -7364,12 +7364,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51761 * enable outbound interrupt coalescing in accelerator mode;
51762 */
51763 if (trans_support & CFGTBL_Trans_io_accel1) {
51764- access = SA5_ioaccel_mode1_access;
51765+ access = &SA5_ioaccel_mode1_access;
51766 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51767 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51768 } else {
51769 if (trans_support & CFGTBL_Trans_io_accel2) {
51770- access = SA5_ioaccel_mode2_access;
51771+ access = &SA5_ioaccel_mode2_access;
51772 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51773 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51774 }
51775diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
51776index 24472ce..8782caf 100644
51777--- a/drivers/scsi/hpsa.h
51778+++ b/drivers/scsi/hpsa.h
51779@@ -127,7 +127,7 @@ struct ctlr_info {
51780 unsigned int msix_vector;
51781 unsigned int msi_vector;
51782 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
51783- struct access_method access;
51784+ struct access_method *access;
51785 char hba_mode_enabled;
51786
51787 /* queue and queue Info */
51788@@ -536,43 +536,43 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
51789 }
51790
51791 static struct access_method SA5_access = {
51792- SA5_submit_command,
51793- SA5_intr_mask,
51794- SA5_fifo_full,
51795- SA5_intr_pending,
51796- SA5_completed,
51797+ .submit_command = SA5_submit_command,
51798+ .set_intr_mask = SA5_intr_mask,
51799+ .fifo_full = SA5_fifo_full,
51800+ .intr_pending = SA5_intr_pending,
51801+ .command_completed = SA5_completed,
51802 };
51803
51804 static struct access_method SA5_ioaccel_mode1_access = {
51805- SA5_submit_command,
51806- SA5_performant_intr_mask,
51807- SA5_fifo_full,
51808- SA5_ioaccel_mode1_intr_pending,
51809- SA5_ioaccel_mode1_completed,
51810+ .submit_command = SA5_submit_command,
51811+ .set_intr_mask = SA5_performant_intr_mask,
51812+ .fifo_full = SA5_fifo_full,
51813+ .intr_pending = SA5_ioaccel_mode1_intr_pending,
51814+ .command_completed = SA5_ioaccel_mode1_completed,
51815 };
51816
51817 static struct access_method SA5_ioaccel_mode2_access = {
51818- SA5_submit_command_ioaccel2,
51819- SA5_performant_intr_mask,
51820- SA5_fifo_full,
51821- SA5_performant_intr_pending,
51822- SA5_performant_completed,
51823+ .submit_command = SA5_submit_command_ioaccel2,
51824+ .set_intr_mask = SA5_performant_intr_mask,
51825+ .fifo_full = SA5_fifo_full,
51826+ .intr_pending = SA5_performant_intr_pending,
51827+ .command_completed = SA5_performant_completed,
51828 };
51829
51830 static struct access_method SA5_performant_access = {
51831- SA5_submit_command,
51832- SA5_performant_intr_mask,
51833- SA5_fifo_full,
51834- SA5_performant_intr_pending,
51835- SA5_performant_completed,
51836+ .submit_command = SA5_submit_command,
51837+ .set_intr_mask = SA5_performant_intr_mask,
51838+ .fifo_full = SA5_fifo_full,
51839+ .intr_pending = SA5_performant_intr_pending,
51840+ .command_completed = SA5_performant_completed,
51841 };
51842
51843 static struct access_method SA5_performant_access_no_read = {
51844- SA5_submit_command_no_read,
51845- SA5_performant_intr_mask,
51846- SA5_fifo_full,
51847- SA5_performant_intr_pending,
51848- SA5_performant_completed,
51849+ .submit_command = SA5_submit_command_no_read,
51850+ .set_intr_mask = SA5_performant_intr_mask,
51851+ .fifo_full = SA5_fifo_full,
51852+ .intr_pending = SA5_performant_intr_pending,
51853+ .command_completed = SA5_performant_completed,
51854 };
51855
51856 struct board_type {
51857diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
51858index 1b3a094..068e683 100644
51859--- a/drivers/scsi/libfc/fc_exch.c
51860+++ b/drivers/scsi/libfc/fc_exch.c
51861@@ -101,12 +101,12 @@ struct fc_exch_mgr {
51862 u16 pool_max_index;
51863
51864 struct {
51865- atomic_t no_free_exch;
51866- atomic_t no_free_exch_xid;
51867- atomic_t xid_not_found;
51868- atomic_t xid_busy;
51869- atomic_t seq_not_found;
51870- atomic_t non_bls_resp;
51871+ atomic_unchecked_t no_free_exch;
51872+ atomic_unchecked_t no_free_exch_xid;
51873+ atomic_unchecked_t xid_not_found;
51874+ atomic_unchecked_t xid_busy;
51875+ atomic_unchecked_t seq_not_found;
51876+ atomic_unchecked_t non_bls_resp;
51877 } stats;
51878 };
51879
51880@@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
51881 /* allocate memory for exchange */
51882 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
51883 if (!ep) {
51884- atomic_inc(&mp->stats.no_free_exch);
51885+ atomic_inc_unchecked(&mp->stats.no_free_exch);
51886 goto out;
51887 }
51888 memset(ep, 0, sizeof(*ep));
51889@@ -874,7 +874,7 @@ out:
51890 return ep;
51891 err:
51892 spin_unlock_bh(&pool->lock);
51893- atomic_inc(&mp->stats.no_free_exch_xid);
51894+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
51895 mempool_free(ep, mp->ep_pool);
51896 return NULL;
51897 }
51898@@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51899 xid = ntohs(fh->fh_ox_id); /* we originated exch */
51900 ep = fc_exch_find(mp, xid);
51901 if (!ep) {
51902- atomic_inc(&mp->stats.xid_not_found);
51903+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51904 reject = FC_RJT_OX_ID;
51905 goto out;
51906 }
51907@@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51908 ep = fc_exch_find(mp, xid);
51909 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
51910 if (ep) {
51911- atomic_inc(&mp->stats.xid_busy);
51912+ atomic_inc_unchecked(&mp->stats.xid_busy);
51913 reject = FC_RJT_RX_ID;
51914 goto rel;
51915 }
51916@@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51917 }
51918 xid = ep->xid; /* get our XID */
51919 } else if (!ep) {
51920- atomic_inc(&mp->stats.xid_not_found);
51921+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51922 reject = FC_RJT_RX_ID; /* XID not found */
51923 goto out;
51924 }
51925@@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51926 } else {
51927 sp = &ep->seq;
51928 if (sp->id != fh->fh_seq_id) {
51929- atomic_inc(&mp->stats.seq_not_found);
51930+ atomic_inc_unchecked(&mp->stats.seq_not_found);
51931 if (f_ctl & FC_FC_END_SEQ) {
51932 /*
51933 * Update sequence_id based on incoming last
51934@@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51935
51936 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
51937 if (!ep) {
51938- atomic_inc(&mp->stats.xid_not_found);
51939+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51940 goto out;
51941 }
51942 if (ep->esb_stat & ESB_ST_COMPLETE) {
51943- atomic_inc(&mp->stats.xid_not_found);
51944+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51945 goto rel;
51946 }
51947 if (ep->rxid == FC_XID_UNKNOWN)
51948 ep->rxid = ntohs(fh->fh_rx_id);
51949 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
51950- atomic_inc(&mp->stats.xid_not_found);
51951+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51952 goto rel;
51953 }
51954 if (ep->did != ntoh24(fh->fh_s_id) &&
51955 ep->did != FC_FID_FLOGI) {
51956- atomic_inc(&mp->stats.xid_not_found);
51957+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51958 goto rel;
51959 }
51960 sof = fr_sof(fp);
51961@@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51962 sp->ssb_stat |= SSB_ST_RESP;
51963 sp->id = fh->fh_seq_id;
51964 } else if (sp->id != fh->fh_seq_id) {
51965- atomic_inc(&mp->stats.seq_not_found);
51966+ atomic_inc_unchecked(&mp->stats.seq_not_found);
51967 goto rel;
51968 }
51969
51970@@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51971 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
51972
51973 if (!sp)
51974- atomic_inc(&mp->stats.xid_not_found);
51975+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51976 else
51977- atomic_inc(&mp->stats.non_bls_resp);
51978+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
51979
51980 fc_frame_free(fp);
51981 }
51982@@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
51983
51984 list_for_each_entry(ema, &lport->ema_list, ema_list) {
51985 mp = ema->mp;
51986- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
51987+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
51988 st->fc_no_free_exch_xid +=
51989- atomic_read(&mp->stats.no_free_exch_xid);
51990- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
51991- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
51992- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
51993- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
51994+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
51995+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
51996+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
51997+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
51998+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
51999 }
52000 }
52001 EXPORT_SYMBOL(fc_exch_update_stats);
52002diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
52003index 766098a..1c6c971 100644
52004--- a/drivers/scsi/libsas/sas_ata.c
52005+++ b/drivers/scsi/libsas/sas_ata.c
52006@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
52007 .postreset = ata_std_postreset,
52008 .error_handler = ata_std_error_handler,
52009 .post_internal_cmd = sas_ata_post_internal,
52010- .qc_defer = ata_std_qc_defer,
52011+ .qc_defer = ata_std_qc_defer,
52012 .qc_prep = ata_noop_qc_prep,
52013 .qc_issue = sas_ata_qc_issue,
52014 .qc_fill_rtf = sas_ata_qc_fill_rtf,
52015diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
52016index 434e903..5a4a79b 100644
52017--- a/drivers/scsi/lpfc/lpfc.h
52018+++ b/drivers/scsi/lpfc/lpfc.h
52019@@ -430,7 +430,7 @@ struct lpfc_vport {
52020 struct dentry *debug_nodelist;
52021 struct dentry *vport_debugfs_root;
52022 struct lpfc_debugfs_trc *disc_trc;
52023- atomic_t disc_trc_cnt;
52024+ atomic_unchecked_t disc_trc_cnt;
52025 #endif
52026 uint8_t stat_data_enabled;
52027 uint8_t stat_data_blocked;
52028@@ -880,8 +880,8 @@ struct lpfc_hba {
52029 struct timer_list fabric_block_timer;
52030 unsigned long bit_flags;
52031 #define FABRIC_COMANDS_BLOCKED 0
52032- atomic_t num_rsrc_err;
52033- atomic_t num_cmd_success;
52034+ atomic_unchecked_t num_rsrc_err;
52035+ atomic_unchecked_t num_cmd_success;
52036 unsigned long last_rsrc_error_time;
52037 unsigned long last_ramp_down_time;
52038 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
52039@@ -916,7 +916,7 @@ struct lpfc_hba {
52040
52041 struct dentry *debug_slow_ring_trc;
52042 struct lpfc_debugfs_trc *slow_ring_trc;
52043- atomic_t slow_ring_trc_cnt;
52044+ atomic_unchecked_t slow_ring_trc_cnt;
52045 /* iDiag debugfs sub-directory */
52046 struct dentry *idiag_root;
52047 struct dentry *idiag_pci_cfg;
52048diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
52049index b0aedce..89c6ca6 100644
52050--- a/drivers/scsi/lpfc/lpfc_debugfs.c
52051+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
52052@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
52053
52054 #include <linux/debugfs.h>
52055
52056-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
52057+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
52058 static unsigned long lpfc_debugfs_start_time = 0L;
52059
52060 /* iDiag */
52061@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
52062 lpfc_debugfs_enable = 0;
52063
52064 len = 0;
52065- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
52066+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
52067 (lpfc_debugfs_max_disc_trc - 1);
52068 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
52069 dtp = vport->disc_trc + i;
52070@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
52071 lpfc_debugfs_enable = 0;
52072
52073 len = 0;
52074- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
52075+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
52076 (lpfc_debugfs_max_slow_ring_trc - 1);
52077 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
52078 dtp = phba->slow_ring_trc + i;
52079@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
52080 !vport || !vport->disc_trc)
52081 return;
52082
52083- index = atomic_inc_return(&vport->disc_trc_cnt) &
52084+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
52085 (lpfc_debugfs_max_disc_trc - 1);
52086 dtp = vport->disc_trc + index;
52087 dtp->fmt = fmt;
52088 dtp->data1 = data1;
52089 dtp->data2 = data2;
52090 dtp->data3 = data3;
52091- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
52092+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
52093 dtp->jif = jiffies;
52094 #endif
52095 return;
52096@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
52097 !phba || !phba->slow_ring_trc)
52098 return;
52099
52100- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
52101+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
52102 (lpfc_debugfs_max_slow_ring_trc - 1);
52103 dtp = phba->slow_ring_trc + index;
52104 dtp->fmt = fmt;
52105 dtp->data1 = data1;
52106 dtp->data2 = data2;
52107 dtp->data3 = data3;
52108- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
52109+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
52110 dtp->jif = jiffies;
52111 #endif
52112 return;
52113@@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
52114 "slow_ring buffer\n");
52115 goto debug_failed;
52116 }
52117- atomic_set(&phba->slow_ring_trc_cnt, 0);
52118+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
52119 memset(phba->slow_ring_trc, 0,
52120 (sizeof(struct lpfc_debugfs_trc) *
52121 lpfc_debugfs_max_slow_ring_trc));
52122@@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
52123 "buffer\n");
52124 goto debug_failed;
52125 }
52126- atomic_set(&vport->disc_trc_cnt, 0);
52127+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
52128
52129 snprintf(name, sizeof(name), "discovery_trace");
52130 vport->debug_disc_trc =
52131diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
52132index a5769a9..718ecc7 100644
52133--- a/drivers/scsi/lpfc/lpfc_init.c
52134+++ b/drivers/scsi/lpfc/lpfc_init.c
52135@@ -11299,8 +11299,10 @@ lpfc_init(void)
52136 "misc_register returned with status %d", error);
52137
52138 if (lpfc_enable_npiv) {
52139- lpfc_transport_functions.vport_create = lpfc_vport_create;
52140- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
52141+ pax_open_kernel();
52142+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
52143+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
52144+ pax_close_kernel();
52145 }
52146 lpfc_transport_template =
52147 fc_attach_transport(&lpfc_transport_functions);
52148diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
52149index 7862c55..5aa65df 100644
52150--- a/drivers/scsi/lpfc/lpfc_scsi.c
52151+++ b/drivers/scsi/lpfc/lpfc_scsi.c
52152@@ -382,7 +382,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
52153 uint32_t evt_posted;
52154
52155 spin_lock_irqsave(&phba->hbalock, flags);
52156- atomic_inc(&phba->num_rsrc_err);
52157+ atomic_inc_unchecked(&phba->num_rsrc_err);
52158 phba->last_rsrc_error_time = jiffies;
52159
52160 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
52161@@ -423,8 +423,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
52162 unsigned long num_rsrc_err, num_cmd_success;
52163 int i;
52164
52165- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
52166- num_cmd_success = atomic_read(&phba->num_cmd_success);
52167+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
52168+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
52169
52170 /*
52171 * The error and success command counters are global per
52172@@ -452,8 +452,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
52173 }
52174 }
52175 lpfc_destroy_vport_work_array(phba, vports);
52176- atomic_set(&phba->num_rsrc_err, 0);
52177- atomic_set(&phba->num_cmd_success, 0);
52178+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
52179+ atomic_set_unchecked(&phba->num_cmd_success, 0);
52180 }
52181
52182 /**
52183diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
52184index dd46101..ca80eb9 100644
52185--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
52186+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
52187@@ -1559,7 +1559,7 @@ _scsih_get_resync(struct device *dev)
52188 {
52189 struct scsi_device *sdev = to_scsi_device(dev);
52190 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
52191- static struct _raid_device *raid_device;
52192+ struct _raid_device *raid_device;
52193 unsigned long flags;
52194 Mpi2RaidVolPage0_t vol_pg0;
52195 Mpi2ConfigReply_t mpi_reply;
52196@@ -1611,7 +1611,7 @@ _scsih_get_state(struct device *dev)
52197 {
52198 struct scsi_device *sdev = to_scsi_device(dev);
52199 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
52200- static struct _raid_device *raid_device;
52201+ struct _raid_device *raid_device;
52202 unsigned long flags;
52203 Mpi2RaidVolPage0_t vol_pg0;
52204 Mpi2ConfigReply_t mpi_reply;
52205@@ -6648,7 +6648,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
52206 Mpi2EventDataIrOperationStatus_t *event_data =
52207 (Mpi2EventDataIrOperationStatus_t *)
52208 fw_event->event_data;
52209- static struct _raid_device *raid_device;
52210+ struct _raid_device *raid_device;
52211 unsigned long flags;
52212 u16 handle;
52213
52214@@ -7119,7 +7119,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
52215 u64 sas_address;
52216 struct _sas_device *sas_device;
52217 struct _sas_node *expander_device;
52218- static struct _raid_device *raid_device;
52219+ struct _raid_device *raid_device;
52220 u8 retry_count;
52221 unsigned long flags;
52222
52223diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
52224index 6f3275d..fa5e6b6 100644
52225--- a/drivers/scsi/pmcraid.c
52226+++ b/drivers/scsi/pmcraid.c
52227@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
52228 res->scsi_dev = scsi_dev;
52229 scsi_dev->hostdata = res;
52230 res->change_detected = 0;
52231- atomic_set(&res->read_failures, 0);
52232- atomic_set(&res->write_failures, 0);
52233+ atomic_set_unchecked(&res->read_failures, 0);
52234+ atomic_set_unchecked(&res->write_failures, 0);
52235 rc = 0;
52236 }
52237 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
52238@@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
52239
52240 /* If this was a SCSI read/write command keep count of errors */
52241 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
52242- atomic_inc(&res->read_failures);
52243+ atomic_inc_unchecked(&res->read_failures);
52244 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
52245- atomic_inc(&res->write_failures);
52246+ atomic_inc_unchecked(&res->write_failures);
52247
52248 if (!RES_IS_GSCSI(res->cfg_entry) &&
52249 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
52250@@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
52251 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
52252 * hrrq_id assigned here in queuecommand
52253 */
52254- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
52255+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
52256 pinstance->num_hrrq;
52257 cmd->cmd_done = pmcraid_io_done;
52258
52259@@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
52260 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
52261 * hrrq_id assigned here in queuecommand
52262 */
52263- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
52264+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
52265 pinstance->num_hrrq;
52266
52267 if (request_size) {
52268@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
52269
52270 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
52271 /* add resources only after host is added into system */
52272- if (!atomic_read(&pinstance->expose_resources))
52273+ if (!atomic_read_unchecked(&pinstance->expose_resources))
52274 return;
52275
52276 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
52277@@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
52278 init_waitqueue_head(&pinstance->reset_wait_q);
52279
52280 atomic_set(&pinstance->outstanding_cmds, 0);
52281- atomic_set(&pinstance->last_message_id, 0);
52282- atomic_set(&pinstance->expose_resources, 0);
52283+ atomic_set_unchecked(&pinstance->last_message_id, 0);
52284+ atomic_set_unchecked(&pinstance->expose_resources, 0);
52285
52286 INIT_LIST_HEAD(&pinstance->free_res_q);
52287 INIT_LIST_HEAD(&pinstance->used_res_q);
52288@@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
52289 /* Schedule worker thread to handle CCN and take care of adding and
52290 * removing devices to OS
52291 */
52292- atomic_set(&pinstance->expose_resources, 1);
52293+ atomic_set_unchecked(&pinstance->expose_resources, 1);
52294 schedule_work(&pinstance->worker_q);
52295 return rc;
52296
52297diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
52298index e1d150f..6c6df44 100644
52299--- a/drivers/scsi/pmcraid.h
52300+++ b/drivers/scsi/pmcraid.h
52301@@ -748,7 +748,7 @@ struct pmcraid_instance {
52302 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
52303
52304 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
52305- atomic_t last_message_id;
52306+ atomic_unchecked_t last_message_id;
52307
52308 /* configuration table */
52309 struct pmcraid_config_table *cfg_table;
52310@@ -777,7 +777,7 @@ struct pmcraid_instance {
52311 atomic_t outstanding_cmds;
52312
52313 /* should add/delete resources to mid-layer now ?*/
52314- atomic_t expose_resources;
52315+ atomic_unchecked_t expose_resources;
52316
52317
52318
52319@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
52320 struct pmcraid_config_table_entry_ext cfg_entry_ext;
52321 };
52322 struct scsi_device *scsi_dev; /* Link scsi_device structure */
52323- atomic_t read_failures; /* count of failed READ commands */
52324- atomic_t write_failures; /* count of failed WRITE commands */
52325+ atomic_unchecked_t read_failures; /* count of failed READ commands */
52326+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
52327
52328 /* To indicate add/delete/modify during CCN */
52329 u8 change_detected;
52330diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
52331index 16fe519..3b1ec82 100644
52332--- a/drivers/scsi/qla2xxx/qla_attr.c
52333+++ b/drivers/scsi/qla2xxx/qla_attr.c
52334@@ -2188,7 +2188,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
52335 return 0;
52336 }
52337
52338-struct fc_function_template qla2xxx_transport_functions = {
52339+fc_function_template_no_const qla2xxx_transport_functions = {
52340
52341 .show_host_node_name = 1,
52342 .show_host_port_name = 1,
52343@@ -2236,7 +2236,7 @@ struct fc_function_template qla2xxx_transport_functions = {
52344 .bsg_timeout = qla24xx_bsg_timeout,
52345 };
52346
52347-struct fc_function_template qla2xxx_transport_vport_functions = {
52348+fc_function_template_no_const qla2xxx_transport_vport_functions = {
52349
52350 .show_host_node_name = 1,
52351 .show_host_port_name = 1,
52352diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
52353index d646540..5b13554 100644
52354--- a/drivers/scsi/qla2xxx/qla_gbl.h
52355+++ b/drivers/scsi/qla2xxx/qla_gbl.h
52356@@ -569,8 +569,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
52357 struct device_attribute;
52358 extern struct device_attribute *qla2x00_host_attrs[];
52359 struct fc_function_template;
52360-extern struct fc_function_template qla2xxx_transport_functions;
52361-extern struct fc_function_template qla2xxx_transport_vport_functions;
52362+extern fc_function_template_no_const qla2xxx_transport_functions;
52363+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
52364 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
52365 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
52366 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
52367diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
52368index 8252c0e..613adad 100644
52369--- a/drivers/scsi/qla2xxx/qla_os.c
52370+++ b/drivers/scsi/qla2xxx/qla_os.c
52371@@ -1493,8 +1493,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
52372 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
52373 /* Ok, a 64bit DMA mask is applicable. */
52374 ha->flags.enable_64bit_addressing = 1;
52375- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
52376- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
52377+ pax_open_kernel();
52378+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
52379+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
52380+ pax_close_kernel();
52381 return;
52382 }
52383 }
52384diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
52385index 8f6d0fb..1b21097 100644
52386--- a/drivers/scsi/qla4xxx/ql4_def.h
52387+++ b/drivers/scsi/qla4xxx/ql4_def.h
52388@@ -305,7 +305,7 @@ struct ddb_entry {
52389 * (4000 only) */
52390 atomic_t relogin_timer; /* Max Time to wait for
52391 * relogin to complete */
52392- atomic_t relogin_retry_count; /* Num of times relogin has been
52393+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
52394 * retried */
52395 uint32_t default_time2wait; /* Default Min time between
52396 * relogins (+aens) */
52397diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
52398index 199fcf7..3c3a918 100644
52399--- a/drivers/scsi/qla4xxx/ql4_os.c
52400+++ b/drivers/scsi/qla4xxx/ql4_os.c
52401@@ -4496,12 +4496,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
52402 */
52403 if (!iscsi_is_session_online(cls_sess)) {
52404 /* Reset retry relogin timer */
52405- atomic_inc(&ddb_entry->relogin_retry_count);
52406+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
52407 DEBUG2(ql4_printk(KERN_INFO, ha,
52408 "%s: index[%d] relogin timed out-retrying"
52409 " relogin (%d), retry (%d)\n", __func__,
52410 ddb_entry->fw_ddb_index,
52411- atomic_read(&ddb_entry->relogin_retry_count),
52412+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
52413 ddb_entry->default_time2wait + 4));
52414 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
52415 atomic_set(&ddb_entry->retry_relogin_timer,
52416@@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
52417
52418 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
52419 atomic_set(&ddb_entry->relogin_timer, 0);
52420- atomic_set(&ddb_entry->relogin_retry_count, 0);
52421+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
52422 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
52423 ddb_entry->default_relogin_timeout =
52424 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
52425diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
52426index d81f3cc..0093e5b 100644
52427--- a/drivers/scsi/scsi.c
52428+++ b/drivers/scsi/scsi.c
52429@@ -645,7 +645,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
52430 struct Scsi_Host *host = cmd->device->host;
52431 int rtn = 0;
52432
52433- atomic_inc(&cmd->device->iorequest_cnt);
52434+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
52435
52436 /* check if the device is still usable */
52437 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
52438diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
52439index 7cb8c73..14561b5 100644
52440--- a/drivers/scsi/scsi_lib.c
52441+++ b/drivers/scsi/scsi_lib.c
52442@@ -1581,7 +1581,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
52443 shost = sdev->host;
52444 scsi_init_cmd_errh(cmd);
52445 cmd->result = DID_NO_CONNECT << 16;
52446- atomic_inc(&cmd->device->iorequest_cnt);
52447+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
52448
52449 /*
52450 * SCSI request completion path will do scsi_device_unbusy(),
52451@@ -1604,9 +1604,9 @@ static void scsi_softirq_done(struct request *rq)
52452
52453 INIT_LIST_HEAD(&cmd->eh_entry);
52454
52455- atomic_inc(&cmd->device->iodone_cnt);
52456+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
52457 if (cmd->result)
52458- atomic_inc(&cmd->device->ioerr_cnt);
52459+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
52460
52461 disposition = scsi_decide_disposition(cmd);
52462 if (disposition != SUCCESS &&
52463diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
52464index 8b4105a..1f58363 100644
52465--- a/drivers/scsi/scsi_sysfs.c
52466+++ b/drivers/scsi/scsi_sysfs.c
52467@@ -805,7 +805,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
52468 char *buf) \
52469 { \
52470 struct scsi_device *sdev = to_scsi_device(dev); \
52471- unsigned long long count = atomic_read(&sdev->field); \
52472+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
52473 return snprintf(buf, 20, "0x%llx\n", count); \
52474 } \
52475 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
52476diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
52477index 5d6f348..18778a6b 100644
52478--- a/drivers/scsi/scsi_transport_fc.c
52479+++ b/drivers/scsi/scsi_transport_fc.c
52480@@ -501,7 +501,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
52481 * Netlink Infrastructure
52482 */
52483
52484-static atomic_t fc_event_seq;
52485+static atomic_unchecked_t fc_event_seq;
52486
52487 /**
52488 * fc_get_event_number - Obtain the next sequential FC event number
52489@@ -514,7 +514,7 @@ static atomic_t fc_event_seq;
52490 u32
52491 fc_get_event_number(void)
52492 {
52493- return atomic_add_return(1, &fc_event_seq);
52494+ return atomic_add_return_unchecked(1, &fc_event_seq);
52495 }
52496 EXPORT_SYMBOL(fc_get_event_number);
52497
52498@@ -658,7 +658,7 @@ static __init int fc_transport_init(void)
52499 {
52500 int error;
52501
52502- atomic_set(&fc_event_seq, 0);
52503+ atomic_set_unchecked(&fc_event_seq, 0);
52504
52505 error = transport_class_register(&fc_host_class);
52506 if (error)
52507@@ -848,7 +848,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
52508 char *cp;
52509
52510 *val = simple_strtoul(buf, &cp, 0);
52511- if ((*cp && (*cp != '\n')) || (*val < 0))
52512+ if (*cp && (*cp != '\n'))
52513 return -EINVAL;
52514 /*
52515 * Check for overflow; dev_loss_tmo is u32
52516diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
52517index 67d43e3..8cee73c 100644
52518--- a/drivers/scsi/scsi_transport_iscsi.c
52519+++ b/drivers/scsi/scsi_transport_iscsi.c
52520@@ -79,7 +79,7 @@ struct iscsi_internal {
52521 struct transport_container session_cont;
52522 };
52523
52524-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
52525+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
52526 static struct workqueue_struct *iscsi_eh_timer_workq;
52527
52528 static DEFINE_IDA(iscsi_sess_ida);
52529@@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
52530 int err;
52531
52532 ihost = shost->shost_data;
52533- session->sid = atomic_add_return(1, &iscsi_session_nr);
52534+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
52535
52536 if (target_id == ISCSI_MAX_TARGET) {
52537 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
52538@@ -4515,7 +4515,7 @@ static __init int iscsi_transport_init(void)
52539 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
52540 ISCSI_TRANSPORT_VERSION);
52541
52542- atomic_set(&iscsi_session_nr, 0);
52543+ atomic_set_unchecked(&iscsi_session_nr, 0);
52544
52545 err = class_register(&iscsi_transport_class);
52546 if (err)
52547diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
52548index ae45bd9..c32a586 100644
52549--- a/drivers/scsi/scsi_transport_srp.c
52550+++ b/drivers/scsi/scsi_transport_srp.c
52551@@ -35,7 +35,7 @@
52552 #include "scsi_priv.h"
52553
52554 struct srp_host_attrs {
52555- atomic_t next_port_id;
52556+ atomic_unchecked_t next_port_id;
52557 };
52558 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
52559
52560@@ -100,7 +100,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
52561 struct Scsi_Host *shost = dev_to_shost(dev);
52562 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
52563
52564- atomic_set(&srp_host->next_port_id, 0);
52565+ atomic_set_unchecked(&srp_host->next_port_id, 0);
52566 return 0;
52567 }
52568
52569@@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
52570 rport_fast_io_fail_timedout);
52571 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
52572
52573- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
52574+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
52575 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
52576
52577 transport_setup_device(&rport->dev);
52578diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
52579index 2c2041c..9d94085 100644
52580--- a/drivers/scsi/sd.c
52581+++ b/drivers/scsi/sd.c
52582@@ -3002,7 +3002,7 @@ static int sd_probe(struct device *dev)
52583 sdkp->disk = gd;
52584 sdkp->index = index;
52585 atomic_set(&sdkp->openers, 0);
52586- atomic_set(&sdkp->device->ioerr_cnt, 0);
52587+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
52588
52589 if (!sdp->request_queue->rq_timeout) {
52590 if (sdp->type != TYPE_MOD)
52591diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
52592index 01cf888..59e0475 100644
52593--- a/drivers/scsi/sg.c
52594+++ b/drivers/scsi/sg.c
52595@@ -1138,7 +1138,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
52596 sdp->disk->disk_name,
52597 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
52598 NULL,
52599- (char *)arg);
52600+ (char __user *)arg);
52601 case BLKTRACESTART:
52602 return blk_trace_startstop(sdp->device->request_queue, 1);
52603 case BLKTRACESTOP:
52604diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
52605index 11a5043..e36f04c 100644
52606--- a/drivers/soc/tegra/fuse/fuse-tegra.c
52607+++ b/drivers/soc/tegra/fuse/fuse-tegra.c
52608@@ -70,7 +70,7 @@ static ssize_t fuse_read(struct file *fd, struct kobject *kobj,
52609 return i;
52610 }
52611
52612-static struct bin_attribute fuse_bin_attr = {
52613+static bin_attribute_no_const fuse_bin_attr = {
52614 .attr = { .name = "fuse", .mode = S_IRUGO, },
52615 .read = fuse_read,
52616 };
52617diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
52618index 2bf2dfa..b4d9008 100644
52619--- a/drivers/spi/spi.c
52620+++ b/drivers/spi/spi.c
52621@@ -2210,7 +2210,7 @@ int spi_bus_unlock(struct spi_master *master)
52622 EXPORT_SYMBOL_GPL(spi_bus_unlock);
52623
52624 /* portable code must never pass more than 32 bytes */
52625-#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
52626+#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
52627
52628 static u8 *buf;
52629
52630diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
52631index b41429f..2de5373 100644
52632--- a/drivers/staging/android/timed_output.c
52633+++ b/drivers/staging/android/timed_output.c
52634@@ -25,7 +25,7 @@
52635 #include "timed_output.h"
52636
52637 static struct class *timed_output_class;
52638-static atomic_t device_count;
52639+static atomic_unchecked_t device_count;
52640
52641 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
52642 char *buf)
52643@@ -65,7 +65,7 @@ static int create_timed_output_class(void)
52644 timed_output_class = class_create(THIS_MODULE, "timed_output");
52645 if (IS_ERR(timed_output_class))
52646 return PTR_ERR(timed_output_class);
52647- atomic_set(&device_count, 0);
52648+ atomic_set_unchecked(&device_count, 0);
52649 timed_output_class->dev_groups = timed_output_groups;
52650 }
52651
52652@@ -83,7 +83,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
52653 if (ret < 0)
52654 return ret;
52655
52656- tdev->index = atomic_inc_return(&device_count);
52657+ tdev->index = atomic_inc_return_unchecked(&device_count);
52658 tdev->dev = device_create(timed_output_class, NULL,
52659 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
52660 if (IS_ERR(tdev->dev))
52661diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
52662index 001348c..cfaac8a 100644
52663--- a/drivers/staging/gdm724x/gdm_tty.c
52664+++ b/drivers/staging/gdm724x/gdm_tty.c
52665@@ -44,7 +44,7 @@
52666 #define gdm_tty_send_control(n, r, v, d, l) (\
52667 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
52668
52669-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
52670+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
52671
52672 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
52673 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
52674diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
52675index 6b22106..6c6e641 100644
52676--- a/drivers/staging/imx-drm/imx-drm-core.c
52677+++ b/drivers/staging/imx-drm/imx-drm-core.c
52678@@ -355,7 +355,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
52679 if (imxdrm->pipes >= MAX_CRTC)
52680 return -EINVAL;
52681
52682- if (imxdrm->drm->open_count)
52683+ if (local_read(&imxdrm->drm->open_count))
52684 return -EBUSY;
52685
52686 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
52687diff --git a/drivers/staging/line6/driver.c b/drivers/staging/line6/driver.c
52688index 503b2d7..c918745 100644
52689--- a/drivers/staging/line6/driver.c
52690+++ b/drivers/staging/line6/driver.c
52691@@ -463,7 +463,7 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
52692 {
52693 struct usb_device *usbdev = line6->usbdev;
52694 int ret;
52695- unsigned char len;
52696+ unsigned char *plen;
52697
52698 /* query the serial number: */
52699 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
52700@@ -476,27 +476,34 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
52701 return ret;
52702 }
52703
52704+ plen = kmalloc(1, GFP_KERNEL);
52705+ if (plen == NULL)
52706+ return -ENOMEM;
52707+
52708 /* Wait for data length. We'll get 0xff until length arrives. */
52709 do {
52710 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
52711 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
52712 USB_DIR_IN,
52713- 0x0012, 0x0000, &len, 1,
52714+ 0x0012, 0x0000, plen, 1,
52715 LINE6_TIMEOUT * HZ);
52716 if (ret < 0) {
52717 dev_err(line6->ifcdev,
52718 "receive length failed (error %d)\n", ret);
52719+ kfree(plen);
52720 return ret;
52721 }
52722- } while (len == 0xff);
52723+ } while (*plen == 0xff);
52724
52725- if (len != datalen) {
52726+ if (*plen != datalen) {
52727 /* should be equal or something went wrong */
52728 dev_err(line6->ifcdev,
52729 "length mismatch (expected %d, got %d)\n",
52730- (int)datalen, (int)len);
52731+ (int)datalen, (int)*plen);
52732+ kfree(plen);
52733 return -EINVAL;
52734 }
52735+ kfree(plen);
52736
52737 /* receive the result: */
52738 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
52739diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
52740index bcce919..f30fcf9 100644
52741--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
52742+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
52743@@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
52744 return 0;
52745 }
52746
52747-sfw_test_client_ops_t brw_test_client;
52748-void brw_init_test_client(void)
52749-{
52750- brw_test_client.tso_init = brw_client_init;
52751- brw_test_client.tso_fini = brw_client_fini;
52752- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
52753- brw_test_client.tso_done_rpc = brw_client_done_rpc;
52754+sfw_test_client_ops_t brw_test_client = {
52755+ .tso_init = brw_client_init,
52756+ .tso_fini = brw_client_fini,
52757+ .tso_prep_rpc = brw_client_prep_rpc,
52758+ .tso_done_rpc = brw_client_done_rpc,
52759 };
52760
52761 srpc_service_t brw_test_service;
52762diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
52763index 7e83dff..1f9a545 100644
52764--- a/drivers/staging/lustre/lnet/selftest/framework.c
52765+++ b/drivers/staging/lustre/lnet/selftest/framework.c
52766@@ -1633,12 +1633,10 @@ static srpc_service_t sfw_services[] =
52767
52768 extern sfw_test_client_ops_t ping_test_client;
52769 extern srpc_service_t ping_test_service;
52770-extern void ping_init_test_client(void);
52771 extern void ping_init_test_service(void);
52772
52773 extern sfw_test_client_ops_t brw_test_client;
52774 extern srpc_service_t brw_test_service;
52775-extern void brw_init_test_client(void);
52776 extern void brw_init_test_service(void);
52777
52778
52779@@ -1682,12 +1680,10 @@ sfw_startup (void)
52780 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
52781 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
52782
52783- brw_init_test_client();
52784 brw_init_test_service();
52785 rc = sfw_register_test(&brw_test_service, &brw_test_client);
52786 LASSERT (rc == 0);
52787
52788- ping_init_test_client();
52789 ping_init_test_service();
52790 rc = sfw_register_test(&ping_test_service, &ping_test_client);
52791 LASSERT (rc == 0);
52792diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
52793index 750cac4..e4d751f 100644
52794--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
52795+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
52796@@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
52797 return 0;
52798 }
52799
52800-sfw_test_client_ops_t ping_test_client;
52801-void ping_init_test_client(void)
52802-{
52803- ping_test_client.tso_init = ping_client_init;
52804- ping_test_client.tso_fini = ping_client_fini;
52805- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
52806- ping_test_client.tso_done_rpc = ping_client_done_rpc;
52807-}
52808+sfw_test_client_ops_t ping_test_client = {
52809+ .tso_init = ping_client_init,
52810+ .tso_fini = ping_client_fini,
52811+ .tso_prep_rpc = ping_client_prep_rpc,
52812+ .tso_done_rpc = ping_client_done_rpc,
52813+};
52814
52815 srpc_service_t ping_test_service;
52816 void ping_init_test_service(void)
52817diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52818index 30b1812f..9e5bd0b 100644
52819--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
52820+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52821@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
52822 ldlm_completion_callback lcs_completion;
52823 ldlm_blocking_callback lcs_blocking;
52824 ldlm_glimpse_callback lcs_glimpse;
52825-};
52826+} __no_const;
52827
52828 /* ldlm_lockd.c */
52829 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
52830diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
52831index 489bdd3..65058081 100644
52832--- a/drivers/staging/lustre/lustre/include/obd.h
52833+++ b/drivers/staging/lustre/lustre/include/obd.h
52834@@ -1438,7 +1438,7 @@ struct md_ops {
52835 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
52836 * wrapper function in include/linux/obd_class.h.
52837 */
52838-};
52839+} __no_const;
52840
52841 struct lsm_operations {
52842 void (*lsm_free)(struct lov_stripe_md *);
52843diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52844index b798daa..b28ca8f 100644
52845--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52846+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52847@@ -258,7 +258,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
52848 int added = (mode == LCK_NL);
52849 int overlaps = 0;
52850 int splitted = 0;
52851- const struct ldlm_callback_suite null_cbs = { NULL };
52852+ const struct ldlm_callback_suite null_cbs = { };
52853
52854 CDEBUG(D_DLMTRACE, "flags %#llx owner %llu pid %u mode %u start %llu end %llu\n",
52855 *flags, new->l_policy_data.l_flock.owner,
52856diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52857index 13a9266..3439390 100644
52858--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52859+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52860@@ -235,7 +235,7 @@ int proc_console_max_delay_cs(struct ctl_table *table, int write,
52861 void __user *buffer, size_t *lenp, loff_t *ppos)
52862 {
52863 int rc, max_delay_cs;
52864- struct ctl_table dummy = *table;
52865+ ctl_table_no_const dummy = *table;
52866 long d;
52867
52868 dummy.data = &max_delay_cs;
52869@@ -267,7 +267,7 @@ int proc_console_min_delay_cs(struct ctl_table *table, int write,
52870 void __user *buffer, size_t *lenp, loff_t *ppos)
52871 {
52872 int rc, min_delay_cs;
52873- struct ctl_table dummy = *table;
52874+ ctl_table_no_const dummy = *table;
52875 long d;
52876
52877 dummy.data = &min_delay_cs;
52878@@ -299,7 +299,7 @@ int proc_console_backoff(struct ctl_table *table, int write,
52879 void __user *buffer, size_t *lenp, loff_t *ppos)
52880 {
52881 int rc, backoff;
52882- struct ctl_table dummy = *table;
52883+ ctl_table_no_const dummy = *table;
52884
52885 dummy.data = &backoff;
52886 dummy.proc_handler = &proc_dointvec;
52887diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
52888index 3396858..c0bd996 100644
52889--- a/drivers/staging/lustre/lustre/libcfs/module.c
52890+++ b/drivers/staging/lustre/lustre/libcfs/module.c
52891@@ -314,11 +314,11 @@ out:
52892
52893
52894 struct cfs_psdev_ops libcfs_psdev_ops = {
52895- libcfs_psdev_open,
52896- libcfs_psdev_release,
52897- NULL,
52898- NULL,
52899- libcfs_ioctl
52900+ .p_open = libcfs_psdev_open,
52901+ .p_close = libcfs_psdev_release,
52902+ .p_read = NULL,
52903+ .p_write = NULL,
52904+ .p_ioctl = libcfs_ioctl
52905 };
52906
52907 extern int insert_proc(void);
52908diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
52909index efa2faf..03a9836 100644
52910--- a/drivers/staging/lustre/lustre/llite/dir.c
52911+++ b/drivers/staging/lustre/lustre/llite/dir.c
52912@@ -659,7 +659,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
52913 int mode;
52914 int err;
52915
52916- mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
52917+ mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
52918 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
52919 strlen(filename), mode, LUSTRE_OPC_MKDIR,
52920 lump);
52921diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
52922index a0f4868..139f1fb 100644
52923--- a/drivers/staging/octeon/ethernet-rx.c
52924+++ b/drivers/staging/octeon/ethernet-rx.c
52925@@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52926 /* Increment RX stats for virtual ports */
52927 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
52928 #ifdef CONFIG_64BIT
52929- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
52930- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
52931+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
52932+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
52933 #else
52934- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
52935- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
52936+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
52937+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
52938 #endif
52939 }
52940 netif_receive_skb(skb);
52941@@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52942 dev->name);
52943 */
52944 #ifdef CONFIG_64BIT
52945- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
52946+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52947 #else
52948- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
52949+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
52950 #endif
52951 dev_kfree_skb_irq(skb);
52952 }
52953diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
52954index 2aa7235..ba3c205 100644
52955--- a/drivers/staging/octeon/ethernet.c
52956+++ b/drivers/staging/octeon/ethernet.c
52957@@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
52958 * since the RX tasklet also increments it.
52959 */
52960 #ifdef CONFIG_64BIT
52961- atomic64_add(rx_status.dropped_packets,
52962- (atomic64_t *)&priv->stats.rx_dropped);
52963+ atomic64_add_unchecked(rx_status.dropped_packets,
52964+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52965 #else
52966- atomic_add(rx_status.dropped_packets,
52967- (atomic_t *)&priv->stats.rx_dropped);
52968+ atomic_add_unchecked(rx_status.dropped_packets,
52969+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
52970 #endif
52971 }
52972
52973diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
52974index 56d5c50..a14f4db 100644
52975--- a/drivers/staging/rtl8188eu/include/hal_intf.h
52976+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
52977@@ -234,7 +234,7 @@ struct hal_ops {
52978
52979 void (*hal_notch_filter)(struct adapter *adapter, bool enable);
52980 void (*hal_reset_security_engine)(struct adapter *adapter);
52981-};
52982+} __no_const;
52983
52984 enum rt_eeprom_type {
52985 EEPROM_93C46,
52986diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
52987index dc23395..cf7e9b1 100644
52988--- a/drivers/staging/rtl8712/rtl871x_io.h
52989+++ b/drivers/staging/rtl8712/rtl871x_io.h
52990@@ -108,7 +108,7 @@ struct _io_ops {
52991 u8 *pmem);
52992 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
52993 u8 *pmem);
52994-};
52995+} __no_const;
52996
52997 struct io_req {
52998 struct list_head list;
52999diff --git a/drivers/staging/unisys/visorchipset/visorchipset.h b/drivers/staging/unisys/visorchipset/visorchipset.h
53000index 2bf2e2f..84421c9 100644
53001--- a/drivers/staging/unisys/visorchipset/visorchipset.h
53002+++ b/drivers/staging/unisys/visorchipset/visorchipset.h
53003@@ -228,7 +228,7 @@ typedef struct {
53004 void (*device_resume)(ulong busNo, ulong devNo);
53005 int (*get_channel_info)(uuid_le typeGuid, ulong *minSize,
53006 ulong *maxSize);
53007-} VISORCHIPSET_BUSDEV_NOTIFIERS;
53008+} __no_const VISORCHIPSET_BUSDEV_NOTIFIERS;
53009
53010 /* These functions live inside visorchipset, and will be called to indicate
53011 * responses to specific events (by code outside of visorchipset).
53012@@ -243,7 +243,7 @@ typedef struct {
53013 void (*device_destroy)(ulong busNo, ulong devNo, int response);
53014 void (*device_pause)(ulong busNo, ulong devNo, int response);
53015 void (*device_resume)(ulong busNo, ulong devNo, int response);
53016-} VISORCHIPSET_BUSDEV_RESPONDERS;
53017+} __no_const VISORCHIPSET_BUSDEV_RESPONDERS;
53018
53019 /** Register functions (in the bus driver) to get called by visorchipset
53020 * whenever a bus or device appears for which this service partition is
53021diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
53022index 164136b..7244df5 100644
53023--- a/drivers/staging/vt6655/hostap.c
53024+++ b/drivers/staging/vt6655/hostap.c
53025@@ -68,14 +68,13 @@ static int msglevel = MSG_LEVEL_INFO;
53026 *
53027 */
53028
53029+static net_device_ops_no_const apdev_netdev_ops;
53030+
53031 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
53032 {
53033 PSDevice apdev_priv;
53034 struct net_device *dev = pDevice->dev;
53035 int ret;
53036- const struct net_device_ops apdev_netdev_ops = {
53037- .ndo_start_xmit = pDevice->tx_80211,
53038- };
53039
53040 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
53041
53042@@ -87,6 +86,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
53043 *apdev_priv = *pDevice;
53044 eth_hw_addr_inherit(pDevice->apdev, dev);
53045
53046+ /* only half broken now */
53047+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
53048 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
53049
53050 pDevice->apdev->type = ARPHRD_IEEE80211;
53051diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
53052index e7e9372..161f530 100644
53053--- a/drivers/target/sbp/sbp_target.c
53054+++ b/drivers/target/sbp/sbp_target.c
53055@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
53056
53057 #define SESSION_MAINTENANCE_INTERVAL HZ
53058
53059-static atomic_t login_id = ATOMIC_INIT(0);
53060+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
53061
53062 static void session_maintenance_work(struct work_struct *);
53063 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
53064@@ -444,7 +444,7 @@ static void sbp_management_request_login(
53065 login->lun = se_lun;
53066 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
53067 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
53068- login->login_id = atomic_inc_return(&login_id);
53069+ login->login_id = atomic_inc_return_unchecked(&login_id);
53070
53071 login->tgt_agt = sbp_target_agent_register(login);
53072 if (IS_ERR(login->tgt_agt)) {
53073diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
53074index 15a1c13..6c9b96b 100644
53075--- a/drivers/target/target_core_device.c
53076+++ b/drivers/target/target_core_device.c
53077@@ -1526,7 +1526,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
53078 spin_lock_init(&dev->se_tmr_lock);
53079 spin_lock_init(&dev->qf_cmd_lock);
53080 sema_init(&dev->caw_sem, 1);
53081- atomic_set(&dev->dev_ordered_id, 0);
53082+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
53083 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
53084 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
53085 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
53086diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
53087index a9c77b5..024a07d 100644
53088--- a/drivers/target/target_core_transport.c
53089+++ b/drivers/target/target_core_transport.c
53090@@ -1165,7 +1165,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
53091 * Used to determine when ORDERED commands should go from
53092 * Dormant to Active status.
53093 */
53094- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
53095+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
53096 smp_mb__after_atomic();
53097 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
53098 cmd->se_ordered_id, cmd->sam_task_attr,
53099diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
53100index 4b2b999..cad9fa5 100644
53101--- a/drivers/thermal/of-thermal.c
53102+++ b/drivers/thermal/of-thermal.c
53103@@ -30,6 +30,7 @@
53104 #include <linux/err.h>
53105 #include <linux/export.h>
53106 #include <linux/string.h>
53107+#include <linux/mm.h>
53108
53109 #include "thermal_core.h"
53110
53111@@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
53112 tz->get_trend = get_trend;
53113 tz->sensor_data = data;
53114
53115- tzd->ops->get_temp = of_thermal_get_temp;
53116- tzd->ops->get_trend = of_thermal_get_trend;
53117+ pax_open_kernel();
53118+ *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
53119+ *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
53120+ pax_close_kernel();
53121 mutex_unlock(&tzd->lock);
53122
53123 return tzd;
53124@@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
53125 return;
53126
53127 mutex_lock(&tzd->lock);
53128- tzd->ops->get_temp = NULL;
53129- tzd->ops->get_trend = NULL;
53130+ pax_open_kernel();
53131+ *(void **)&tzd->ops->get_temp = NULL;
53132+ *(void **)&tzd->ops->get_trend = NULL;
53133+ pax_close_kernel();
53134
53135 tz->get_temp = NULL;
53136 tz->get_trend = NULL;
53137diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
53138index fd66f57..48e6376 100644
53139--- a/drivers/tty/cyclades.c
53140+++ b/drivers/tty/cyclades.c
53141@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
53142 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
53143 info->port.count);
53144 #endif
53145- info->port.count++;
53146+ atomic_inc(&info->port.count);
53147 #ifdef CY_DEBUG_COUNT
53148 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
53149- current->pid, info->port.count);
53150+ current->pid, atomic_read(&info->port.count));
53151 #endif
53152
53153 /*
53154@@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
53155 for (j = 0; j < cy_card[i].nports; j++) {
53156 info = &cy_card[i].ports[j];
53157
53158- if (info->port.count) {
53159+ if (atomic_read(&info->port.count)) {
53160 /* XXX is the ldisc num worth this? */
53161 struct tty_struct *tty;
53162 struct tty_ldisc *ld;
53163diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
53164index 4fcec1d..5a036f7 100644
53165--- a/drivers/tty/hvc/hvc_console.c
53166+++ b/drivers/tty/hvc/hvc_console.c
53167@@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
53168
53169 spin_lock_irqsave(&hp->port.lock, flags);
53170 /* Check and then increment for fast path open. */
53171- if (hp->port.count++ > 0) {
53172+ if (atomic_inc_return(&hp->port.count) > 1) {
53173 spin_unlock_irqrestore(&hp->port.lock, flags);
53174 hvc_kick();
53175 return 0;
53176@@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
53177
53178 spin_lock_irqsave(&hp->port.lock, flags);
53179
53180- if (--hp->port.count == 0) {
53181+ if (atomic_dec_return(&hp->port.count) == 0) {
53182 spin_unlock_irqrestore(&hp->port.lock, flags);
53183 /* We are done with the tty pointer now. */
53184 tty_port_tty_set(&hp->port, NULL);
53185@@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
53186 */
53187 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
53188 } else {
53189- if (hp->port.count < 0)
53190+ if (atomic_read(&hp->port.count) < 0)
53191 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
53192- hp->vtermno, hp->port.count);
53193+ hp->vtermno, atomic_read(&hp->port.count));
53194 spin_unlock_irqrestore(&hp->port.lock, flags);
53195 }
53196 }
53197@@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
53198 * open->hangup case this can be called after the final close so prevent
53199 * that from happening for now.
53200 */
53201- if (hp->port.count <= 0) {
53202+ if (atomic_read(&hp->port.count) <= 0) {
53203 spin_unlock_irqrestore(&hp->port.lock, flags);
53204 return;
53205 }
53206
53207- hp->port.count = 0;
53208+ atomic_set(&hp->port.count, 0);
53209 spin_unlock_irqrestore(&hp->port.lock, flags);
53210 tty_port_tty_set(&hp->port, NULL);
53211
53212@@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
53213 return -EPIPE;
53214
53215 /* FIXME what's this (unprotected) check for? */
53216- if (hp->port.count <= 0)
53217+ if (atomic_read(&hp->port.count) <= 0)
53218 return -EIO;
53219
53220 spin_lock_irqsave(&hp->lock, flags);
53221diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
53222index 81e939e..95ead10 100644
53223--- a/drivers/tty/hvc/hvcs.c
53224+++ b/drivers/tty/hvc/hvcs.c
53225@@ -83,6 +83,7 @@
53226 #include <asm/hvcserver.h>
53227 #include <asm/uaccess.h>
53228 #include <asm/vio.h>
53229+#include <asm/local.h>
53230
53231 /*
53232 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
53233@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
53234
53235 spin_lock_irqsave(&hvcsd->lock, flags);
53236
53237- if (hvcsd->port.count > 0) {
53238+ if (atomic_read(&hvcsd->port.count) > 0) {
53239 spin_unlock_irqrestore(&hvcsd->lock, flags);
53240 printk(KERN_INFO "HVCS: vterm state unchanged. "
53241 "The hvcs device node is still in use.\n");
53242@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
53243 }
53244 }
53245
53246- hvcsd->port.count = 0;
53247+ atomic_set(&hvcsd->port.count, 0);
53248 hvcsd->port.tty = tty;
53249 tty->driver_data = hvcsd;
53250
53251@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
53252 unsigned long flags;
53253
53254 spin_lock_irqsave(&hvcsd->lock, flags);
53255- hvcsd->port.count++;
53256+ atomic_inc(&hvcsd->port.count);
53257 hvcsd->todo_mask |= HVCS_SCHED_READ;
53258 spin_unlock_irqrestore(&hvcsd->lock, flags);
53259
53260@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
53261 hvcsd = tty->driver_data;
53262
53263 spin_lock_irqsave(&hvcsd->lock, flags);
53264- if (--hvcsd->port.count == 0) {
53265+ if (atomic_dec_and_test(&hvcsd->port.count)) {
53266
53267 vio_disable_interrupts(hvcsd->vdev);
53268
53269@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
53270
53271 free_irq(irq, hvcsd);
53272 return;
53273- } else if (hvcsd->port.count < 0) {
53274+ } else if (atomic_read(&hvcsd->port.count) < 0) {
53275 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
53276 " is missmanaged.\n",
53277- hvcsd->vdev->unit_address, hvcsd->port.count);
53278+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
53279 }
53280
53281 spin_unlock_irqrestore(&hvcsd->lock, flags);
53282@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
53283
53284 spin_lock_irqsave(&hvcsd->lock, flags);
53285 /* Preserve this so that we know how many kref refs to put */
53286- temp_open_count = hvcsd->port.count;
53287+ temp_open_count = atomic_read(&hvcsd->port.count);
53288
53289 /*
53290 * Don't kref put inside the spinlock because the destruction
53291@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
53292 tty->driver_data = NULL;
53293 hvcsd->port.tty = NULL;
53294
53295- hvcsd->port.count = 0;
53296+ atomic_set(&hvcsd->port.count, 0);
53297
53298 /* This will drop any buffered data on the floor which is OK in a hangup
53299 * scenario. */
53300@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
53301 * the middle of a write operation? This is a crummy place to do this
53302 * but we want to keep it all in the spinlock.
53303 */
53304- if (hvcsd->port.count <= 0) {
53305+ if (atomic_read(&hvcsd->port.count) <= 0) {
53306 spin_unlock_irqrestore(&hvcsd->lock, flags);
53307 return -ENODEV;
53308 }
53309@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
53310 {
53311 struct hvcs_struct *hvcsd = tty->driver_data;
53312
53313- if (!hvcsd || hvcsd->port.count <= 0)
53314+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
53315 return 0;
53316
53317 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
53318diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
53319index 4190199..06d5bfa 100644
53320--- a/drivers/tty/hvc/hvsi.c
53321+++ b/drivers/tty/hvc/hvsi.c
53322@@ -85,7 +85,7 @@ struct hvsi_struct {
53323 int n_outbuf;
53324 uint32_t vtermno;
53325 uint32_t virq;
53326- atomic_t seqno; /* HVSI packet sequence number */
53327+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
53328 uint16_t mctrl;
53329 uint8_t state; /* HVSI protocol state */
53330 uint8_t flags;
53331@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
53332
53333 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
53334 packet.hdr.len = sizeof(struct hvsi_query_response);
53335- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53336+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53337 packet.verb = VSV_SEND_VERSION_NUMBER;
53338 packet.u.version = HVSI_VERSION;
53339 packet.query_seqno = query_seqno+1;
53340@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
53341
53342 packet.hdr.type = VS_QUERY_PACKET_HEADER;
53343 packet.hdr.len = sizeof(struct hvsi_query);
53344- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53345+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53346 packet.verb = verb;
53347
53348 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
53349@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
53350 int wrote;
53351
53352 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
53353- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53354+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53355 packet.hdr.len = sizeof(struct hvsi_control);
53356 packet.verb = VSV_SET_MODEM_CTL;
53357 packet.mask = HVSI_TSDTR;
53358@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
53359 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
53360
53361 packet.hdr.type = VS_DATA_PACKET_HEADER;
53362- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53363+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53364 packet.hdr.len = count + sizeof(struct hvsi_header);
53365 memcpy(&packet.data, buf, count);
53366
53367@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
53368 struct hvsi_control packet __ALIGNED__;
53369
53370 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
53371- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53372+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53373 packet.hdr.len = 6;
53374 packet.verb = VSV_CLOSE_PROTOCOL;
53375
53376@@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
53377
53378 tty_port_tty_set(&hp->port, tty);
53379 spin_lock_irqsave(&hp->lock, flags);
53380- hp->port.count++;
53381+ atomic_inc(&hp->port.count);
53382 atomic_set(&hp->seqno, 0);
53383 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
53384 spin_unlock_irqrestore(&hp->lock, flags);
53385@@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
53386
53387 spin_lock_irqsave(&hp->lock, flags);
53388
53389- if (--hp->port.count == 0) {
53390+ if (atomic_dec_return(&hp->port.count) == 0) {
53391 tty_port_tty_set(&hp->port, NULL);
53392 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
53393
53394@@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
53395
53396 spin_lock_irqsave(&hp->lock, flags);
53397 }
53398- } else if (hp->port.count < 0)
53399+ } else if (atomic_read(&hp->port.count) < 0)
53400 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
53401- hp - hvsi_ports, hp->port.count);
53402+ hp - hvsi_ports, atomic_read(&hp->port.count));
53403
53404 spin_unlock_irqrestore(&hp->lock, flags);
53405 }
53406@@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
53407 tty_port_tty_set(&hp->port, NULL);
53408
53409 spin_lock_irqsave(&hp->lock, flags);
53410- hp->port.count = 0;
53411+ atomic_set(&hp->port.count, 0);
53412 hp->n_outbuf = 0;
53413 spin_unlock_irqrestore(&hp->lock, flags);
53414 }
53415diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
53416index 7ae6c29..05c6dba 100644
53417--- a/drivers/tty/hvc/hvsi_lib.c
53418+++ b/drivers/tty/hvc/hvsi_lib.c
53419@@ -8,7 +8,7 @@
53420
53421 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
53422 {
53423- packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
53424+ packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
53425
53426 /* Assumes that always succeeds, works in practice */
53427 return pv->put_chars(pv->termno, (char *)packet, packet->len);
53428@@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
53429
53430 /* Reset state */
53431 pv->established = 0;
53432- atomic_set(&pv->seqno, 0);
53433+ atomic_set_unchecked(&pv->seqno, 0);
53434
53435 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
53436
53437diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
53438index 345cebb..d5a1e9e 100644
53439--- a/drivers/tty/ipwireless/tty.c
53440+++ b/drivers/tty/ipwireless/tty.c
53441@@ -28,6 +28,7 @@
53442 #include <linux/tty_driver.h>
53443 #include <linux/tty_flip.h>
53444 #include <linux/uaccess.h>
53445+#include <asm/local.h>
53446
53447 #include "tty.h"
53448 #include "network.h"
53449@@ -93,10 +94,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53450 return -ENODEV;
53451
53452 mutex_lock(&tty->ipw_tty_mutex);
53453- if (tty->port.count == 0)
53454+ if (atomic_read(&tty->port.count) == 0)
53455 tty->tx_bytes_queued = 0;
53456
53457- tty->port.count++;
53458+ atomic_inc(&tty->port.count);
53459
53460 tty->port.tty = linux_tty;
53461 linux_tty->driver_data = tty;
53462@@ -112,9 +113,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53463
53464 static void do_ipw_close(struct ipw_tty *tty)
53465 {
53466- tty->port.count--;
53467-
53468- if (tty->port.count == 0) {
53469+ if (atomic_dec_return(&tty->port.count) == 0) {
53470 struct tty_struct *linux_tty = tty->port.tty;
53471
53472 if (linux_tty != NULL) {
53473@@ -135,7 +134,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
53474 return;
53475
53476 mutex_lock(&tty->ipw_tty_mutex);
53477- if (tty->port.count == 0) {
53478+ if (atomic_read(&tty->port.count) == 0) {
53479 mutex_unlock(&tty->ipw_tty_mutex);
53480 return;
53481 }
53482@@ -158,7 +157,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
53483
53484 mutex_lock(&tty->ipw_tty_mutex);
53485
53486- if (!tty->port.count) {
53487+ if (!atomic_read(&tty->port.count)) {
53488 mutex_unlock(&tty->ipw_tty_mutex);
53489 return;
53490 }
53491@@ -197,7 +196,7 @@ static int ipw_write(struct tty_struct *linux_tty,
53492 return -ENODEV;
53493
53494 mutex_lock(&tty->ipw_tty_mutex);
53495- if (!tty->port.count) {
53496+ if (!atomic_read(&tty->port.count)) {
53497 mutex_unlock(&tty->ipw_tty_mutex);
53498 return -EINVAL;
53499 }
53500@@ -237,7 +236,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
53501 if (!tty)
53502 return -ENODEV;
53503
53504- if (!tty->port.count)
53505+ if (!atomic_read(&tty->port.count))
53506 return -EINVAL;
53507
53508 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
53509@@ -279,7 +278,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
53510 if (!tty)
53511 return 0;
53512
53513- if (!tty->port.count)
53514+ if (!atomic_read(&tty->port.count))
53515 return 0;
53516
53517 return tty->tx_bytes_queued;
53518@@ -360,7 +359,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
53519 if (!tty)
53520 return -ENODEV;
53521
53522- if (!tty->port.count)
53523+ if (!atomic_read(&tty->port.count))
53524 return -EINVAL;
53525
53526 return get_control_lines(tty);
53527@@ -376,7 +375,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
53528 if (!tty)
53529 return -ENODEV;
53530
53531- if (!tty->port.count)
53532+ if (!atomic_read(&tty->port.count))
53533 return -EINVAL;
53534
53535 return set_control_lines(tty, set, clear);
53536@@ -390,7 +389,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
53537 if (!tty)
53538 return -ENODEV;
53539
53540- if (!tty->port.count)
53541+ if (!atomic_read(&tty->port.count))
53542 return -EINVAL;
53543
53544 /* FIXME: Exactly how is the tty object locked here .. */
53545@@ -546,7 +545,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
53546 * are gone */
53547 mutex_lock(&ttyj->ipw_tty_mutex);
53548 }
53549- while (ttyj->port.count)
53550+ while (atomic_read(&ttyj->port.count))
53551 do_ipw_close(ttyj);
53552 ipwireless_disassociate_network_ttys(network,
53553 ttyj->channel_idx);
53554diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
53555index 1deaca4..c8582d4 100644
53556--- a/drivers/tty/moxa.c
53557+++ b/drivers/tty/moxa.c
53558@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
53559 }
53560
53561 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
53562- ch->port.count++;
53563+ atomic_inc(&ch->port.count);
53564 tty->driver_data = ch;
53565 tty_port_tty_set(&ch->port, tty);
53566 mutex_lock(&ch->port.mutex);
53567diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
53568index c434376..114ce13 100644
53569--- a/drivers/tty/n_gsm.c
53570+++ b/drivers/tty/n_gsm.c
53571@@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
53572 spin_lock_init(&dlci->lock);
53573 mutex_init(&dlci->mutex);
53574 dlci->fifo = &dlci->_fifo;
53575- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
53576+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
53577 kfree(dlci);
53578 return NULL;
53579 }
53580@@ -2958,7 +2958,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
53581 struct gsm_dlci *dlci = tty->driver_data;
53582 struct tty_port *port = &dlci->port;
53583
53584- port->count++;
53585+ atomic_inc(&port->count);
53586 tty_port_tty_set(port, tty);
53587
53588 dlci->modem_rx = 0;
53589diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
53590index f44f1ba..a8d5915 100644
53591--- a/drivers/tty/n_tty.c
53592+++ b/drivers/tty/n_tty.c
53593@@ -115,7 +115,7 @@ struct n_tty_data {
53594 int minimum_to_wake;
53595
53596 /* consumer-published */
53597- size_t read_tail;
53598+ size_t read_tail __intentional_overflow(-1);
53599 size_t line_start;
53600
53601 /* protected by output lock */
53602@@ -2517,6 +2517,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
53603 {
53604 *ops = tty_ldisc_N_TTY;
53605 ops->owner = NULL;
53606- ops->refcount = ops->flags = 0;
53607+ atomic_set(&ops->refcount, 0);
53608+ ops->flags = 0;
53609 }
53610 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
53611diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
53612index 9bbdb1d..dc514ee 100644
53613--- a/drivers/tty/pty.c
53614+++ b/drivers/tty/pty.c
53615@@ -789,8 +789,10 @@ static void __init unix98_pty_init(void)
53616 panic("Couldn't register Unix98 pts driver");
53617
53618 /* Now create the /dev/ptmx special device */
53619+ pax_open_kernel();
53620 tty_default_fops(&ptmx_fops);
53621- ptmx_fops.open = ptmx_open;
53622+ *(void **)&ptmx_fops.open = ptmx_open;
53623+ pax_close_kernel();
53624
53625 cdev_init(&ptmx_cdev, &ptmx_fops);
53626 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
53627diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
53628index 383c4c7..d408e21 100644
53629--- a/drivers/tty/rocket.c
53630+++ b/drivers/tty/rocket.c
53631@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
53632 tty->driver_data = info;
53633 tty_port_tty_set(port, tty);
53634
53635- if (port->count++ == 0) {
53636+ if (atomic_inc_return(&port->count) == 1) {
53637 atomic_inc(&rp_num_ports_open);
53638
53639 #ifdef ROCKET_DEBUG_OPEN
53640@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
53641 #endif
53642 }
53643 #ifdef ROCKET_DEBUG_OPEN
53644- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
53645+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
53646 #endif
53647
53648 /*
53649@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
53650 spin_unlock_irqrestore(&info->port.lock, flags);
53651 return;
53652 }
53653- if (info->port.count)
53654+ if (atomic_read(&info->port.count))
53655 atomic_dec(&rp_num_ports_open);
53656 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
53657 spin_unlock_irqrestore(&info->port.lock, flags);
53658diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
53659index aa28209..e08fb85 100644
53660--- a/drivers/tty/serial/ioc4_serial.c
53661+++ b/drivers/tty/serial/ioc4_serial.c
53662@@ -437,7 +437,7 @@ struct ioc4_soft {
53663 } is_intr_info[MAX_IOC4_INTR_ENTS];
53664
53665 /* Number of entries active in the above array */
53666- atomic_t is_num_intrs;
53667+ atomic_unchecked_t is_num_intrs;
53668 } is_intr_type[IOC4_NUM_INTR_TYPES];
53669
53670 /* is_ir_lock must be held while
53671@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
53672 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
53673 || (type == IOC4_OTHER_INTR_TYPE)));
53674
53675- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
53676+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
53677 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
53678
53679 /* Save off the lower level interrupt handler */
53680@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
53681
53682 soft = arg;
53683 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
53684- num_intrs = (int)atomic_read(
53685+ num_intrs = (int)atomic_read_unchecked(
53686 &soft->is_intr_type[intr_type].is_num_intrs);
53687
53688 this_mir = this_ir = pending_intrs(soft, intr_type);
53689diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c
53690index 6ec7501..265bcbf 100644
53691--- a/drivers/tty/serial/kgdb_nmi.c
53692+++ b/drivers/tty/serial/kgdb_nmi.c
53693@@ -51,7 +51,9 @@ static int kgdb_nmi_console_setup(struct console *co, char *options)
53694 * I/O utilities that messages sent to the console will automatically
53695 * be displayed on the dbg_io.
53696 */
53697- dbg_io_ops->is_console = true;
53698+ pax_open_kernel();
53699+ *(int *)&dbg_io_ops->is_console = true;
53700+ pax_close_kernel();
53701
53702 return 0;
53703 }
53704diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
53705index a260cde..6b2b5ce 100644
53706--- a/drivers/tty/serial/kgdboc.c
53707+++ b/drivers/tty/serial/kgdboc.c
53708@@ -24,8 +24,9 @@
53709 #define MAX_CONFIG_LEN 40
53710
53711 static struct kgdb_io kgdboc_io_ops;
53712+static struct kgdb_io kgdboc_io_ops_console;
53713
53714-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
53715+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
53716 static int configured = -1;
53717
53718 static char config[MAX_CONFIG_LEN];
53719@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
53720 kgdboc_unregister_kbd();
53721 if (configured == 1)
53722 kgdb_unregister_io_module(&kgdboc_io_ops);
53723+ else if (configured == 2)
53724+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
53725 }
53726
53727 static int configure_kgdboc(void)
53728@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
53729 int err;
53730 char *cptr = config;
53731 struct console *cons;
53732+ int is_console = 0;
53733
53734 err = kgdboc_option_setup(config);
53735 if (err || !strlen(config) || isspace(config[0]))
53736 goto noconfig;
53737
53738 err = -ENODEV;
53739- kgdboc_io_ops.is_console = 0;
53740 kgdb_tty_driver = NULL;
53741
53742 kgdboc_use_kms = 0;
53743@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
53744 int idx;
53745 if (cons->device && cons->device(cons, &idx) == p &&
53746 idx == tty_line) {
53747- kgdboc_io_ops.is_console = 1;
53748+ is_console = 1;
53749 break;
53750 }
53751 cons = cons->next;
53752@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
53753 kgdb_tty_line = tty_line;
53754
53755 do_register:
53756- err = kgdb_register_io_module(&kgdboc_io_ops);
53757+ if (is_console) {
53758+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
53759+ configured = 2;
53760+ } else {
53761+ err = kgdb_register_io_module(&kgdboc_io_ops);
53762+ configured = 1;
53763+ }
53764 if (err)
53765 goto noconfig;
53766
53767@@ -205,8 +214,6 @@ do_register:
53768 if (err)
53769 goto nmi_con_failed;
53770
53771- configured = 1;
53772-
53773 return 0;
53774
53775 nmi_con_failed:
53776@@ -223,7 +230,7 @@ noconfig:
53777 static int __init init_kgdboc(void)
53778 {
53779 /* Already configured? */
53780- if (configured == 1)
53781+ if (configured >= 1)
53782 return 0;
53783
53784 return configure_kgdboc();
53785@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
53786 if (config[len - 1] == '\n')
53787 config[len - 1] = '\0';
53788
53789- if (configured == 1)
53790+ if (configured >= 1)
53791 cleanup_kgdboc();
53792
53793 /* Go and configure with the new params. */
53794@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
53795 .post_exception = kgdboc_post_exp_handler,
53796 };
53797
53798+static struct kgdb_io kgdboc_io_ops_console = {
53799+ .name = "kgdboc",
53800+ .read_char = kgdboc_get_char,
53801+ .write_char = kgdboc_put_char,
53802+ .pre_exception = kgdboc_pre_exp_handler,
53803+ .post_exception = kgdboc_post_exp_handler,
53804+ .is_console = 1
53805+};
53806+
53807 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
53808 /* This is only available if kgdboc is a built in for early debugging */
53809 static int __init kgdboc_early_init(char *opt)
53810diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
53811index 077570a..12550a9 100644
53812--- a/drivers/tty/serial/msm_serial.c
53813+++ b/drivers/tty/serial/msm_serial.c
53814@@ -981,7 +981,7 @@ static struct uart_driver msm_uart_driver = {
53815 .cons = MSM_CONSOLE,
53816 };
53817
53818-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
53819+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
53820
53821 static const struct of_device_id msm_uartdm_table[] = {
53822 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
53823@@ -1000,7 +1000,7 @@ static int msm_serial_probe(struct platform_device *pdev)
53824 int irq;
53825
53826 if (pdev->id == -1)
53827- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
53828+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
53829
53830 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
53831 return -ENXIO;
53832diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
53833index c78f43a..22b1dab 100644
53834--- a/drivers/tty/serial/samsung.c
53835+++ b/drivers/tty/serial/samsung.c
53836@@ -478,11 +478,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
53837 }
53838 }
53839
53840+static int s3c64xx_serial_startup(struct uart_port *port);
53841 static int s3c24xx_serial_startup(struct uart_port *port)
53842 {
53843 struct s3c24xx_uart_port *ourport = to_ourport(port);
53844 int ret;
53845
53846+ /* Startup sequence is different for s3c64xx and higher SoC's */
53847+ if (s3c24xx_serial_has_interrupt_mask(port))
53848+ return s3c64xx_serial_startup(port);
53849+
53850 dbg("s3c24xx_serial_startup: port=%p (%08llx,%p)\n",
53851 port, (unsigned long long)port->mapbase, port->membase);
53852
53853@@ -1155,10 +1160,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
53854 /* setup info for port */
53855 port->dev = &platdev->dev;
53856
53857- /* Startup sequence is different for s3c64xx and higher SoC's */
53858- if (s3c24xx_serial_has_interrupt_mask(port))
53859- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
53860-
53861 port->uartclk = 1;
53862
53863 if (cfg->uart_flags & UPF_CONS_FLOW) {
53864diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
53865index 0f03988..8a8038d 100644
53866--- a/drivers/tty/serial/serial_core.c
53867+++ b/drivers/tty/serial/serial_core.c
53868@@ -1343,7 +1343,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
53869
53870 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
53871
53872- if (!port->count || tty_port_close_start(port, tty, filp) == 0)
53873+ if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
53874 return;
53875
53876 /*
53877@@ -1470,7 +1470,7 @@ static void uart_hangup(struct tty_struct *tty)
53878 uart_flush_buffer(tty);
53879 uart_shutdown(tty, state);
53880 spin_lock_irqsave(&port->lock, flags);
53881- port->count = 0;
53882+ atomic_set(&port->count, 0);
53883 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
53884 spin_unlock_irqrestore(&port->lock, flags);
53885 tty_port_tty_set(port, NULL);
53886@@ -1568,7 +1568,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53887 goto end;
53888 }
53889
53890- port->count++;
53891+ atomic_inc(&port->count);
53892 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
53893 retval = -ENXIO;
53894 goto err_dec_count;
53895@@ -1600,7 +1600,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53896 end:
53897 return retval;
53898 err_dec_count:
53899- port->count--;
53900+ atomic_inc(&port->count);
53901 mutex_unlock(&port->mutex);
53902 goto end;
53903 }
53904diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
53905index b799170..87dafd5 100644
53906--- a/drivers/tty/synclink.c
53907+++ b/drivers/tty/synclink.c
53908@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53909
53910 if (debug_level >= DEBUG_LEVEL_INFO)
53911 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
53912- __FILE__,__LINE__, info->device_name, info->port.count);
53913+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53914
53915 if (tty_port_close_start(&info->port, tty, filp) == 0)
53916 goto cleanup;
53917@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53918 cleanup:
53919 if (debug_level >= DEBUG_LEVEL_INFO)
53920 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
53921- tty->driver->name, info->port.count);
53922+ tty->driver->name, atomic_read(&info->port.count));
53923
53924 } /* end of mgsl_close() */
53925
53926@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
53927
53928 mgsl_flush_buffer(tty);
53929 shutdown(info);
53930-
53931- info->port.count = 0;
53932+
53933+ atomic_set(&info->port.count, 0);
53934 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53935 info->port.tty = NULL;
53936
53937@@ -3296,10 +3296,10 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53938
53939 if (debug_level >= DEBUG_LEVEL_INFO)
53940 printk("%s(%d):block_til_ready before block on %s count=%d\n",
53941- __FILE__,__LINE__, tty->driver->name, port->count );
53942+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53943
53944 spin_lock_irqsave(&info->irq_spinlock, flags);
53945- port->count--;
53946+ atomic_dec(&port->count);
53947 spin_unlock_irqrestore(&info->irq_spinlock, flags);
53948 port->blocked_open++;
53949
53950@@ -3327,7 +3327,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53951
53952 if (debug_level >= DEBUG_LEVEL_INFO)
53953 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
53954- __FILE__,__LINE__, tty->driver->name, port->count );
53955+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53956
53957 tty_unlock(tty);
53958 schedule();
53959@@ -3339,12 +3339,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53960
53961 /* FIXME: Racy on hangup during close wait */
53962 if (!tty_hung_up_p(filp))
53963- port->count++;
53964+ atomic_inc(&port->count);
53965 port->blocked_open--;
53966
53967 if (debug_level >= DEBUG_LEVEL_INFO)
53968 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
53969- __FILE__,__LINE__, tty->driver->name, port->count );
53970+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53971
53972 if (!retval)
53973 port->flags |= ASYNC_NORMAL_ACTIVE;
53974@@ -3396,7 +3396,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53975
53976 if (debug_level >= DEBUG_LEVEL_INFO)
53977 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
53978- __FILE__,__LINE__,tty->driver->name, info->port.count);
53979+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53980
53981 /* If port is closing, signal caller to try again */
53982 if (info->port.flags & ASYNC_CLOSING){
53983@@ -3415,10 +3415,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53984 spin_unlock_irqrestore(&info->netlock, flags);
53985 goto cleanup;
53986 }
53987- info->port.count++;
53988+ atomic_inc(&info->port.count);
53989 spin_unlock_irqrestore(&info->netlock, flags);
53990
53991- if (info->port.count == 1) {
53992+ if (atomic_read(&info->port.count) == 1) {
53993 /* 1st open on this device, init hardware */
53994 retval = startup(info);
53995 if (retval < 0)
53996@@ -3442,8 +3442,8 @@ cleanup:
53997 if (retval) {
53998 if (tty->count == 1)
53999 info->port.tty = NULL; /* tty layer will release tty struct */
54000- if(info->port.count)
54001- info->port.count--;
54002+ if (atomic_read(&info->port.count))
54003+ atomic_dec(&info->port.count);
54004 }
54005
54006 return retval;
54007@@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
54008 unsigned short new_crctype;
54009
54010 /* return error if TTY interface open */
54011- if (info->port.count)
54012+ if (atomic_read(&info->port.count))
54013 return -EBUSY;
54014
54015 switch (encoding)
54016@@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
54017
54018 /* arbitrate between network and tty opens */
54019 spin_lock_irqsave(&info->netlock, flags);
54020- if (info->port.count != 0 || info->netcount != 0) {
54021+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
54022 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
54023 spin_unlock_irqrestore(&info->netlock, flags);
54024 return -EBUSY;
54025@@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
54026 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
54027
54028 /* return error if TTY interface open */
54029- if (info->port.count)
54030+ if (atomic_read(&info->port.count))
54031 return -EBUSY;
54032
54033 if (cmd != SIOCWANDEV)
54034diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
54035index 0e8c39b..e0cb171 100644
54036--- a/drivers/tty/synclink_gt.c
54037+++ b/drivers/tty/synclink_gt.c
54038@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
54039 tty->driver_data = info;
54040 info->port.tty = tty;
54041
54042- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
54043+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
54044
54045 /* If port is closing, signal caller to try again */
54046 if (info->port.flags & ASYNC_CLOSING){
54047@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
54048 mutex_unlock(&info->port.mutex);
54049 goto cleanup;
54050 }
54051- info->port.count++;
54052+ atomic_inc(&info->port.count);
54053 spin_unlock_irqrestore(&info->netlock, flags);
54054
54055- if (info->port.count == 1) {
54056+ if (atomic_read(&info->port.count) == 1) {
54057 /* 1st open on this device, init hardware */
54058 retval = startup(info);
54059 if (retval < 0) {
54060@@ -715,8 +715,8 @@ cleanup:
54061 if (retval) {
54062 if (tty->count == 1)
54063 info->port.tty = NULL; /* tty layer will release tty struct */
54064- if(info->port.count)
54065- info->port.count--;
54066+ if(atomic_read(&info->port.count))
54067+ atomic_dec(&info->port.count);
54068 }
54069
54070 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
54071@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54072
54073 if (sanity_check(info, tty->name, "close"))
54074 return;
54075- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
54076+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
54077
54078 if (tty_port_close_start(&info->port, tty, filp) == 0)
54079 goto cleanup;
54080@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54081 tty_port_close_end(&info->port, tty);
54082 info->port.tty = NULL;
54083 cleanup:
54084- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
54085+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
54086 }
54087
54088 static void hangup(struct tty_struct *tty)
54089@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
54090 shutdown(info);
54091
54092 spin_lock_irqsave(&info->port.lock, flags);
54093- info->port.count = 0;
54094+ atomic_set(&info->port.count, 0);
54095 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
54096 info->port.tty = NULL;
54097 spin_unlock_irqrestore(&info->port.lock, flags);
54098@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
54099 unsigned short new_crctype;
54100
54101 /* return error if TTY interface open */
54102- if (info->port.count)
54103+ if (atomic_read(&info->port.count))
54104 return -EBUSY;
54105
54106 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
54107@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
54108
54109 /* arbitrate between network and tty opens */
54110 spin_lock_irqsave(&info->netlock, flags);
54111- if (info->port.count != 0 || info->netcount != 0) {
54112+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
54113 DBGINFO(("%s hdlc_open busy\n", dev->name));
54114 spin_unlock_irqrestore(&info->netlock, flags);
54115 return -EBUSY;
54116@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
54117 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
54118
54119 /* return error if TTY interface open */
54120- if (info->port.count)
54121+ if (atomic_read(&info->port.count))
54122 return -EBUSY;
54123
54124 if (cmd != SIOCWANDEV)
54125@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
54126 if (port == NULL)
54127 continue;
54128 spin_lock(&port->lock);
54129- if ((port->port.count || port->netcount) &&
54130+ if ((atomic_read(&port->port.count) || port->netcount) &&
54131 port->pending_bh && !port->bh_running &&
54132 !port->bh_requested) {
54133 DBGISR(("%s bh queued\n", port->device_name));
54134@@ -3299,7 +3299,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54135 add_wait_queue(&port->open_wait, &wait);
54136
54137 spin_lock_irqsave(&info->lock, flags);
54138- port->count--;
54139+ atomic_dec(&port->count);
54140 spin_unlock_irqrestore(&info->lock, flags);
54141 port->blocked_open++;
54142
54143@@ -3335,7 +3335,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54144 remove_wait_queue(&port->open_wait, &wait);
54145
54146 if (!tty_hung_up_p(filp))
54147- port->count++;
54148+ atomic_inc(&port->count);
54149 port->blocked_open--;
54150
54151 if (!retval)
54152diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
54153index c3f9091..abe4601 100644
54154--- a/drivers/tty/synclinkmp.c
54155+++ b/drivers/tty/synclinkmp.c
54156@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
54157
54158 if (debug_level >= DEBUG_LEVEL_INFO)
54159 printk("%s(%d):%s open(), old ref count = %d\n",
54160- __FILE__,__LINE__,tty->driver->name, info->port.count);
54161+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
54162
54163 /* If port is closing, signal caller to try again */
54164 if (info->port.flags & ASYNC_CLOSING){
54165@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
54166 spin_unlock_irqrestore(&info->netlock, flags);
54167 goto cleanup;
54168 }
54169- info->port.count++;
54170+ atomic_inc(&info->port.count);
54171 spin_unlock_irqrestore(&info->netlock, flags);
54172
54173- if (info->port.count == 1) {
54174+ if (atomic_read(&info->port.count) == 1) {
54175 /* 1st open on this device, init hardware */
54176 retval = startup(info);
54177 if (retval < 0)
54178@@ -796,8 +796,8 @@ cleanup:
54179 if (retval) {
54180 if (tty->count == 1)
54181 info->port.tty = NULL; /* tty layer will release tty struct */
54182- if(info->port.count)
54183- info->port.count--;
54184+ if(atomic_read(&info->port.count))
54185+ atomic_dec(&info->port.count);
54186 }
54187
54188 return retval;
54189@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54190
54191 if (debug_level >= DEBUG_LEVEL_INFO)
54192 printk("%s(%d):%s close() entry, count=%d\n",
54193- __FILE__,__LINE__, info->device_name, info->port.count);
54194+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
54195
54196 if (tty_port_close_start(&info->port, tty, filp) == 0)
54197 goto cleanup;
54198@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
54199 cleanup:
54200 if (debug_level >= DEBUG_LEVEL_INFO)
54201 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
54202- tty->driver->name, info->port.count);
54203+ tty->driver->name, atomic_read(&info->port.count));
54204 }
54205
54206 /* Called by tty_hangup() when a hangup is signaled.
54207@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
54208 shutdown(info);
54209
54210 spin_lock_irqsave(&info->port.lock, flags);
54211- info->port.count = 0;
54212+ atomic_set(&info->port.count, 0);
54213 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
54214 info->port.tty = NULL;
54215 spin_unlock_irqrestore(&info->port.lock, flags);
54216@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
54217 unsigned short new_crctype;
54218
54219 /* return error if TTY interface open */
54220- if (info->port.count)
54221+ if (atomic_read(&info->port.count))
54222 return -EBUSY;
54223
54224 switch (encoding)
54225@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
54226
54227 /* arbitrate between network and tty opens */
54228 spin_lock_irqsave(&info->netlock, flags);
54229- if (info->port.count != 0 || info->netcount != 0) {
54230+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
54231 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
54232 spin_unlock_irqrestore(&info->netlock, flags);
54233 return -EBUSY;
54234@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
54235 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
54236
54237 /* return error if TTY interface open */
54238- if (info->port.count)
54239+ if (atomic_read(&info->port.count))
54240 return -EBUSY;
54241
54242 if (cmd != SIOCWANDEV)
54243@@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
54244 * do not request bottom half processing if the
54245 * device is not open in a normal mode.
54246 */
54247- if ( port && (port->port.count || port->netcount) &&
54248+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
54249 port->pending_bh && !port->bh_running &&
54250 !port->bh_requested ) {
54251 if ( debug_level >= DEBUG_LEVEL_ISR )
54252@@ -3318,10 +3318,10 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54253
54254 if (debug_level >= DEBUG_LEVEL_INFO)
54255 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
54256- __FILE__,__LINE__, tty->driver->name, port->count );
54257+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54258
54259 spin_lock_irqsave(&info->lock, flags);
54260- port->count--;
54261+ atomic_dec(&port->count);
54262 spin_unlock_irqrestore(&info->lock, flags);
54263 port->blocked_open++;
54264
54265@@ -3349,7 +3349,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54266
54267 if (debug_level >= DEBUG_LEVEL_INFO)
54268 printk("%s(%d):%s block_til_ready() count=%d\n",
54269- __FILE__,__LINE__, tty->driver->name, port->count );
54270+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54271
54272 tty_unlock(tty);
54273 schedule();
54274@@ -3359,12 +3359,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
54275 set_current_state(TASK_RUNNING);
54276 remove_wait_queue(&port->open_wait, &wait);
54277 if (!tty_hung_up_p(filp))
54278- port->count++;
54279+ atomic_inc(&port->count);
54280 port->blocked_open--;
54281
54282 if (debug_level >= DEBUG_LEVEL_INFO)
54283 printk("%s(%d):%s block_til_ready() after, count=%d\n",
54284- __FILE__,__LINE__, tty->driver->name, port->count );
54285+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
54286
54287 if (!retval)
54288 port->flags |= ASYNC_NORMAL_ACTIVE;
54289diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
54290index 42bad18..447d7a2 100644
54291--- a/drivers/tty/sysrq.c
54292+++ b/drivers/tty/sysrq.c
54293@@ -1084,7 +1084,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
54294 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
54295 size_t count, loff_t *ppos)
54296 {
54297- if (count) {
54298+ if (count && capable(CAP_SYS_ADMIN)) {
54299 char c;
54300
54301 if (get_user(c, buf))
54302diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
54303index 848c17a..e930437 100644
54304--- a/drivers/tty/tty_io.c
54305+++ b/drivers/tty/tty_io.c
54306@@ -3469,7 +3469,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
54307
54308 void tty_default_fops(struct file_operations *fops)
54309 {
54310- *fops = tty_fops;
54311+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
54312 }
54313
54314 /*
54315diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
54316index 2d822aa..a566234 100644
54317--- a/drivers/tty/tty_ldisc.c
54318+++ b/drivers/tty/tty_ldisc.c
54319@@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
54320 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
54321 tty_ldiscs[disc] = new_ldisc;
54322 new_ldisc->num = disc;
54323- new_ldisc->refcount = 0;
54324+ atomic_set(&new_ldisc->refcount, 0);
54325 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
54326
54327 return ret;
54328@@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
54329 return -EINVAL;
54330
54331 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
54332- if (tty_ldiscs[disc]->refcount)
54333+ if (atomic_read(&tty_ldiscs[disc]->refcount))
54334 ret = -EBUSY;
54335 else
54336 tty_ldiscs[disc] = NULL;
54337@@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
54338 if (ldops) {
54339 ret = ERR_PTR(-EAGAIN);
54340 if (try_module_get(ldops->owner)) {
54341- ldops->refcount++;
54342+ atomic_inc(&ldops->refcount);
54343 ret = ldops;
54344 }
54345 }
54346@@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
54347 unsigned long flags;
54348
54349 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
54350- ldops->refcount--;
54351+ atomic_dec(&ldops->refcount);
54352 module_put(ldops->owner);
54353 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
54354 }
54355diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
54356index 1b93357..ea9f82c 100644
54357--- a/drivers/tty/tty_port.c
54358+++ b/drivers/tty/tty_port.c
54359@@ -237,7 +237,7 @@ void tty_port_hangup(struct tty_port *port)
54360 unsigned long flags;
54361
54362 spin_lock_irqsave(&port->lock, flags);
54363- port->count = 0;
54364+ atomic_set(&port->count, 0);
54365 port->flags &= ~ASYNC_NORMAL_ACTIVE;
54366 tty = port->tty;
54367 if (tty)
54368@@ -399,7 +399,7 @@ int tty_port_block_til_ready(struct tty_port *port,
54369
54370 /* The port lock protects the port counts */
54371 spin_lock_irqsave(&port->lock, flags);
54372- port->count--;
54373+ atomic_dec(&port->count);
54374 port->blocked_open++;
54375 spin_unlock_irqrestore(&port->lock, flags);
54376
54377@@ -441,7 +441,7 @@ int tty_port_block_til_ready(struct tty_port *port,
54378 we must not mess that up further */
54379 spin_lock_irqsave(&port->lock, flags);
54380 if (!tty_hung_up_p(filp))
54381- port->count++;
54382+ atomic_inc(&port->count);
54383 port->blocked_open--;
54384 if (retval == 0)
54385 port->flags |= ASYNC_NORMAL_ACTIVE;
54386@@ -479,19 +479,19 @@ int tty_port_close_start(struct tty_port *port,
54387 return 0;
54388 }
54389
54390- if (tty->count == 1 && port->count != 1) {
54391+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
54392 printk(KERN_WARNING
54393 "tty_port_close_start: tty->count = 1 port count = %d.\n",
54394- port->count);
54395- port->count = 1;
54396+ atomic_read(&port->count));
54397+ atomic_set(&port->count, 1);
54398 }
54399- if (--port->count < 0) {
54400+ if (atomic_dec_return(&port->count) < 0) {
54401 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
54402- port->count);
54403- port->count = 0;
54404+ atomic_read(&port->count));
54405+ atomic_set(&port->count, 0);
54406 }
54407
54408- if (port->count) {
54409+ if (atomic_read(&port->count)) {
54410 spin_unlock_irqrestore(&port->lock, flags);
54411 return 0;
54412 }
54413@@ -592,7 +592,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
54414 struct file *filp)
54415 {
54416 spin_lock_irq(&port->lock);
54417- ++port->count;
54418+ atomic_inc(&port->count);
54419 spin_unlock_irq(&port->lock);
54420 tty_port_tty_set(port, tty);
54421
54422diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
54423index d0e3a44..5f8b754 100644
54424--- a/drivers/tty/vt/keyboard.c
54425+++ b/drivers/tty/vt/keyboard.c
54426@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
54427 kbd->kbdmode == VC_OFF) &&
54428 value != KVAL(K_SAK))
54429 return; /* SAK is allowed even in raw mode */
54430+
54431+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54432+ {
54433+ void *func = fn_handler[value];
54434+ if (func == fn_show_state || func == fn_show_ptregs ||
54435+ func == fn_show_mem)
54436+ return;
54437+ }
54438+#endif
54439+
54440 fn_handler[value](vc);
54441 }
54442
54443@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54444 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
54445 return -EFAULT;
54446
54447- if (!capable(CAP_SYS_TTY_CONFIG))
54448- perm = 0;
54449-
54450 switch (cmd) {
54451 case KDGKBENT:
54452 /* Ensure another thread doesn't free it under us */
54453@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54454 spin_unlock_irqrestore(&kbd_event_lock, flags);
54455 return put_user(val, &user_kbe->kb_value);
54456 case KDSKBENT:
54457+ if (!capable(CAP_SYS_TTY_CONFIG))
54458+ perm = 0;
54459+
54460 if (!perm)
54461 return -EPERM;
54462 if (!i && v == K_NOSUCHMAP) {
54463@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54464 int i, j, k;
54465 int ret;
54466
54467- if (!capable(CAP_SYS_TTY_CONFIG))
54468- perm = 0;
54469-
54470 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
54471 if (!kbs) {
54472 ret = -ENOMEM;
54473@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54474 kfree(kbs);
54475 return ((p && *p) ? -EOVERFLOW : 0);
54476 case KDSKBSENT:
54477+ if (!capable(CAP_SYS_TTY_CONFIG))
54478+ perm = 0;
54479+
54480 if (!perm) {
54481 ret = -EPERM;
54482 goto reterr;
54483diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
54484index a673e5b..36e5d32 100644
54485--- a/drivers/uio/uio.c
54486+++ b/drivers/uio/uio.c
54487@@ -25,6 +25,7 @@
54488 #include <linux/kobject.h>
54489 #include <linux/cdev.h>
54490 #include <linux/uio_driver.h>
54491+#include <asm/local.h>
54492
54493 #define UIO_MAX_DEVICES (1U << MINORBITS)
54494
54495@@ -32,7 +33,7 @@ struct uio_device {
54496 struct module *owner;
54497 struct device *dev;
54498 int minor;
54499- atomic_t event;
54500+ atomic_unchecked_t event;
54501 struct fasync_struct *async_queue;
54502 wait_queue_head_t wait;
54503 struct uio_info *info;
54504@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
54505 struct device_attribute *attr, char *buf)
54506 {
54507 struct uio_device *idev = dev_get_drvdata(dev);
54508- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
54509+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
54510 }
54511 static DEVICE_ATTR_RO(event);
54512
54513@@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
54514 {
54515 struct uio_device *idev = info->uio_dev;
54516
54517- atomic_inc(&idev->event);
54518+ atomic_inc_unchecked(&idev->event);
54519 wake_up_interruptible(&idev->wait);
54520 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
54521 }
54522@@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
54523 }
54524
54525 listener->dev = idev;
54526- listener->event_count = atomic_read(&idev->event);
54527+ listener->event_count = atomic_read_unchecked(&idev->event);
54528 filep->private_data = listener;
54529
54530 if (idev->info->open) {
54531@@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
54532 return -EIO;
54533
54534 poll_wait(filep, &idev->wait, wait);
54535- if (listener->event_count != atomic_read(&idev->event))
54536+ if (listener->event_count != atomic_read_unchecked(&idev->event))
54537 return POLLIN | POLLRDNORM;
54538 return 0;
54539 }
54540@@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
54541 do {
54542 set_current_state(TASK_INTERRUPTIBLE);
54543
54544- event_count = atomic_read(&idev->event);
54545+ event_count = atomic_read_unchecked(&idev->event);
54546 if (event_count != listener->event_count) {
54547 if (copy_to_user(buf, &event_count, count))
54548 retval = -EFAULT;
54549@@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
54550 static int uio_find_mem_index(struct vm_area_struct *vma)
54551 {
54552 struct uio_device *idev = vma->vm_private_data;
54553+ unsigned long size;
54554
54555 if (vma->vm_pgoff < MAX_UIO_MAPS) {
54556- if (idev->info->mem[vma->vm_pgoff].size == 0)
54557+ size = idev->info->mem[vma->vm_pgoff].size;
54558+ if (size == 0)
54559+ return -1;
54560+ if (vma->vm_end - vma->vm_start > size)
54561 return -1;
54562 return (int)vma->vm_pgoff;
54563 }
54564@@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
54565 idev->owner = owner;
54566 idev->info = info;
54567 init_waitqueue_head(&idev->wait);
54568- atomic_set(&idev->event, 0);
54569+ atomic_set_unchecked(&idev->event, 0);
54570
54571 ret = uio_get_minor(idev);
54572 if (ret)
54573diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
54574index 813d4d3..a71934f 100644
54575--- a/drivers/usb/atm/cxacru.c
54576+++ b/drivers/usb/atm/cxacru.c
54577@@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
54578 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
54579 if (ret < 2)
54580 return -EINVAL;
54581- if (index < 0 || index > 0x7f)
54582+ if (index > 0x7f)
54583 return -EINVAL;
54584 pos += tmp;
54585
54586diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
54587index dada014..1d0d517 100644
54588--- a/drivers/usb/atm/usbatm.c
54589+++ b/drivers/usb/atm/usbatm.c
54590@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54591 if (printk_ratelimit())
54592 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
54593 __func__, vpi, vci);
54594- atomic_inc(&vcc->stats->rx_err);
54595+ atomic_inc_unchecked(&vcc->stats->rx_err);
54596 return;
54597 }
54598
54599@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54600 if (length > ATM_MAX_AAL5_PDU) {
54601 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
54602 __func__, length, vcc);
54603- atomic_inc(&vcc->stats->rx_err);
54604+ atomic_inc_unchecked(&vcc->stats->rx_err);
54605 goto out;
54606 }
54607
54608@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54609 if (sarb->len < pdu_length) {
54610 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
54611 __func__, pdu_length, sarb->len, vcc);
54612- atomic_inc(&vcc->stats->rx_err);
54613+ atomic_inc_unchecked(&vcc->stats->rx_err);
54614 goto out;
54615 }
54616
54617 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
54618 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
54619 __func__, vcc);
54620- atomic_inc(&vcc->stats->rx_err);
54621+ atomic_inc_unchecked(&vcc->stats->rx_err);
54622 goto out;
54623 }
54624
54625@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54626 if (printk_ratelimit())
54627 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
54628 __func__, length);
54629- atomic_inc(&vcc->stats->rx_drop);
54630+ atomic_inc_unchecked(&vcc->stats->rx_drop);
54631 goto out;
54632 }
54633
54634@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54635
54636 vcc->push(vcc, skb);
54637
54638- atomic_inc(&vcc->stats->rx);
54639+ atomic_inc_unchecked(&vcc->stats->rx);
54640 out:
54641 skb_trim(sarb, 0);
54642 }
54643@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
54644 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
54645
54646 usbatm_pop(vcc, skb);
54647- atomic_inc(&vcc->stats->tx);
54648+ atomic_inc_unchecked(&vcc->stats->tx);
54649
54650 skb = skb_dequeue(&instance->sndqueue);
54651 }
54652@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
54653 if (!left--)
54654 return sprintf(page,
54655 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
54656- atomic_read(&atm_dev->stats.aal5.tx),
54657- atomic_read(&atm_dev->stats.aal5.tx_err),
54658- atomic_read(&atm_dev->stats.aal5.rx),
54659- atomic_read(&atm_dev->stats.aal5.rx_err),
54660- atomic_read(&atm_dev->stats.aal5.rx_drop));
54661+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
54662+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
54663+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
54664+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
54665+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
54666
54667 if (!left--) {
54668 if (instance->disconnected)
54669diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
54670index 2a3bbdf..91d72cf 100644
54671--- a/drivers/usb/core/devices.c
54672+++ b/drivers/usb/core/devices.c
54673@@ -126,7 +126,7 @@ static const char format_endpt[] =
54674 * time it gets called.
54675 */
54676 static struct device_connect_event {
54677- atomic_t count;
54678+ atomic_unchecked_t count;
54679 wait_queue_head_t wait;
54680 } device_event = {
54681 .count = ATOMIC_INIT(1),
54682@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
54683
54684 void usbfs_conn_disc_event(void)
54685 {
54686- atomic_add(2, &device_event.count);
54687+ atomic_add_unchecked(2, &device_event.count);
54688 wake_up(&device_event.wait);
54689 }
54690
54691@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
54692
54693 poll_wait(file, &device_event.wait, wait);
54694
54695- event_count = atomic_read(&device_event.count);
54696+ event_count = atomic_read_unchecked(&device_event.count);
54697 if (file->f_version != event_count) {
54698 file->f_version = event_count;
54699 return POLLIN | POLLRDNORM;
54700diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
54701index 0b59731..46ee7d1 100644
54702--- a/drivers/usb/core/devio.c
54703+++ b/drivers/usb/core/devio.c
54704@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54705 struct usb_dev_state *ps = file->private_data;
54706 struct usb_device *dev = ps->dev;
54707 ssize_t ret = 0;
54708- unsigned len;
54709+ size_t len;
54710 loff_t pos;
54711 int i;
54712
54713@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54714 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
54715 struct usb_config_descriptor *config =
54716 (struct usb_config_descriptor *)dev->rawdescriptors[i];
54717- unsigned int length = le16_to_cpu(config->wTotalLength);
54718+ size_t length = le16_to_cpu(config->wTotalLength);
54719
54720 if (*ppos < pos + length) {
54721
54722 /* The descriptor may claim to be longer than it
54723 * really is. Here is the actual allocated length. */
54724- unsigned alloclen =
54725+ size_t alloclen =
54726 le16_to_cpu(dev->config[i].desc.wTotalLength);
54727
54728- len = length - (*ppos - pos);
54729+ len = length + pos - *ppos;
54730 if (len > nbytes)
54731 len = nbytes;
54732
54733 /* Simply don't write (skip over) unallocated parts */
54734 if (alloclen > (*ppos - pos)) {
54735- alloclen -= (*ppos - pos);
54736+ alloclen = alloclen + pos - *ppos;
54737 if (copy_to_user(buf,
54738 dev->rawdescriptors[i] + (*ppos - pos),
54739 min(len, alloclen))) {
54740diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
54741index 258e6fe..9ea48d7 100644
54742--- a/drivers/usb/core/hcd.c
54743+++ b/drivers/usb/core/hcd.c
54744@@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54745 */
54746 usb_get_urb(urb);
54747 atomic_inc(&urb->use_count);
54748- atomic_inc(&urb->dev->urbnum);
54749+ atomic_inc_unchecked(&urb->dev->urbnum);
54750 usbmon_urb_submit(&hcd->self, urb);
54751
54752 /* NOTE requirements on root-hub callers (usbfs and the hub
54753@@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54754 urb->hcpriv = NULL;
54755 INIT_LIST_HEAD(&urb->urb_list);
54756 atomic_dec(&urb->use_count);
54757- atomic_dec(&urb->dev->urbnum);
54758+ atomic_dec_unchecked(&urb->dev->urbnum);
54759 if (atomic_read(&urb->reject))
54760 wake_up(&usb_kill_urb_queue);
54761 usb_put_urb(urb);
54762diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
54763index 674c262..71fdd90 100644
54764--- a/drivers/usb/core/hub.c
54765+++ b/drivers/usb/core/hub.c
54766@@ -27,6 +27,7 @@
54767 #include <linux/freezer.h>
54768 #include <linux/random.h>
54769 #include <linux/pm_qos.h>
54770+#include <linux/grsecurity.h>
54771
54772 #include <asm/uaccess.h>
54773 #include <asm/byteorder.h>
54774@@ -4665,6 +4666,10 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
54775 goto done;
54776 return;
54777 }
54778+
54779+ if (gr_handle_new_usb())
54780+ goto done;
54781+
54782 if (hub_is_superspeed(hub->hdev))
54783 unit_load = 150;
54784 else
54785diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
54786index 0c8a7fc..c45b40a 100644
54787--- a/drivers/usb/core/message.c
54788+++ b/drivers/usb/core/message.c
54789@@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
54790 * Return: If successful, the number of bytes transferred. Otherwise, a negative
54791 * error number.
54792 */
54793-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54794+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54795 __u8 requesttype, __u16 value, __u16 index, void *data,
54796 __u16 size, int timeout)
54797 {
54798@@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
54799 * If successful, 0. Otherwise a negative error number. The number of actual
54800 * bytes transferred will be stored in the @actual_length parameter.
54801 */
54802-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54803+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54804 void *data, int len, int *actual_length, int timeout)
54805 {
54806 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
54807@@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
54808 * bytes transferred will be stored in the @actual_length parameter.
54809 *
54810 */
54811-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54812+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54813 void *data, int len, int *actual_length, int timeout)
54814 {
54815 struct urb *urb;
54816diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
54817index 1236c60..d47a51c 100644
54818--- a/drivers/usb/core/sysfs.c
54819+++ b/drivers/usb/core/sysfs.c
54820@@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
54821 struct usb_device *udev;
54822
54823 udev = to_usb_device(dev);
54824- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
54825+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
54826 }
54827 static DEVICE_ATTR_RO(urbnum);
54828
54829diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
54830index 2dd2362..1135437 100644
54831--- a/drivers/usb/core/usb.c
54832+++ b/drivers/usb/core/usb.c
54833@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
54834 set_dev_node(&dev->dev, dev_to_node(bus->controller));
54835 dev->state = USB_STATE_ATTACHED;
54836 dev->lpm_disable_count = 1;
54837- atomic_set(&dev->urbnum, 0);
54838+ atomic_set_unchecked(&dev->urbnum, 0);
54839
54840 INIT_LIST_HEAD(&dev->ep0.urb_list);
54841 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
54842diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
54843index 8cfc319..4868255 100644
54844--- a/drivers/usb/early/ehci-dbgp.c
54845+++ b/drivers/usb/early/ehci-dbgp.c
54846@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
54847
54848 #ifdef CONFIG_KGDB
54849 static struct kgdb_io kgdbdbgp_io_ops;
54850-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
54851+static struct kgdb_io kgdbdbgp_io_ops_console;
54852+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
54853 #else
54854 #define dbgp_kgdb_mode (0)
54855 #endif
54856@@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
54857 .write_char = kgdbdbgp_write_char,
54858 };
54859
54860+static struct kgdb_io kgdbdbgp_io_ops_console = {
54861+ .name = "kgdbdbgp",
54862+ .read_char = kgdbdbgp_read_char,
54863+ .write_char = kgdbdbgp_write_char,
54864+ .is_console = 1
54865+};
54866+
54867 static int kgdbdbgp_wait_time;
54868
54869 static int __init kgdbdbgp_parse_config(char *str)
54870@@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
54871 ptr++;
54872 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
54873 }
54874- kgdb_register_io_module(&kgdbdbgp_io_ops);
54875- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
54876+ if (early_dbgp_console.index != -1)
54877+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
54878+ else
54879+ kgdb_register_io_module(&kgdbdbgp_io_ops);
54880
54881 return 0;
54882 }
54883diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
54884index 2b4c82d..06a8ee6 100644
54885--- a/drivers/usb/gadget/function/f_uac1.c
54886+++ b/drivers/usb/gadget/function/f_uac1.c
54887@@ -13,6 +13,7 @@
54888 #include <linux/kernel.h>
54889 #include <linux/device.h>
54890 #include <linux/atomic.h>
54891+#include <linux/module.h>
54892
54893 #include "u_uac1.h"
54894
54895diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
54896index ad0aca8..8ff84865 100644
54897--- a/drivers/usb/gadget/function/u_serial.c
54898+++ b/drivers/usb/gadget/function/u_serial.c
54899@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54900 spin_lock_irq(&port->port_lock);
54901
54902 /* already open? Great. */
54903- if (port->port.count) {
54904+ if (atomic_read(&port->port.count)) {
54905 status = 0;
54906- port->port.count++;
54907+ atomic_inc(&port->port.count);
54908
54909 /* currently opening/closing? wait ... */
54910 } else if (port->openclose) {
54911@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54912 tty->driver_data = port;
54913 port->port.tty = tty;
54914
54915- port->port.count = 1;
54916+ atomic_set(&port->port.count, 1);
54917 port->openclose = false;
54918
54919 /* if connected, start the I/O stream */
54920@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54921
54922 spin_lock_irq(&port->port_lock);
54923
54924- if (port->port.count != 1) {
54925- if (port->port.count == 0)
54926+ if (atomic_read(&port->port.count) != 1) {
54927+ if (atomic_read(&port->port.count) == 0)
54928 WARN_ON(1);
54929 else
54930- --port->port.count;
54931+ atomic_dec(&port->port.count);
54932 goto exit;
54933 }
54934
54935@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54936 * and sleep if necessary
54937 */
54938 port->openclose = true;
54939- port->port.count = 0;
54940+ atomic_set(&port->port.count, 0);
54941
54942 gser = port->port_usb;
54943 if (gser && gser->disconnect)
54944@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
54945 int cond;
54946
54947 spin_lock_irq(&port->port_lock);
54948- cond = (port->port.count == 0) && !port->openclose;
54949+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
54950 spin_unlock_irq(&port->port_lock);
54951 return cond;
54952 }
54953@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
54954 /* if it's already open, start I/O ... and notify the serial
54955 * protocol about open/close status (connect/disconnect).
54956 */
54957- if (port->port.count) {
54958+ if (atomic_read(&port->port.count)) {
54959 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
54960 gs_start_io(port);
54961 if (gser->connect)
54962@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
54963
54964 port->port_usb = NULL;
54965 gser->ioport = NULL;
54966- if (port->port.count > 0 || port->openclose) {
54967+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
54968 wake_up_interruptible(&port->drain_wait);
54969 if (port->port.tty)
54970 tty_hangup(port->port.tty);
54971@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
54972
54973 /* finally, free any unused/unusable I/O buffers */
54974 spin_lock_irqsave(&port->port_lock, flags);
54975- if (port->port.count == 0 && !port->openclose)
54976+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
54977 gs_buf_free(&port->port_write_buf);
54978 gs_free_requests(gser->out, &port->read_pool, NULL);
54979 gs_free_requests(gser->out, &port->read_queue, NULL);
54980diff --git a/drivers/usb/gadget/function/u_uac1.c b/drivers/usb/gadget/function/u_uac1.c
54981index 7a55fea..cc0ed4f 100644
54982--- a/drivers/usb/gadget/function/u_uac1.c
54983+++ b/drivers/usb/gadget/function/u_uac1.c
54984@@ -16,6 +16,7 @@
54985 #include <linux/ctype.h>
54986 #include <linux/random.h>
54987 #include <linux/syscalls.h>
54988+#include <linux/module.h>
54989
54990 #include "u_uac1.h"
54991
54992diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
54993index 6130b75..3b60008 100644
54994--- a/drivers/usb/host/ehci-hub.c
54995+++ b/drivers/usb/host/ehci-hub.c
54996@@ -771,7 +771,7 @@ static struct urb *request_single_step_set_feature_urb(
54997 urb->transfer_flags = URB_DIR_IN;
54998 usb_get_urb(urb);
54999 atomic_inc(&urb->use_count);
55000- atomic_inc(&urb->dev->urbnum);
55001+ atomic_inc_unchecked(&urb->dev->urbnum);
55002 urb->setup_dma = dma_map_single(
55003 hcd->self.controller,
55004 urb->setup_packet,
55005@@ -838,7 +838,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
55006 urb->status = -EINPROGRESS;
55007 usb_get_urb(urb);
55008 atomic_inc(&urb->use_count);
55009- atomic_inc(&urb->dev->urbnum);
55010+ atomic_inc_unchecked(&urb->dev->urbnum);
55011 retval = submit_single_step_set_feature(hcd, urb, 0);
55012 if (!retval && !wait_for_completion_timeout(&done,
55013 msecs_to_jiffies(2000))) {
55014diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
55015index d0d8fad..668ef7b 100644
55016--- a/drivers/usb/host/hwa-hc.c
55017+++ b/drivers/usb/host/hwa-hc.c
55018@@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
55019 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
55020 struct wahc *wa = &hwahc->wa;
55021 struct device *dev = &wa->usb_iface->dev;
55022- u8 mas_le[UWB_NUM_MAS/8];
55023+ u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
55024+
55025+ if (mas_le == NULL)
55026+ return -ENOMEM;
55027
55028 /* Set the stream index */
55029 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
55030@@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
55031 WUSB_REQ_SET_WUSB_MAS,
55032 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
55033 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
55034- mas_le, 32, USB_CTRL_SET_TIMEOUT);
55035+ mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
55036 if (result < 0)
55037 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
55038 out:
55039+ kfree(mas_le);
55040+
55041 return result;
55042 }
55043
55044diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
55045index b3d245e..99549ed 100644
55046--- a/drivers/usb/misc/appledisplay.c
55047+++ b/drivers/usb/misc/appledisplay.c
55048@@ -84,7 +84,7 @@ struct appledisplay {
55049 struct mutex sysfslock; /* concurrent read and write */
55050 };
55051
55052-static atomic_t count_displays = ATOMIC_INIT(0);
55053+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
55054 static struct workqueue_struct *wq;
55055
55056 static void appledisplay_complete(struct urb *urb)
55057@@ -288,7 +288,7 @@ static int appledisplay_probe(struct usb_interface *iface,
55058
55059 /* Register backlight device */
55060 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
55061- atomic_inc_return(&count_displays) - 1);
55062+ atomic_inc_return_unchecked(&count_displays) - 1);
55063 memset(&props, 0, sizeof(struct backlight_properties));
55064 props.type = BACKLIGHT_RAW;
55065 props.max_brightness = 0xff;
55066diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
55067index 8d7fc48..01c4986 100644
55068--- a/drivers/usb/serial/console.c
55069+++ b/drivers/usb/serial/console.c
55070@@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
55071
55072 info->port = port;
55073
55074- ++port->port.count;
55075+ atomic_inc(&port->port.count);
55076 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
55077 if (serial->type->set_termios) {
55078 /*
55079@@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
55080 }
55081 /* Now that any required fake tty operations are completed restore
55082 * the tty port count */
55083- --port->port.count;
55084+ atomic_dec(&port->port.count);
55085 /* The console is special in terms of closing the device so
55086 * indicate this port is now acting as a system console. */
55087 port->port.console = 1;
55088@@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
55089 free_tty:
55090 kfree(tty);
55091 reset_open_count:
55092- port->port.count = 0;
55093+ atomic_set(&port->port.count, 0);
55094 usb_autopm_put_interface(serial->interface);
55095 error_get_interface:
55096 usb_serial_put(serial);
55097@@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
55098 static void usb_console_write(struct console *co,
55099 const char *buf, unsigned count)
55100 {
55101- static struct usbcons_info *info = &usbcons_info;
55102+ struct usbcons_info *info = &usbcons_info;
55103 struct usb_serial_port *port = info->port;
55104 struct usb_serial *serial;
55105 int retval = -ENODEV;
55106diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
55107index 307e339..6aa97cb 100644
55108--- a/drivers/usb/storage/usb.h
55109+++ b/drivers/usb/storage/usb.h
55110@@ -63,7 +63,7 @@ struct us_unusual_dev {
55111 __u8 useProtocol;
55112 __u8 useTransport;
55113 int (*initFunction)(struct us_data *);
55114-};
55115+} __do_const;
55116
55117
55118 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
55119diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h
55120index a863a98..d272795 100644
55121--- a/drivers/usb/usbip/vhci.h
55122+++ b/drivers/usb/usbip/vhci.h
55123@@ -83,7 +83,7 @@ struct vhci_hcd {
55124 unsigned resuming:1;
55125 unsigned long re_timeout;
55126
55127- atomic_t seqnum;
55128+ atomic_unchecked_t seqnum;
55129
55130 /*
55131 * NOTE:
55132diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
55133index c02374b..32d47a9 100644
55134--- a/drivers/usb/usbip/vhci_hcd.c
55135+++ b/drivers/usb/usbip/vhci_hcd.c
55136@@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
55137
55138 spin_lock(&vdev->priv_lock);
55139
55140- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
55141+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
55142 if (priv->seqnum == 0xffff)
55143 dev_info(&urb->dev->dev, "seqnum max\n");
55144
55145@@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
55146 return -ENOMEM;
55147 }
55148
55149- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
55150+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
55151 if (unlink->seqnum == 0xffff)
55152 pr_info("seqnum max\n");
55153
55154@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
55155 vdev->rhport = rhport;
55156 }
55157
55158- atomic_set(&vhci->seqnum, 0);
55159+ atomic_set_unchecked(&vhci->seqnum, 0);
55160 spin_lock_init(&vhci->lock);
55161
55162 hcd->power_budget = 0; /* no limit */
55163diff --git a/drivers/usb/usbip/vhci_rx.c b/drivers/usb/usbip/vhci_rx.c
55164index 00e4a54..d676f85 100644
55165--- a/drivers/usb/usbip/vhci_rx.c
55166+++ b/drivers/usb/usbip/vhci_rx.c
55167@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
55168 if (!urb) {
55169 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
55170 pr_info("max seqnum %d\n",
55171- atomic_read(&the_controller->seqnum));
55172+ atomic_read_unchecked(&the_controller->seqnum));
55173 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
55174 return;
55175 }
55176diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
55177index f2a8d29..7bc3fe7 100644
55178--- a/drivers/usb/wusbcore/wa-hc.h
55179+++ b/drivers/usb/wusbcore/wa-hc.h
55180@@ -240,7 +240,7 @@ struct wahc {
55181 spinlock_t xfer_list_lock;
55182 struct work_struct xfer_enqueue_work;
55183 struct work_struct xfer_error_work;
55184- atomic_t xfer_id_count;
55185+ atomic_unchecked_t xfer_id_count;
55186
55187 kernel_ulong_t quirks;
55188 };
55189@@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
55190 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
55191 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
55192 wa->dto_in_use = 0;
55193- atomic_set(&wa->xfer_id_count, 1);
55194+ atomic_set_unchecked(&wa->xfer_id_count, 1);
55195 /* init the buf in URBs */
55196 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
55197 usb_init_urb(&(wa->buf_in_urbs[index]));
55198diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
55199index e279015..c2d0dae 100644
55200--- a/drivers/usb/wusbcore/wa-xfer.c
55201+++ b/drivers/usb/wusbcore/wa-xfer.c
55202@@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
55203 */
55204 static void wa_xfer_id_init(struct wa_xfer *xfer)
55205 {
55206- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
55207+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
55208 }
55209
55210 /* Return the xfer's ID. */
55211diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
55212index f018d8d..ccab63f 100644
55213--- a/drivers/vfio/vfio.c
55214+++ b/drivers/vfio/vfio.c
55215@@ -481,7 +481,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
55216 return 0;
55217
55218 /* TODO Prevent device auto probing */
55219- WARN("Device %s added to live group %d!\n", dev_name(dev),
55220+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
55221 iommu_group_id(group->iommu_group));
55222
55223 return 0;
55224diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
55225index 5174eba..451e6bc 100644
55226--- a/drivers/vhost/vringh.c
55227+++ b/drivers/vhost/vringh.c
55228@@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
55229 /* Userspace access helpers: in this case, addresses are really userspace. */
55230 static inline int getu16_user(u16 *val, const u16 *p)
55231 {
55232- return get_user(*val, (__force u16 __user *)p);
55233+ return get_user(*val, (u16 __force_user *)p);
55234 }
55235
55236 static inline int putu16_user(u16 *p, u16 val)
55237 {
55238- return put_user(val, (__force u16 __user *)p);
55239+ return put_user(val, (u16 __force_user *)p);
55240 }
55241
55242 static inline int copydesc_user(void *dst, const void *src, size_t len)
55243 {
55244- return copy_from_user(dst, (__force void __user *)src, len) ?
55245+ return copy_from_user(dst, (void __force_user *)src, len) ?
55246 -EFAULT : 0;
55247 }
55248
55249@@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
55250 const struct vring_used_elem *src,
55251 unsigned int num)
55252 {
55253- return copy_to_user((__force void __user *)dst, src,
55254+ return copy_to_user((void __force_user *)dst, src,
55255 sizeof(*dst) * num) ? -EFAULT : 0;
55256 }
55257
55258 static inline int xfer_from_user(void *src, void *dst, size_t len)
55259 {
55260- return copy_from_user(dst, (__force void __user *)src, len) ?
55261+ return copy_from_user(dst, (void __force_user *)src, len) ?
55262 -EFAULT : 0;
55263 }
55264
55265 static inline int xfer_to_user(void *dst, void *src, size_t len)
55266 {
55267- return copy_to_user((__force void __user *)dst, src, len) ?
55268+ return copy_to_user((void __force_user *)dst, src, len) ?
55269 -EFAULT : 0;
55270 }
55271
55272@@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
55273 vrh->last_used_idx = 0;
55274 vrh->vring.num = num;
55275 /* vring expects kernel addresses, but only used via accessors. */
55276- vrh->vring.desc = (__force struct vring_desc *)desc;
55277- vrh->vring.avail = (__force struct vring_avail *)avail;
55278- vrh->vring.used = (__force struct vring_used *)used;
55279+ vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
55280+ vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
55281+ vrh->vring.used = (__force_kernel struct vring_used *)used;
55282 return 0;
55283 }
55284 EXPORT_SYMBOL(vringh_init_user);
55285@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
55286
55287 static inline int putu16_kern(u16 *p, u16 val)
55288 {
55289- ACCESS_ONCE(*p) = val;
55290+ ACCESS_ONCE_RW(*p) = val;
55291 return 0;
55292 }
55293
55294diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
55295index 84a110a..96312c3 100644
55296--- a/drivers/video/backlight/kb3886_bl.c
55297+++ b/drivers/video/backlight/kb3886_bl.c
55298@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
55299 static unsigned long kb3886bl_flags;
55300 #define KB3886BL_SUSPENDED 0x01
55301
55302-static struct dmi_system_id kb3886bl_device_table[] __initdata = {
55303+static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
55304 {
55305 .ident = "Sahara Touch-iT",
55306 .matches = {
55307diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
55308index 1b0b233..6f34c2c 100644
55309--- a/drivers/video/fbdev/arcfb.c
55310+++ b/drivers/video/fbdev/arcfb.c
55311@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
55312 return -ENOSPC;
55313
55314 err = 0;
55315- if ((count + p) > fbmemlength) {
55316+ if (count > (fbmemlength - p)) {
55317 count = fbmemlength - p;
55318 err = -ENOSPC;
55319 }
55320diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
55321index ff60701..814b973 100644
55322--- a/drivers/video/fbdev/aty/aty128fb.c
55323+++ b/drivers/video/fbdev/aty/aty128fb.c
55324@@ -149,7 +149,7 @@ enum {
55325 };
55326
55327 /* Must match above enum */
55328-static char * const r128_family[] = {
55329+static const char * const r128_family[] = {
55330 "AGP",
55331 "PCI",
55332 "PRO AGP",
55333diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
55334index 37ec09b..98f8862 100644
55335--- a/drivers/video/fbdev/aty/atyfb_base.c
55336+++ b/drivers/video/fbdev/aty/atyfb_base.c
55337@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
55338 par->accel_flags = var->accel_flags; /* hack */
55339
55340 if (var->accel_flags) {
55341- info->fbops->fb_sync = atyfb_sync;
55342+ pax_open_kernel();
55343+ *(void **)&info->fbops->fb_sync = atyfb_sync;
55344+ pax_close_kernel();
55345 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55346 } else {
55347- info->fbops->fb_sync = NULL;
55348+ pax_open_kernel();
55349+ *(void **)&info->fbops->fb_sync = NULL;
55350+ pax_close_kernel();
55351 info->flags |= FBINFO_HWACCEL_DISABLED;
55352 }
55353
55354diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
55355index 2fa0317..4983f2a 100644
55356--- a/drivers/video/fbdev/aty/mach64_cursor.c
55357+++ b/drivers/video/fbdev/aty/mach64_cursor.c
55358@@ -8,6 +8,7 @@
55359 #include "../core/fb_draw.h"
55360
55361 #include <asm/io.h>
55362+#include <asm/pgtable.h>
55363
55364 #ifdef __sparc__
55365 #include <asm/fbio.h>
55366@@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
55367 info->sprite.buf_align = 16; /* and 64 lines tall. */
55368 info->sprite.flags = FB_PIXMAP_IO;
55369
55370- info->fbops->fb_cursor = atyfb_cursor;
55371+ pax_open_kernel();
55372+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
55373+ pax_close_kernel();
55374
55375 return 0;
55376 }
55377diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
55378index 900aa4e..6d49418 100644
55379--- a/drivers/video/fbdev/core/fb_defio.c
55380+++ b/drivers/video/fbdev/core/fb_defio.c
55381@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
55382
55383 BUG_ON(!fbdefio);
55384 mutex_init(&fbdefio->lock);
55385- info->fbops->fb_mmap = fb_deferred_io_mmap;
55386+ pax_open_kernel();
55387+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
55388+ pax_close_kernel();
55389 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
55390 INIT_LIST_HEAD(&fbdefio->pagelist);
55391 if (fbdefio->delay == 0) /* set a default of 1 s */
55392@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
55393 page->mapping = NULL;
55394 }
55395
55396- info->fbops->fb_mmap = NULL;
55397+ *(void **)&info->fbops->fb_mmap = NULL;
55398 mutex_destroy(&fbdefio->lock);
55399 }
55400 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
55401diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
55402index b5e85f6..290f8c7 100644
55403--- a/drivers/video/fbdev/core/fbmem.c
55404+++ b/drivers/video/fbdev/core/fbmem.c
55405@@ -1301,7 +1301,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
55406 __u32 data;
55407 int err;
55408
55409- err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
55410+ err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
55411
55412 data = (__u32) (unsigned long) fix->smem_start;
55413 err |= put_user(data, &fix32->smem_start);
55414diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
55415index 4254336..282567e 100644
55416--- a/drivers/video/fbdev/hyperv_fb.c
55417+++ b/drivers/video/fbdev/hyperv_fb.c
55418@@ -240,7 +240,7 @@ static uint screen_fb_size;
55419 static inline int synthvid_send(struct hv_device *hdev,
55420 struct synthvid_msg *msg)
55421 {
55422- static atomic64_t request_id = ATOMIC64_INIT(0);
55423+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
55424 int ret;
55425
55426 msg->pipe_hdr.type = PIPE_MSG_DATA;
55427@@ -248,7 +248,7 @@ static inline int synthvid_send(struct hv_device *hdev,
55428
55429 ret = vmbus_sendpacket(hdev->channel, msg,
55430 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
55431- atomic64_inc_return(&request_id),
55432+ atomic64_inc_return_unchecked(&request_id),
55433 VM_PKT_DATA_INBAND, 0);
55434
55435 if (ret)
55436diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
55437index 7672d2e..b56437f 100644
55438--- a/drivers/video/fbdev/i810/i810_accel.c
55439+++ b/drivers/video/fbdev/i810/i810_accel.c
55440@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
55441 }
55442 }
55443 printk("ringbuffer lockup!!!\n");
55444+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
55445 i810_report_error(mmio);
55446 par->dev_flags |= LOCKUP;
55447 info->pixmap.scan_align = 1;
55448diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55449index a01147f..5d896f8 100644
55450--- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55451+++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55452@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55453
55454 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55455 struct matrox_switch matrox_mystique = {
55456- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55457+ .preinit = MGA1064_preinit,
55458+ .reset = MGA1064_reset,
55459+ .init = MGA1064_init,
55460+ .restore = MGA1064_restore,
55461 };
55462 EXPORT_SYMBOL(matrox_mystique);
55463 #endif
55464
55465 #ifdef CONFIG_FB_MATROX_G
55466 struct matrox_switch matrox_G100 = {
55467- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55468+ .preinit = MGAG100_preinit,
55469+ .reset = MGAG100_reset,
55470+ .init = MGAG100_init,
55471+ .restore = MGAG100_restore,
55472 };
55473 EXPORT_SYMBOL(matrox_G100);
55474 #endif
55475diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55476index 195ad7c..09743fc 100644
55477--- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55478+++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55479@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55480 }
55481
55482 struct matrox_switch matrox_millennium = {
55483- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55484+ .preinit = Ti3026_preinit,
55485+ .reset = Ti3026_reset,
55486+ .init = Ti3026_init,
55487+ .restore = Ti3026_restore
55488 };
55489 EXPORT_SYMBOL(matrox_millennium);
55490 #endif
55491diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55492index fe92eed..106e085 100644
55493--- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55494+++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55495@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55496 struct mb862xxfb_par *par = info->par;
55497
55498 if (info->var.bits_per_pixel == 32) {
55499- info->fbops->fb_fillrect = cfb_fillrect;
55500- info->fbops->fb_copyarea = cfb_copyarea;
55501- info->fbops->fb_imageblit = cfb_imageblit;
55502+ pax_open_kernel();
55503+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55504+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55505+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55506+ pax_close_kernel();
55507 } else {
55508 outreg(disp, GC_L0EM, 3);
55509- info->fbops->fb_fillrect = mb86290fb_fillrect;
55510- info->fbops->fb_copyarea = mb86290fb_copyarea;
55511- info->fbops->fb_imageblit = mb86290fb_imageblit;
55512+ pax_open_kernel();
55513+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55514+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55515+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55516+ pax_close_kernel();
55517 }
55518 outreg(draw, GDC_REG_DRAW_BASE, 0);
55519 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55520diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
55521index def0412..fed6529 100644
55522--- a/drivers/video/fbdev/nvidia/nvidia.c
55523+++ b/drivers/video/fbdev/nvidia/nvidia.c
55524@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55525 info->fix.line_length = (info->var.xres_virtual *
55526 info->var.bits_per_pixel) >> 3;
55527 if (info->var.accel_flags) {
55528- info->fbops->fb_imageblit = nvidiafb_imageblit;
55529- info->fbops->fb_fillrect = nvidiafb_fillrect;
55530- info->fbops->fb_copyarea = nvidiafb_copyarea;
55531- info->fbops->fb_sync = nvidiafb_sync;
55532+ pax_open_kernel();
55533+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55534+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55535+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55536+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55537+ pax_close_kernel();
55538 info->pixmap.scan_align = 4;
55539 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55540 info->flags |= FBINFO_READS_FAST;
55541 NVResetGraphics(info);
55542 } else {
55543- info->fbops->fb_imageblit = cfb_imageblit;
55544- info->fbops->fb_fillrect = cfb_fillrect;
55545- info->fbops->fb_copyarea = cfb_copyarea;
55546- info->fbops->fb_sync = NULL;
55547+ pax_open_kernel();
55548+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55549+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55550+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55551+ *(void **)&info->fbops->fb_sync = NULL;
55552+ pax_close_kernel();
55553 info->pixmap.scan_align = 1;
55554 info->flags |= FBINFO_HWACCEL_DISABLED;
55555 info->flags &= ~FBINFO_READS_FAST;
55556@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55557 info->pixmap.size = 8 * 1024;
55558 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55559
55560- if (!hwcur)
55561- info->fbops->fb_cursor = NULL;
55562+ if (!hwcur) {
55563+ pax_open_kernel();
55564+ *(void **)&info->fbops->fb_cursor = NULL;
55565+ pax_close_kernel();
55566+ }
55567
55568 info->var.accel_flags = (!noaccel);
55569
55570diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
55571index 2412a0d..294215b 100644
55572--- a/drivers/video/fbdev/omap2/dss/display.c
55573+++ b/drivers/video/fbdev/omap2/dss/display.c
55574@@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55575 if (dssdev->name == NULL)
55576 dssdev->name = dssdev->alias;
55577
55578+ pax_open_kernel();
55579 if (drv && drv->get_resolution == NULL)
55580- drv->get_resolution = omapdss_default_get_resolution;
55581+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55582 if (drv && drv->get_recommended_bpp == NULL)
55583- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55584+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55585 if (drv && drv->get_timings == NULL)
55586- drv->get_timings = omapdss_default_get_timings;
55587+ *(void **)&drv->get_timings = omapdss_default_get_timings;
55588+ pax_close_kernel();
55589
55590 mutex_lock(&panel_list_mutex);
55591 list_add_tail(&dssdev->panel_list, &panel_list);
55592diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
55593index 83433cb..71e9b98 100644
55594--- a/drivers/video/fbdev/s1d13xxxfb.c
55595+++ b/drivers/video/fbdev/s1d13xxxfb.c
55596@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55597
55598 switch(prod_id) {
55599 case S1D13506_PROD_ID: /* activate acceleration */
55600- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55601- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55602+ pax_open_kernel();
55603+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55604+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55605+ pax_close_kernel();
55606 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55607 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55608 break;
55609diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
55610index 2bcc84a..29dd1ea 100644
55611--- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
55612+++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
55613@@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
55614 }
55615
55616 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
55617- lcdc_sys_write_index,
55618- lcdc_sys_write_data,
55619- lcdc_sys_read_data,
55620+ .write_index = lcdc_sys_write_index,
55621+ .write_data = lcdc_sys_write_data,
55622+ .read_data = lcdc_sys_read_data,
55623 };
55624
55625 static int sh_mobile_lcdc_sginit(struct fb_info *info,
55626diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
55627index d513ed6..90b0de9 100644
55628--- a/drivers/video/fbdev/smscufx.c
55629+++ b/drivers/video/fbdev/smscufx.c
55630@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55631 fb_deferred_io_cleanup(info);
55632 kfree(info->fbdefio);
55633 info->fbdefio = NULL;
55634- info->fbops->fb_mmap = ufx_ops_mmap;
55635+ pax_open_kernel();
55636+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55637+ pax_close_kernel();
55638 }
55639
55640 pr_debug("released /dev/fb%d user=%d count=%d",
55641diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
55642index 77b890e..458e666 100644
55643--- a/drivers/video/fbdev/udlfb.c
55644+++ b/drivers/video/fbdev/udlfb.c
55645@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55646 dlfb_urb_completion(urb);
55647
55648 error:
55649- atomic_add(bytes_sent, &dev->bytes_sent);
55650- atomic_add(bytes_identical, &dev->bytes_identical);
55651- atomic_add(width*height*2, &dev->bytes_rendered);
55652+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55653+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55654+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55655 end_cycles = get_cycles();
55656- atomic_add(((unsigned int) ((end_cycles - start_cycles)
55657+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55658 >> 10)), /* Kcycles */
55659 &dev->cpu_kcycles_used);
55660
55661@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55662 dlfb_urb_completion(urb);
55663
55664 error:
55665- atomic_add(bytes_sent, &dev->bytes_sent);
55666- atomic_add(bytes_identical, &dev->bytes_identical);
55667- atomic_add(bytes_rendered, &dev->bytes_rendered);
55668+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55669+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55670+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55671 end_cycles = get_cycles();
55672- atomic_add(((unsigned int) ((end_cycles - start_cycles)
55673+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55674 >> 10)), /* Kcycles */
55675 &dev->cpu_kcycles_used);
55676 }
55677@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55678 fb_deferred_io_cleanup(info);
55679 kfree(info->fbdefio);
55680 info->fbdefio = NULL;
55681- info->fbops->fb_mmap = dlfb_ops_mmap;
55682+ pax_open_kernel();
55683+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55684+ pax_close_kernel();
55685 }
55686
55687 pr_warn("released /dev/fb%d user=%d count=%d\n",
55688@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55689 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55690 struct dlfb_data *dev = fb_info->par;
55691 return snprintf(buf, PAGE_SIZE, "%u\n",
55692- atomic_read(&dev->bytes_rendered));
55693+ atomic_read_unchecked(&dev->bytes_rendered));
55694 }
55695
55696 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55697@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55698 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55699 struct dlfb_data *dev = fb_info->par;
55700 return snprintf(buf, PAGE_SIZE, "%u\n",
55701- atomic_read(&dev->bytes_identical));
55702+ atomic_read_unchecked(&dev->bytes_identical));
55703 }
55704
55705 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55706@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55707 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55708 struct dlfb_data *dev = fb_info->par;
55709 return snprintf(buf, PAGE_SIZE, "%u\n",
55710- atomic_read(&dev->bytes_sent));
55711+ atomic_read_unchecked(&dev->bytes_sent));
55712 }
55713
55714 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55715@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55716 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55717 struct dlfb_data *dev = fb_info->par;
55718 return snprintf(buf, PAGE_SIZE, "%u\n",
55719- atomic_read(&dev->cpu_kcycles_used));
55720+ atomic_read_unchecked(&dev->cpu_kcycles_used));
55721 }
55722
55723 static ssize_t edid_show(
55724@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55725 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55726 struct dlfb_data *dev = fb_info->par;
55727
55728- atomic_set(&dev->bytes_rendered, 0);
55729- atomic_set(&dev->bytes_identical, 0);
55730- atomic_set(&dev->bytes_sent, 0);
55731- atomic_set(&dev->cpu_kcycles_used, 0);
55732+ atomic_set_unchecked(&dev->bytes_rendered, 0);
55733+ atomic_set_unchecked(&dev->bytes_identical, 0);
55734+ atomic_set_unchecked(&dev->bytes_sent, 0);
55735+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55736
55737 return count;
55738 }
55739diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
55740index 509d452..7c9d2de 100644
55741--- a/drivers/video/fbdev/uvesafb.c
55742+++ b/drivers/video/fbdev/uvesafb.c
55743@@ -19,6 +19,7 @@
55744 #include <linux/io.h>
55745 #include <linux/mutex.h>
55746 #include <linux/slab.h>
55747+#include <linux/moduleloader.h>
55748 #include <video/edid.h>
55749 #include <video/uvesafb.h>
55750 #ifdef CONFIG_X86
55751@@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55752 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55753 par->pmi_setpal = par->ypan = 0;
55754 } else {
55755+
55756+#ifdef CONFIG_PAX_KERNEXEC
55757+#ifdef CONFIG_MODULES
55758+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55759+#endif
55760+ if (!par->pmi_code) {
55761+ par->pmi_setpal = par->ypan = 0;
55762+ return 0;
55763+ }
55764+#endif
55765+
55766 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55767 + task->t.regs.edi);
55768+
55769+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55770+ pax_open_kernel();
55771+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55772+ pax_close_kernel();
55773+
55774+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55775+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55776+#else
55777 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55778 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55779+#endif
55780+
55781 printk(KERN_INFO "uvesafb: protected mode interface info at "
55782 "%04x:%04x\n",
55783 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55784@@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55785 par->ypan = ypan;
55786
55787 if (par->pmi_setpal || par->ypan) {
55788+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55789 if (__supported_pte_mask & _PAGE_NX) {
55790 par->pmi_setpal = par->ypan = 0;
55791 printk(KERN_WARNING "uvesafb: NX protection is active, "
55792 "better not use the PMI.\n");
55793- } else {
55794+ } else
55795+#endif
55796 uvesafb_vbe_getpmi(task, par);
55797- }
55798 }
55799 #else
55800 /* The protected mode interface is not available on non-x86. */
55801@@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55802 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55803
55804 /* Disable blanking if the user requested so. */
55805- if (!blank)
55806- info->fbops->fb_blank = NULL;
55807+ if (!blank) {
55808+ pax_open_kernel();
55809+ *(void **)&info->fbops->fb_blank = NULL;
55810+ pax_close_kernel();
55811+ }
55812
55813 /*
55814 * Find out how much IO memory is required for the mode with
55815@@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55816 info->flags = FBINFO_FLAG_DEFAULT |
55817 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55818
55819- if (!par->ypan)
55820- info->fbops->fb_pan_display = NULL;
55821+ if (!par->ypan) {
55822+ pax_open_kernel();
55823+ *(void **)&info->fbops->fb_pan_display = NULL;
55824+ pax_close_kernel();
55825+ }
55826 }
55827
55828 static void uvesafb_init_mtrr(struct fb_info *info)
55829@@ -1787,6 +1817,11 @@ out_mode:
55830 out:
55831 kfree(par->vbe_modes);
55832
55833+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55834+ if (par->pmi_code)
55835+ module_free_exec(NULL, par->pmi_code);
55836+#endif
55837+
55838 framebuffer_release(info);
55839 return err;
55840 }
55841@@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
55842 kfree(par->vbe_state_orig);
55843 kfree(par->vbe_state_saved);
55844
55845+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55846+ if (par->pmi_code)
55847+ module_free_exec(NULL, par->pmi_code);
55848+#endif
55849+
55850 framebuffer_release(info);
55851 }
55852 return 0;
55853diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
55854index 6170e7f..dd63031 100644
55855--- a/drivers/video/fbdev/vesafb.c
55856+++ b/drivers/video/fbdev/vesafb.c
55857@@ -9,6 +9,7 @@
55858 */
55859
55860 #include <linux/module.h>
55861+#include <linux/moduleloader.h>
55862 #include <linux/kernel.h>
55863 #include <linux/errno.h>
55864 #include <linux/string.h>
55865@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55866 static int vram_total; /* Set total amount of memory */
55867 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55868 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55869-static void (*pmi_start)(void) __read_mostly;
55870-static void (*pmi_pal) (void) __read_mostly;
55871+static void (*pmi_start)(void) __read_only;
55872+static void (*pmi_pal) (void) __read_only;
55873 static int depth __read_mostly;
55874 static int vga_compat __read_mostly;
55875 /* --------------------------------------------------------------------- */
55876@@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
55877 unsigned int size_remap;
55878 unsigned int size_total;
55879 char *option = NULL;
55880+ void *pmi_code = NULL;
55881
55882 /* ignore error return of fb_get_options */
55883 fb_get_options("vesafb", &option);
55884@@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
55885 size_remap = size_total;
55886 vesafb_fix.smem_len = size_remap;
55887
55888-#ifndef __i386__
55889- screen_info.vesapm_seg = 0;
55890-#endif
55891-
55892 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55893 printk(KERN_WARNING
55894 "vesafb: cannot reserve video memory at 0x%lx\n",
55895@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55896 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55897 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55898
55899+#ifdef __i386__
55900+
55901+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55902+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
55903+ if (!pmi_code)
55904+#elif !defined(CONFIG_PAX_KERNEXEC)
55905+ if (0)
55906+#endif
55907+
55908+#endif
55909+ screen_info.vesapm_seg = 0;
55910+
55911 if (screen_info.vesapm_seg) {
55912- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55913- screen_info.vesapm_seg,screen_info.vesapm_off);
55914+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55915+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55916 }
55917
55918 if (screen_info.vesapm_seg < 0xc000)
55919@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55920
55921 if (ypan || pmi_setpal) {
55922 unsigned short *pmi_base;
55923+
55924 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55925- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55926- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55927+
55928+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55929+ pax_open_kernel();
55930+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55931+#else
55932+ pmi_code = pmi_base;
55933+#endif
55934+
55935+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55936+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55937+
55938+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55939+ pmi_start = ktva_ktla(pmi_start);
55940+ pmi_pal = ktva_ktla(pmi_pal);
55941+ pax_close_kernel();
55942+#endif
55943+
55944 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55945 if (pmi_base[3]) {
55946 printk(KERN_INFO "vesafb: pmi: ports = ");
55947@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55948 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55949 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55950
55951- if (!ypan)
55952- info->fbops->fb_pan_display = NULL;
55953+ if (!ypan) {
55954+ pax_open_kernel();
55955+ *(void **)&info->fbops->fb_pan_display = NULL;
55956+ pax_close_kernel();
55957+ }
55958
55959 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55960 err = -ENOMEM;
55961@@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55962 fb_info(info, "%s frame buffer device\n", info->fix.id);
55963 return 0;
55964 err:
55965+
55966+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55967+ module_free_exec(NULL, pmi_code);
55968+#endif
55969+
55970 if (info->screen_base)
55971 iounmap(info->screen_base);
55972 framebuffer_release(info);
55973diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
55974index 88714ae..16c2e11 100644
55975--- a/drivers/video/fbdev/via/via_clock.h
55976+++ b/drivers/video/fbdev/via/via_clock.h
55977@@ -56,7 +56,7 @@ struct via_clock {
55978
55979 void (*set_engine_pll_state)(u8 state);
55980 void (*set_engine_pll)(struct via_pll_config config);
55981-};
55982+} __no_const;
55983
55984
55985 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55986diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
55987index 3c14e43..2630570 100644
55988--- a/drivers/video/logo/logo_linux_clut224.ppm
55989+++ b/drivers/video/logo/logo_linux_clut224.ppm
55990@@ -2,1603 +2,1123 @@ P3
55991 # Standard 224-color Linux logo
55992 80 80
55993 255
55994- 0 0 0 0 0 0 0 0 0 0 0 0
55995- 0 0 0 0 0 0 0 0 0 0 0 0
55996- 0 0 0 0 0 0 0 0 0 0 0 0
55997- 0 0 0 0 0 0 0 0 0 0 0 0
55998- 0 0 0 0 0 0 0 0 0 0 0 0
55999- 0 0 0 0 0 0 0 0 0 0 0 0
56000- 0 0 0 0 0 0 0 0 0 0 0 0
56001- 0 0 0 0 0 0 0 0 0 0 0 0
56002- 0 0 0 0 0 0 0 0 0 0 0 0
56003- 6 6 6 6 6 6 10 10 10 10 10 10
56004- 10 10 10 6 6 6 6 6 6 6 6 6
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 0 0 0
56008- 0 0 0 0 0 0 0 0 0 0 0 0
56009- 0 0 0 0 0 0 0 0 0 0 0 0
56010- 0 0 0 0 0 0 0 0 0 0 0 0
56011- 0 0 0 0 0 0 0 0 0 0 0 0
56012- 0 0 0 0 0 0 0 0 0 0 0 0
56013- 0 0 0 0 0 0 0 0 0 0 0 0
56014- 0 0 0 0 0 0 0 0 0 0 0 0
56015- 0 0 0 0 0 0 0 0 0 0 0 0
56016- 0 0 0 0 0 0 0 0 0 0 0 0
56017- 0 0 0 0 0 0 0 0 0 0 0 0
56018- 0 0 0 0 0 0 0 0 0 0 0 0
56019- 0 0 0 0 0 0 0 0 0 0 0 0
56020- 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 6 6 6 10 10 10 14 14 14
56023- 22 22 22 26 26 26 30 30 30 34 34 34
56024- 30 30 30 30 30 30 26 26 26 18 18 18
56025- 14 14 14 10 10 10 6 6 6 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 0 0 0
56028- 0 0 0 0 0 0 0 0 0 0 0 0
56029- 0 0 0 0 0 0 0 0 0 0 0 0
56030- 0 0 0 0 0 0 0 0 0 0 0 0
56031- 0 0 0 0 0 0 0 0 0 0 0 0
56032- 0 0 0 0 0 0 0 0 0 0 0 0
56033- 0 0 0 0 0 0 0 0 0 0 0 0
56034- 0 0 0 0 0 0 0 0 0 0 0 0
56035- 0 0 0 0 0 1 0 0 1 0 0 0
56036- 0 0 0 0 0 0 0 0 0 0 0 0
56037- 0 0 0 0 0 0 0 0 0 0 0 0
56038- 0 0 0 0 0 0 0 0 0 0 0 0
56039- 0 0 0 0 0 0 0 0 0 0 0 0
56040- 0 0 0 0 0 0 0 0 0 0 0 0
56041- 0 0 0 0 0 0 0 0 0 0 0 0
56042- 6 6 6 14 14 14 26 26 26 42 42 42
56043- 54 54 54 66 66 66 78 78 78 78 78 78
56044- 78 78 78 74 74 74 66 66 66 54 54 54
56045- 42 42 42 26 26 26 18 18 18 10 10 10
56046- 6 6 6 0 0 0 0 0 0 0 0 0
56047- 0 0 0 0 0 0 0 0 0 0 0 0
56048- 0 0 0 0 0 0 0 0 0 0 0 0
56049- 0 0 0 0 0 0 0 0 0 0 0 0
56050- 0 0 0 0 0 0 0 0 0 0 0 0
56051- 0 0 0 0 0 0 0 0 0 0 0 0
56052- 0 0 0 0 0 0 0 0 0 0 0 0
56053- 0 0 0 0 0 0 0 0 0 0 0 0
56054- 0 0 0 0 0 0 0 0 0 0 0 0
56055- 0 0 1 0 0 0 0 0 0 0 0 0
56056- 0 0 0 0 0 0 0 0 0 0 0 0
56057- 0 0 0 0 0 0 0 0 0 0 0 0
56058- 0 0 0 0 0 0 0 0 0 0 0 0
56059- 0 0 0 0 0 0 0 0 0 0 0 0
56060- 0 0 0 0 0 0 0 0 0 0 0 0
56061- 0 0 0 0 0 0 0 0 0 10 10 10
56062- 22 22 22 42 42 42 66 66 66 86 86 86
56063- 66 66 66 38 38 38 38 38 38 22 22 22
56064- 26 26 26 34 34 34 54 54 54 66 66 66
56065- 86 86 86 70 70 70 46 46 46 26 26 26
56066- 14 14 14 6 6 6 0 0 0 0 0 0
56067- 0 0 0 0 0 0 0 0 0 0 0 0
56068- 0 0 0 0 0 0 0 0 0 0 0 0
56069- 0 0 0 0 0 0 0 0 0 0 0 0
56070- 0 0 0 0 0 0 0 0 0 0 0 0
56071- 0 0 0 0 0 0 0 0 0 0 0 0
56072- 0 0 0 0 0 0 0 0 0 0 0 0
56073- 0 0 0 0 0 0 0 0 0 0 0 0
56074- 0 0 0 0 0 0 0 0 0 0 0 0
56075- 0 0 1 0 0 1 0 0 1 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 10 10 10 26 26 26
56082- 50 50 50 82 82 82 58 58 58 6 6 6
56083- 2 2 6 2 2 6 2 2 6 2 2 6
56084- 2 2 6 2 2 6 2 2 6 2 2 6
56085- 6 6 6 54 54 54 86 86 86 66 66 66
56086- 38 38 38 18 18 18 6 6 6 0 0 0
56087- 0 0 0 0 0 0 0 0 0 0 0 0
56088- 0 0 0 0 0 0 0 0 0 0 0 0
56089- 0 0 0 0 0 0 0 0 0 0 0 0
56090- 0 0 0 0 0 0 0 0 0 0 0 0
56091- 0 0 0 0 0 0 0 0 0 0 0 0
56092- 0 0 0 0 0 0 0 0 0 0 0 0
56093- 0 0 0 0 0 0 0 0 0 0 0 0
56094- 0 0 0 0 0 0 0 0 0 0 0 0
56095- 0 0 0 0 0 0 0 0 0 0 0 0
56096- 0 0 0 0 0 0 0 0 0 0 0 0
56097- 0 0 0 0 0 0 0 0 0 0 0 0
56098- 0 0 0 0 0 0 0 0 0 0 0 0
56099- 0 0 0 0 0 0 0 0 0 0 0 0
56100- 0 0 0 0 0 0 0 0 0 0 0 0
56101- 0 0 0 6 6 6 22 22 22 50 50 50
56102- 78 78 78 34 34 34 2 2 6 2 2 6
56103- 2 2 6 2 2 6 2 2 6 2 2 6
56104- 2 2 6 2 2 6 2 2 6 2 2 6
56105- 2 2 6 2 2 6 6 6 6 70 70 70
56106- 78 78 78 46 46 46 22 22 22 6 6 6
56107- 0 0 0 0 0 0 0 0 0 0 0 0
56108- 0 0 0 0 0 0 0 0 0 0 0 0
56109- 0 0 0 0 0 0 0 0 0 0 0 0
56110- 0 0 0 0 0 0 0 0 0 0 0 0
56111- 0 0 0 0 0 0 0 0 0 0 0 0
56112- 0 0 0 0 0 0 0 0 0 0 0 0
56113- 0 0 0 0 0 0 0 0 0 0 0 0
56114- 0 0 0 0 0 0 0 0 0 0 0 0
56115- 0 0 1 0 0 1 0 0 1 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- 6 6 6 18 18 18 42 42 42 82 82 82
56122- 26 26 26 2 2 6 2 2 6 2 2 6
56123- 2 2 6 2 2 6 2 2 6 2 2 6
56124- 2 2 6 2 2 6 2 2 6 14 14 14
56125- 46 46 46 34 34 34 6 6 6 2 2 6
56126- 42 42 42 78 78 78 42 42 42 18 18 18
56127- 6 6 6 0 0 0 0 0 0 0 0 0
56128- 0 0 0 0 0 0 0 0 0 0 0 0
56129- 0 0 0 0 0 0 0 0 0 0 0 0
56130- 0 0 0 0 0 0 0 0 0 0 0 0
56131- 0 0 0 0 0 0 0 0 0 0 0 0
56132- 0 0 0 0 0 0 0 0 0 0 0 0
56133- 0 0 0 0 0 0 0 0 0 0 0 0
56134- 0 0 0 0 0 0 0 0 0 0 0 0
56135- 0 0 1 0 0 0 0 0 1 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- 10 10 10 30 30 30 66 66 66 58 58 58
56142- 2 2 6 2 2 6 2 2 6 2 2 6
56143- 2 2 6 2 2 6 2 2 6 2 2 6
56144- 2 2 6 2 2 6 2 2 6 26 26 26
56145- 86 86 86 101 101 101 46 46 46 10 10 10
56146- 2 2 6 58 58 58 70 70 70 34 34 34
56147- 10 10 10 0 0 0 0 0 0 0 0 0
56148- 0 0 0 0 0 0 0 0 0 0 0 0
56149- 0 0 0 0 0 0 0 0 0 0 0 0
56150- 0 0 0 0 0 0 0 0 0 0 0 0
56151- 0 0 0 0 0 0 0 0 0 0 0 0
56152- 0 0 0 0 0 0 0 0 0 0 0 0
56153- 0 0 0 0 0 0 0 0 0 0 0 0
56154- 0 0 0 0 0 0 0 0 0 0 0 0
56155- 0 0 1 0 0 1 0 0 1 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- 14 14 14 42 42 42 86 86 86 10 10 10
56162- 2 2 6 2 2 6 2 2 6 2 2 6
56163- 2 2 6 2 2 6 2 2 6 2 2 6
56164- 2 2 6 2 2 6 2 2 6 30 30 30
56165- 94 94 94 94 94 94 58 58 58 26 26 26
56166- 2 2 6 6 6 6 78 78 78 54 54 54
56167- 22 22 22 6 6 6 0 0 0 0 0 0
56168- 0 0 0 0 0 0 0 0 0 0 0 0
56169- 0 0 0 0 0 0 0 0 0 0 0 0
56170- 0 0 0 0 0 0 0 0 0 0 0 0
56171- 0 0 0 0 0 0 0 0 0 0 0 0
56172- 0 0 0 0 0 0 0 0 0 0 0 0
56173- 0 0 0 0 0 0 0 0 0 0 0 0
56174- 0 0 0 0 0 0 0 0 0 0 0 0
56175- 0 0 0 0 0 0 0 0 0 0 0 0
56176- 0 0 0 0 0 0 0 0 0 0 0 0
56177- 0 0 0 0 0 0 0 0 0 0 0 0
56178- 0 0 0 0 0 0 0 0 0 0 0 0
56179- 0 0 0 0 0 0 0 0 0 0 0 0
56180- 0 0 0 0 0 0 0 0 0 6 6 6
56181- 22 22 22 62 62 62 62 62 62 2 2 6
56182- 2 2 6 2 2 6 2 2 6 2 2 6
56183- 2 2 6 2 2 6 2 2 6 2 2 6
56184- 2 2 6 2 2 6 2 2 6 26 26 26
56185- 54 54 54 38 38 38 18 18 18 10 10 10
56186- 2 2 6 2 2 6 34 34 34 82 82 82
56187- 38 38 38 14 14 14 0 0 0 0 0 0
56188- 0 0 0 0 0 0 0 0 0 0 0 0
56189- 0 0 0 0 0 0 0 0 0 0 0 0
56190- 0 0 0 0 0 0 0 0 0 0 0 0
56191- 0 0 0 0 0 0 0 0 0 0 0 0
56192- 0 0 0 0 0 0 0 0 0 0 0 0
56193- 0 0 0 0 0 0 0 0 0 0 0 0
56194- 0 0 0 0 0 0 0 0 0 0 0 0
56195- 0 0 0 0 0 1 0 0 1 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 6 6 6
56201- 30 30 30 78 78 78 30 30 30 2 2 6
56202- 2 2 6 2 2 6 2 2 6 2 2 6
56203- 2 2 6 2 2 6 2 2 6 2 2 6
56204- 2 2 6 2 2 6 2 2 6 10 10 10
56205- 10 10 10 2 2 6 2 2 6 2 2 6
56206- 2 2 6 2 2 6 2 2 6 78 78 78
56207- 50 50 50 18 18 18 6 6 6 0 0 0
56208- 0 0 0 0 0 0 0 0 0 0 0 0
56209- 0 0 0 0 0 0 0 0 0 0 0 0
56210- 0 0 0 0 0 0 0 0 0 0 0 0
56211- 0 0 0 0 0 0 0 0 0 0 0 0
56212- 0 0 0 0 0 0 0 0 0 0 0 0
56213- 0 0 0 0 0 0 0 0 0 0 0 0
56214- 0 0 0 0 0 0 0 0 0 0 0 0
56215- 0 0 1 0 0 0 0 0 0 0 0 0
56216- 0 0 0 0 0 0 0 0 0 0 0 0
56217- 0 0 0 0 0 0 0 0 0 0 0 0
56218- 0 0 0 0 0 0 0 0 0 0 0 0
56219- 0 0 0 0 0 0 0 0 0 0 0 0
56220- 0 0 0 0 0 0 0 0 0 10 10 10
56221- 38 38 38 86 86 86 14 14 14 2 2 6
56222- 2 2 6 2 2 6 2 2 6 2 2 6
56223- 2 2 6 2 2 6 2 2 6 2 2 6
56224- 2 2 6 2 2 6 2 2 6 2 2 6
56225- 2 2 6 2 2 6 2 2 6 2 2 6
56226- 2 2 6 2 2 6 2 2 6 54 54 54
56227- 66 66 66 26 26 26 6 6 6 0 0 0
56228- 0 0 0 0 0 0 0 0 0 0 0 0
56229- 0 0 0 0 0 0 0 0 0 0 0 0
56230- 0 0 0 0 0 0 0 0 0 0 0 0
56231- 0 0 0 0 0 0 0 0 0 0 0 0
56232- 0 0 0 0 0 0 0 0 0 0 0 0
56233- 0 0 0 0 0 0 0 0 0 0 0 0
56234- 0 0 0 0 0 0 0 0 0 0 0 0
56235- 0 0 0 0 0 1 0 0 1 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 14 14 14
56241- 42 42 42 82 82 82 2 2 6 2 2 6
56242- 2 2 6 6 6 6 10 10 10 2 2 6
56243- 2 2 6 2 2 6 2 2 6 2 2 6
56244- 2 2 6 2 2 6 2 2 6 6 6 6
56245- 14 14 14 10 10 10 2 2 6 2 2 6
56246- 2 2 6 2 2 6 2 2 6 18 18 18
56247- 82 82 82 34 34 34 10 10 10 0 0 0
56248- 0 0 0 0 0 0 0 0 0 0 0 0
56249- 0 0 0 0 0 0 0 0 0 0 0 0
56250- 0 0 0 0 0 0 0 0 0 0 0 0
56251- 0 0 0 0 0 0 0 0 0 0 0 0
56252- 0 0 0 0 0 0 0 0 0 0 0 0
56253- 0 0 0 0 0 0 0 0 0 0 0 0
56254- 0 0 0 0 0 0 0 0 0 0 0 0
56255- 0 0 1 0 0 0 0 0 0 0 0 0
56256- 0 0 0 0 0 0 0 0 0 0 0 0
56257- 0 0 0 0 0 0 0 0 0 0 0 0
56258- 0 0 0 0 0 0 0 0 0 0 0 0
56259- 0 0 0 0 0 0 0 0 0 0 0 0
56260- 0 0 0 0 0 0 0 0 0 14 14 14
56261- 46 46 46 86 86 86 2 2 6 2 2 6
56262- 6 6 6 6 6 6 22 22 22 34 34 34
56263- 6 6 6 2 2 6 2 2 6 2 2 6
56264- 2 2 6 2 2 6 18 18 18 34 34 34
56265- 10 10 10 50 50 50 22 22 22 2 2 6
56266- 2 2 6 2 2 6 2 2 6 10 10 10
56267- 86 86 86 42 42 42 14 14 14 0 0 0
56268- 0 0 0 0 0 0 0 0 0 0 0 0
56269- 0 0 0 0 0 0 0 0 0 0 0 0
56270- 0 0 0 0 0 0 0 0 0 0 0 0
56271- 0 0 0 0 0 0 0 0 0 0 0 0
56272- 0 0 0 0 0 0 0 0 0 0 0 0
56273- 0 0 0 0 0 0 0 0 0 0 0 0
56274- 0 0 0 0 0 0 0 0 0 0 0 0
56275- 0 0 1 0 0 1 0 0 1 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 14 14 14
56281- 46 46 46 86 86 86 2 2 6 2 2 6
56282- 38 38 38 116 116 116 94 94 94 22 22 22
56283- 22 22 22 2 2 6 2 2 6 2 2 6
56284- 14 14 14 86 86 86 138 138 138 162 162 162
56285-154 154 154 38 38 38 26 26 26 6 6 6
56286- 2 2 6 2 2 6 2 2 6 2 2 6
56287- 86 86 86 46 46 46 14 14 14 0 0 0
56288- 0 0 0 0 0 0 0 0 0 0 0 0
56289- 0 0 0 0 0 0 0 0 0 0 0 0
56290- 0 0 0 0 0 0 0 0 0 0 0 0
56291- 0 0 0 0 0 0 0 0 0 0 0 0
56292- 0 0 0 0 0 0 0 0 0 0 0 0
56293- 0 0 0 0 0 0 0 0 0 0 0 0
56294- 0 0 0 0 0 0 0 0 0 0 0 0
56295- 0 0 0 0 0 0 0 0 0 0 0 0
56296- 0 0 0 0 0 0 0 0 0 0 0 0
56297- 0 0 0 0 0 0 0 0 0 0 0 0
56298- 0 0 0 0 0 0 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 14 14 14
56301- 46 46 46 86 86 86 2 2 6 14 14 14
56302-134 134 134 198 198 198 195 195 195 116 116 116
56303- 10 10 10 2 2 6 2 2 6 6 6 6
56304-101 98 89 187 187 187 210 210 210 218 218 218
56305-214 214 214 134 134 134 14 14 14 6 6 6
56306- 2 2 6 2 2 6 2 2 6 2 2 6
56307- 86 86 86 50 50 50 18 18 18 6 6 6
56308- 0 0 0 0 0 0 0 0 0 0 0 0
56309- 0 0 0 0 0 0 0 0 0 0 0 0
56310- 0 0 0 0 0 0 0 0 0 0 0 0
56311- 0 0 0 0 0 0 0 0 0 0 0 0
56312- 0 0 0 0 0 0 0 0 0 0 0 0
56313- 0 0 0 0 0 0 0 0 0 0 0 0
56314- 0 0 0 0 0 0 0 0 1 0 0 0
56315- 0 0 1 0 0 1 0 0 1 0 0 0
56316- 0 0 0 0 0 0 0 0 0 0 0 0
56317- 0 0 0 0 0 0 0 0 0 0 0 0
56318- 0 0 0 0 0 0 0 0 0 0 0 0
56319- 0 0 0 0 0 0 0 0 0 0 0 0
56320- 0 0 0 0 0 0 0 0 0 14 14 14
56321- 46 46 46 86 86 86 2 2 6 54 54 54
56322-218 218 218 195 195 195 226 226 226 246 246 246
56323- 58 58 58 2 2 6 2 2 6 30 30 30
56324-210 210 210 253 253 253 174 174 174 123 123 123
56325-221 221 221 234 234 234 74 74 74 2 2 6
56326- 2 2 6 2 2 6 2 2 6 2 2 6
56327- 70 70 70 58 58 58 22 22 22 6 6 6
56328- 0 0 0 0 0 0 0 0 0 0 0 0
56329- 0 0 0 0 0 0 0 0 0 0 0 0
56330- 0 0 0 0 0 0 0 0 0 0 0 0
56331- 0 0 0 0 0 0 0 0 0 0 0 0
56332- 0 0 0 0 0 0 0 0 0 0 0 0
56333- 0 0 0 0 0 0 0 0 0 0 0 0
56334- 0 0 0 0 0 0 0 0 0 0 0 0
56335- 0 0 0 0 0 0 0 0 0 0 0 0
56336- 0 0 0 0 0 0 0 0 0 0 0 0
56337- 0 0 0 0 0 0 0 0 0 0 0 0
56338- 0 0 0 0 0 0 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 14 14 14
56341- 46 46 46 82 82 82 2 2 6 106 106 106
56342-170 170 170 26 26 26 86 86 86 226 226 226
56343-123 123 123 10 10 10 14 14 14 46 46 46
56344-231 231 231 190 190 190 6 6 6 70 70 70
56345- 90 90 90 238 238 238 158 158 158 2 2 6
56346- 2 2 6 2 2 6 2 2 6 2 2 6
56347- 70 70 70 58 58 58 22 22 22 6 6 6
56348- 0 0 0 0 0 0 0 0 0 0 0 0
56349- 0 0 0 0 0 0 0 0 0 0 0 0
56350- 0 0 0 0 0 0 0 0 0 0 0 0
56351- 0 0 0 0 0 0 0 0 0 0 0 0
56352- 0 0 0 0 0 0 0 0 0 0 0 0
56353- 0 0 0 0 0 0 0 0 0 0 0 0
56354- 0 0 0 0 0 0 0 0 1 0 0 0
56355- 0 0 1 0 0 1 0 0 1 0 0 0
56356- 0 0 0 0 0 0 0 0 0 0 0 0
56357- 0 0 0 0 0 0 0 0 0 0 0 0
56358- 0 0 0 0 0 0 0 0 0 0 0 0
56359- 0 0 0 0 0 0 0 0 0 0 0 0
56360- 0 0 0 0 0 0 0 0 0 14 14 14
56361- 42 42 42 86 86 86 6 6 6 116 116 116
56362-106 106 106 6 6 6 70 70 70 149 149 149
56363-128 128 128 18 18 18 38 38 38 54 54 54
56364-221 221 221 106 106 106 2 2 6 14 14 14
56365- 46 46 46 190 190 190 198 198 198 2 2 6
56366- 2 2 6 2 2 6 2 2 6 2 2 6
56367- 74 74 74 62 62 62 22 22 22 6 6 6
56368- 0 0 0 0 0 0 0 0 0 0 0 0
56369- 0 0 0 0 0 0 0 0 0 0 0 0
56370- 0 0 0 0 0 0 0 0 0 0 0 0
56371- 0 0 0 0 0 0 0 0 0 0 0 0
56372- 0 0 0 0 0 0 0 0 0 0 0 0
56373- 0 0 0 0 0 0 0 0 0 0 0 0
56374- 0 0 0 0 0 0 0 0 1 0 0 0
56375- 0 0 1 0 0 0 0 0 1 0 0 0
56376- 0 0 0 0 0 0 0 0 0 0 0 0
56377- 0 0 0 0 0 0 0 0 0 0 0 0
56378- 0 0 0 0 0 0 0 0 0 0 0 0
56379- 0 0 0 0 0 0 0 0 0 0 0 0
56380- 0 0 0 0 0 0 0 0 0 14 14 14
56381- 42 42 42 94 94 94 14 14 14 101 101 101
56382-128 128 128 2 2 6 18 18 18 116 116 116
56383-118 98 46 121 92 8 121 92 8 98 78 10
56384-162 162 162 106 106 106 2 2 6 2 2 6
56385- 2 2 6 195 195 195 195 195 195 6 6 6
56386- 2 2 6 2 2 6 2 2 6 2 2 6
56387- 74 74 74 62 62 62 22 22 22 6 6 6
56388- 0 0 0 0 0 0 0 0 0 0 0 0
56389- 0 0 0 0 0 0 0 0 0 0 0 0
56390- 0 0 0 0 0 0 0 0 0 0 0 0
56391- 0 0 0 0 0 0 0 0 0 0 0 0
56392- 0 0 0 0 0 0 0 0 0 0 0 0
56393- 0 0 0 0 0 0 0 0 0 0 0 0
56394- 0 0 0 0 0 0 0 0 1 0 0 1
56395- 0 0 1 0 0 0 0 0 1 0 0 0
56396- 0 0 0 0 0 0 0 0 0 0 0 0
56397- 0 0 0 0 0 0 0 0 0 0 0 0
56398- 0 0 0 0 0 0 0 0 0 0 0 0
56399- 0 0 0 0 0 0 0 0 0 0 0 0
56400- 0 0 0 0 0 0 0 0 0 10 10 10
56401- 38 38 38 90 90 90 14 14 14 58 58 58
56402-210 210 210 26 26 26 54 38 6 154 114 10
56403-226 170 11 236 186 11 225 175 15 184 144 12
56404-215 174 15 175 146 61 37 26 9 2 2 6
56405- 70 70 70 246 246 246 138 138 138 2 2 6
56406- 2 2 6 2 2 6 2 2 6 2 2 6
56407- 70 70 70 66 66 66 26 26 26 6 6 6
56408- 0 0 0 0 0 0 0 0 0 0 0 0
56409- 0 0 0 0 0 0 0 0 0 0 0 0
56410- 0 0 0 0 0 0 0 0 0 0 0 0
56411- 0 0 0 0 0 0 0 0 0 0 0 0
56412- 0 0 0 0 0 0 0 0 0 0 0 0
56413- 0 0 0 0 0 0 0 0 0 0 0 0
56414- 0 0 0 0 0 0 0 0 0 0 0 0
56415- 0 0 0 0 0 0 0 0 0 0 0 0
56416- 0 0 0 0 0 0 0 0 0 0 0 0
56417- 0 0 0 0 0 0 0 0 0 0 0 0
56418- 0 0 0 0 0 0 0 0 0 0 0 0
56419- 0 0 0 0 0 0 0 0 0 0 0 0
56420- 0 0 0 0 0 0 0 0 0 10 10 10
56421- 38 38 38 86 86 86 14 14 14 10 10 10
56422-195 195 195 188 164 115 192 133 9 225 175 15
56423-239 182 13 234 190 10 232 195 16 232 200 30
56424-245 207 45 241 208 19 232 195 16 184 144 12
56425-218 194 134 211 206 186 42 42 42 2 2 6
56426- 2 2 6 2 2 6 2 2 6 2 2 6
56427- 50 50 50 74 74 74 30 30 30 6 6 6
56428- 0 0 0 0 0 0 0 0 0 0 0 0
56429- 0 0 0 0 0 0 0 0 0 0 0 0
56430- 0 0 0 0 0 0 0 0 0 0 0 0
56431- 0 0 0 0 0 0 0 0 0 0 0 0
56432- 0 0 0 0 0 0 0 0 0 0 0 0
56433- 0 0 0 0 0 0 0 0 0 0 0 0
56434- 0 0 0 0 0 0 0 0 0 0 0 0
56435- 0 0 0 0 0 0 0 0 0 0 0 0
56436- 0 0 0 0 0 0 0 0 0 0 0 0
56437- 0 0 0 0 0 0 0 0 0 0 0 0
56438- 0 0 0 0 0 0 0 0 0 0 0 0
56439- 0 0 0 0 0 0 0 0 0 0 0 0
56440- 0 0 0 0 0 0 0 0 0 10 10 10
56441- 34 34 34 86 86 86 14 14 14 2 2 6
56442-121 87 25 192 133 9 219 162 10 239 182 13
56443-236 186 11 232 195 16 241 208 19 244 214 54
56444-246 218 60 246 218 38 246 215 20 241 208 19
56445-241 208 19 226 184 13 121 87 25 2 2 6
56446- 2 2 6 2 2 6 2 2 6 2 2 6
56447- 50 50 50 82 82 82 34 34 34 10 10 10
56448- 0 0 0 0 0 0 0 0 0 0 0 0
56449- 0 0 0 0 0 0 0 0 0 0 0 0
56450- 0 0 0 0 0 0 0 0 0 0 0 0
56451- 0 0 0 0 0 0 0 0 0 0 0 0
56452- 0 0 0 0 0 0 0 0 0 0 0 0
56453- 0 0 0 0 0 0 0 0 0 0 0 0
56454- 0 0 0 0 0 0 0 0 0 0 0 0
56455- 0 0 0 0 0 0 0 0 0 0 0 0
56456- 0 0 0 0 0 0 0 0 0 0 0 0
56457- 0 0 0 0 0 0 0 0 0 0 0 0
56458- 0 0 0 0 0 0 0 0 0 0 0 0
56459- 0 0 0 0 0 0 0 0 0 0 0 0
56460- 0 0 0 0 0 0 0 0 0 10 10 10
56461- 34 34 34 82 82 82 30 30 30 61 42 6
56462-180 123 7 206 145 10 230 174 11 239 182 13
56463-234 190 10 238 202 15 241 208 19 246 218 74
56464-246 218 38 246 215 20 246 215 20 246 215 20
56465-226 184 13 215 174 15 184 144 12 6 6 6
56466- 2 2 6 2 2 6 2 2 6 2 2 6
56467- 26 26 26 94 94 94 42 42 42 14 14 14
56468- 0 0 0 0 0 0 0 0 0 0 0 0
56469- 0 0 0 0 0 0 0 0 0 0 0 0
56470- 0 0 0 0 0 0 0 0 0 0 0 0
56471- 0 0 0 0 0 0 0 0 0 0 0 0
56472- 0 0 0 0 0 0 0 0 0 0 0 0
56473- 0 0 0 0 0 0 0 0 0 0 0 0
56474- 0 0 0 0 0 0 0 0 0 0 0 0
56475- 0 0 0 0 0 0 0 0 0 0 0 0
56476- 0 0 0 0 0 0 0 0 0 0 0 0
56477- 0 0 0 0 0 0 0 0 0 0 0 0
56478- 0 0 0 0 0 0 0 0 0 0 0 0
56479- 0 0 0 0 0 0 0 0 0 0 0 0
56480- 0 0 0 0 0 0 0 0 0 10 10 10
56481- 30 30 30 78 78 78 50 50 50 104 69 6
56482-192 133 9 216 158 10 236 178 12 236 186 11
56483-232 195 16 241 208 19 244 214 54 245 215 43
56484-246 215 20 246 215 20 241 208 19 198 155 10
56485-200 144 11 216 158 10 156 118 10 2 2 6
56486- 2 2 6 2 2 6 2 2 6 2 2 6
56487- 6 6 6 90 90 90 54 54 54 18 18 18
56488- 6 6 6 0 0 0 0 0 0 0 0 0
56489- 0 0 0 0 0 0 0 0 0 0 0 0
56490- 0 0 0 0 0 0 0 0 0 0 0 0
56491- 0 0 0 0 0 0 0 0 0 0 0 0
56492- 0 0 0 0 0 0 0 0 0 0 0 0
56493- 0 0 0 0 0 0 0 0 0 0 0 0
56494- 0 0 0 0 0 0 0 0 0 0 0 0
56495- 0 0 0 0 0 0 0 0 0 0 0 0
56496- 0 0 0 0 0 0 0 0 0 0 0 0
56497- 0 0 0 0 0 0 0 0 0 0 0 0
56498- 0 0 0 0 0 0 0 0 0 0 0 0
56499- 0 0 0 0 0 0 0 0 0 0 0 0
56500- 0 0 0 0 0 0 0 0 0 10 10 10
56501- 30 30 30 78 78 78 46 46 46 22 22 22
56502-137 92 6 210 162 10 239 182 13 238 190 10
56503-238 202 15 241 208 19 246 215 20 246 215 20
56504-241 208 19 203 166 17 185 133 11 210 150 10
56505-216 158 10 210 150 10 102 78 10 2 2 6
56506- 6 6 6 54 54 54 14 14 14 2 2 6
56507- 2 2 6 62 62 62 74 74 74 30 30 30
56508- 10 10 10 0 0 0 0 0 0 0 0 0
56509- 0 0 0 0 0 0 0 0 0 0 0 0
56510- 0 0 0 0 0 0 0 0 0 0 0 0
56511- 0 0 0 0 0 0 0 0 0 0 0 0
56512- 0 0 0 0 0 0 0 0 0 0 0 0
56513- 0 0 0 0 0 0 0 0 0 0 0 0
56514- 0 0 0 0 0 0 0 0 0 0 0 0
56515- 0 0 0 0 0 0 0 0 0 0 0 0
56516- 0 0 0 0 0 0 0 0 0 0 0 0
56517- 0 0 0 0 0 0 0 0 0 0 0 0
56518- 0 0 0 0 0 0 0 0 0 0 0 0
56519- 0 0 0 0 0 0 0 0 0 0 0 0
56520- 0 0 0 0 0 0 0 0 0 10 10 10
56521- 34 34 34 78 78 78 50 50 50 6 6 6
56522- 94 70 30 139 102 15 190 146 13 226 184 13
56523-232 200 30 232 195 16 215 174 15 190 146 13
56524-168 122 10 192 133 9 210 150 10 213 154 11
56525-202 150 34 182 157 106 101 98 89 2 2 6
56526- 2 2 6 78 78 78 116 116 116 58 58 58
56527- 2 2 6 22 22 22 90 90 90 46 46 46
56528- 18 18 18 6 6 6 0 0 0 0 0 0
56529- 0 0 0 0 0 0 0 0 0 0 0 0
56530- 0 0 0 0 0 0 0 0 0 0 0 0
56531- 0 0 0 0 0 0 0 0 0 0 0 0
56532- 0 0 0 0 0 0 0 0 0 0 0 0
56533- 0 0 0 0 0 0 0 0 0 0 0 0
56534- 0 0 0 0 0 0 0 0 0 0 0 0
56535- 0 0 0 0 0 0 0 0 0 0 0 0
56536- 0 0 0 0 0 0 0 0 0 0 0 0
56537- 0 0 0 0 0 0 0 0 0 0 0 0
56538- 0 0 0 0 0 0 0 0 0 0 0 0
56539- 0 0 0 0 0 0 0 0 0 0 0 0
56540- 0 0 0 0 0 0 0 0 0 10 10 10
56541- 38 38 38 86 86 86 50 50 50 6 6 6
56542-128 128 128 174 154 114 156 107 11 168 122 10
56543-198 155 10 184 144 12 197 138 11 200 144 11
56544-206 145 10 206 145 10 197 138 11 188 164 115
56545-195 195 195 198 198 198 174 174 174 14 14 14
56546- 2 2 6 22 22 22 116 116 116 116 116 116
56547- 22 22 22 2 2 6 74 74 74 70 70 70
56548- 30 30 30 10 10 10 0 0 0 0 0 0
56549- 0 0 0 0 0 0 0 0 0 0 0 0
56550- 0 0 0 0 0 0 0 0 0 0 0 0
56551- 0 0 0 0 0 0 0 0 0 0 0 0
56552- 0 0 0 0 0 0 0 0 0 0 0 0
56553- 0 0 0 0 0 0 0 0 0 0 0 0
56554- 0 0 0 0 0 0 0 0 0 0 0 0
56555- 0 0 0 0 0 0 0 0 0 0 0 0
56556- 0 0 0 0 0 0 0 0 0 0 0 0
56557- 0 0 0 0 0 0 0 0 0 0 0 0
56558- 0 0 0 0 0 0 0 0 0 0 0 0
56559- 0 0 0 0 0 0 0 0 0 0 0 0
56560- 0 0 0 0 0 0 6 6 6 18 18 18
56561- 50 50 50 101 101 101 26 26 26 10 10 10
56562-138 138 138 190 190 190 174 154 114 156 107 11
56563-197 138 11 200 144 11 197 138 11 192 133 9
56564-180 123 7 190 142 34 190 178 144 187 187 187
56565-202 202 202 221 221 221 214 214 214 66 66 66
56566- 2 2 6 2 2 6 50 50 50 62 62 62
56567- 6 6 6 2 2 6 10 10 10 90 90 90
56568- 50 50 50 18 18 18 6 6 6 0 0 0
56569- 0 0 0 0 0 0 0 0 0 0 0 0
56570- 0 0 0 0 0 0 0 0 0 0 0 0
56571- 0 0 0 0 0 0 0 0 0 0 0 0
56572- 0 0 0 0 0 0 0 0 0 0 0 0
56573- 0 0 0 0 0 0 0 0 0 0 0 0
56574- 0 0 0 0 0 0 0 0 0 0 0 0
56575- 0 0 0 0 0 0 0 0 0 0 0 0
56576- 0 0 0 0 0 0 0 0 0 0 0 0
56577- 0 0 0 0 0 0 0 0 0 0 0 0
56578- 0 0 0 0 0 0 0 0 0 0 0 0
56579- 0 0 0 0 0 0 0 0 0 0 0 0
56580- 0 0 0 0 0 0 10 10 10 34 34 34
56581- 74 74 74 74 74 74 2 2 6 6 6 6
56582-144 144 144 198 198 198 190 190 190 178 166 146
56583-154 121 60 156 107 11 156 107 11 168 124 44
56584-174 154 114 187 187 187 190 190 190 210 210 210
56585-246 246 246 253 253 253 253 253 253 182 182 182
56586- 6 6 6 2 2 6 2 2 6 2 2 6
56587- 2 2 6 2 2 6 2 2 6 62 62 62
56588- 74 74 74 34 34 34 14 14 14 0 0 0
56589- 0 0 0 0 0 0 0 0 0 0 0 0
56590- 0 0 0 0 0 0 0 0 0 0 0 0
56591- 0 0 0 0 0 0 0 0 0 0 0 0
56592- 0 0 0 0 0 0 0 0 0 0 0 0
56593- 0 0 0 0 0 0 0 0 0 0 0 0
56594- 0 0 0 0 0 0 0 0 0 0 0 0
56595- 0 0 0 0 0 0 0 0 0 0 0 0
56596- 0 0 0 0 0 0 0 0 0 0 0 0
56597- 0 0 0 0 0 0 0 0 0 0 0 0
56598- 0 0 0 0 0 0 0 0 0 0 0 0
56599- 0 0 0 0 0 0 0 0 0 0 0 0
56600- 0 0 0 10 10 10 22 22 22 54 54 54
56601- 94 94 94 18 18 18 2 2 6 46 46 46
56602-234 234 234 221 221 221 190 190 190 190 190 190
56603-190 190 190 187 187 187 187 187 187 190 190 190
56604-190 190 190 195 195 195 214 214 214 242 242 242
56605-253 253 253 253 253 253 253 253 253 253 253 253
56606- 82 82 82 2 2 6 2 2 6 2 2 6
56607- 2 2 6 2 2 6 2 2 6 14 14 14
56608- 86 86 86 54 54 54 22 22 22 6 6 6
56609- 0 0 0 0 0 0 0 0 0 0 0 0
56610- 0 0 0 0 0 0 0 0 0 0 0 0
56611- 0 0 0 0 0 0 0 0 0 0 0 0
56612- 0 0 0 0 0 0 0 0 0 0 0 0
56613- 0 0 0 0 0 0 0 0 0 0 0 0
56614- 0 0 0 0 0 0 0 0 0 0 0 0
56615- 0 0 0 0 0 0 0 0 0 0 0 0
56616- 0 0 0 0 0 0 0 0 0 0 0 0
56617- 0 0 0 0 0 0 0 0 0 0 0 0
56618- 0 0 0 0 0 0 0 0 0 0 0 0
56619- 0 0 0 0 0 0 0 0 0 0 0 0
56620- 6 6 6 18 18 18 46 46 46 90 90 90
56621- 46 46 46 18 18 18 6 6 6 182 182 182
56622-253 253 253 246 246 246 206 206 206 190 190 190
56623-190 190 190 190 190 190 190 190 190 190 190 190
56624-206 206 206 231 231 231 250 250 250 253 253 253
56625-253 253 253 253 253 253 253 253 253 253 253 253
56626-202 202 202 14 14 14 2 2 6 2 2 6
56627- 2 2 6 2 2 6 2 2 6 2 2 6
56628- 42 42 42 86 86 86 42 42 42 18 18 18
56629- 6 6 6 0 0 0 0 0 0 0 0 0
56630- 0 0 0 0 0 0 0 0 0 0 0 0
56631- 0 0 0 0 0 0 0 0 0 0 0 0
56632- 0 0 0 0 0 0 0 0 0 0 0 0
56633- 0 0 0 0 0 0 0 0 0 0 0 0
56634- 0 0 0 0 0 0 0 0 0 0 0 0
56635- 0 0 0 0 0 0 0 0 0 0 0 0
56636- 0 0 0 0 0 0 0 0 0 0 0 0
56637- 0 0 0 0 0 0 0 0 0 0 0 0
56638- 0 0 0 0 0 0 0 0 0 0 0 0
56639- 0 0 0 0 0 0 0 0 0 6 6 6
56640- 14 14 14 38 38 38 74 74 74 66 66 66
56641- 2 2 6 6 6 6 90 90 90 250 250 250
56642-253 253 253 253 253 253 238 238 238 198 198 198
56643-190 190 190 190 190 190 195 195 195 221 221 221
56644-246 246 246 253 253 253 253 253 253 253 253 253
56645-253 253 253 253 253 253 253 253 253 253 253 253
56646-253 253 253 82 82 82 2 2 6 2 2 6
56647- 2 2 6 2 2 6 2 2 6 2 2 6
56648- 2 2 6 78 78 78 70 70 70 34 34 34
56649- 14 14 14 6 6 6 0 0 0 0 0 0
56650- 0 0 0 0 0 0 0 0 0 0 0 0
56651- 0 0 0 0 0 0 0 0 0 0 0 0
56652- 0 0 0 0 0 0 0 0 0 0 0 0
56653- 0 0 0 0 0 0 0 0 0 0 0 0
56654- 0 0 0 0 0 0 0 0 0 0 0 0
56655- 0 0 0 0 0 0 0 0 0 0 0 0
56656- 0 0 0 0 0 0 0 0 0 0 0 0
56657- 0 0 0 0 0 0 0 0 0 0 0 0
56658- 0 0 0 0 0 0 0 0 0 0 0 0
56659- 0 0 0 0 0 0 0 0 0 14 14 14
56660- 34 34 34 66 66 66 78 78 78 6 6 6
56661- 2 2 6 18 18 18 218 218 218 253 253 253
56662-253 253 253 253 253 253 253 253 253 246 246 246
56663-226 226 226 231 231 231 246 246 246 253 253 253
56664-253 253 253 253 253 253 253 253 253 253 253 253
56665-253 253 253 253 253 253 253 253 253 253 253 253
56666-253 253 253 178 178 178 2 2 6 2 2 6
56667- 2 2 6 2 2 6 2 2 6 2 2 6
56668- 2 2 6 18 18 18 90 90 90 62 62 62
56669- 30 30 30 10 10 10 0 0 0 0 0 0
56670- 0 0 0 0 0 0 0 0 0 0 0 0
56671- 0 0 0 0 0 0 0 0 0 0 0 0
56672- 0 0 0 0 0 0 0 0 0 0 0 0
56673- 0 0 0 0 0 0 0 0 0 0 0 0
56674- 0 0 0 0 0 0 0 0 0 0 0 0
56675- 0 0 0 0 0 0 0 0 0 0 0 0
56676- 0 0 0 0 0 0 0 0 0 0 0 0
56677- 0 0 0 0 0 0 0 0 0 0 0 0
56678- 0 0 0 0 0 0 0 0 0 0 0 0
56679- 0 0 0 0 0 0 10 10 10 26 26 26
56680- 58 58 58 90 90 90 18 18 18 2 2 6
56681- 2 2 6 110 110 110 253 253 253 253 253 253
56682-253 253 253 253 253 253 253 253 253 253 253 253
56683-250 250 250 253 253 253 253 253 253 253 253 253
56684-253 253 253 253 253 253 253 253 253 253 253 253
56685-253 253 253 253 253 253 253 253 253 253 253 253
56686-253 253 253 231 231 231 18 18 18 2 2 6
56687- 2 2 6 2 2 6 2 2 6 2 2 6
56688- 2 2 6 2 2 6 18 18 18 94 94 94
56689- 54 54 54 26 26 26 10 10 10 0 0 0
56690- 0 0 0 0 0 0 0 0 0 0 0 0
56691- 0 0 0 0 0 0 0 0 0 0 0 0
56692- 0 0 0 0 0 0 0 0 0 0 0 0
56693- 0 0 0 0 0 0 0 0 0 0 0 0
56694- 0 0 0 0 0 0 0 0 0 0 0 0
56695- 0 0 0 0 0 0 0 0 0 0 0 0
56696- 0 0 0 0 0 0 0 0 0 0 0 0
56697- 0 0 0 0 0 0 0 0 0 0 0 0
56698- 0 0 0 0 0 0 0 0 0 0 0 0
56699- 0 0 0 6 6 6 22 22 22 50 50 50
56700- 90 90 90 26 26 26 2 2 6 2 2 6
56701- 14 14 14 195 195 195 250 250 250 253 253 253
56702-253 253 253 253 253 253 253 253 253 253 253 253
56703-253 253 253 253 253 253 253 253 253 253 253 253
56704-253 253 253 253 253 253 253 253 253 253 253 253
56705-253 253 253 253 253 253 253 253 253 253 253 253
56706-250 250 250 242 242 242 54 54 54 2 2 6
56707- 2 2 6 2 2 6 2 2 6 2 2 6
56708- 2 2 6 2 2 6 2 2 6 38 38 38
56709- 86 86 86 50 50 50 22 22 22 6 6 6
56710- 0 0 0 0 0 0 0 0 0 0 0 0
56711- 0 0 0 0 0 0 0 0 0 0 0 0
56712- 0 0 0 0 0 0 0 0 0 0 0 0
56713- 0 0 0 0 0 0 0 0 0 0 0 0
56714- 0 0 0 0 0 0 0 0 0 0 0 0
56715- 0 0 0 0 0 0 0 0 0 0 0 0
56716- 0 0 0 0 0 0 0 0 0 0 0 0
56717- 0 0 0 0 0 0 0 0 0 0 0 0
56718- 0 0 0 0 0 0 0 0 0 0 0 0
56719- 6 6 6 14 14 14 38 38 38 82 82 82
56720- 34 34 34 2 2 6 2 2 6 2 2 6
56721- 42 42 42 195 195 195 246 246 246 253 253 253
56722-253 253 253 253 253 253 253 253 253 250 250 250
56723-242 242 242 242 242 242 250 250 250 253 253 253
56724-253 253 253 253 253 253 253 253 253 253 253 253
56725-253 253 253 250 250 250 246 246 246 238 238 238
56726-226 226 226 231 231 231 101 101 101 6 6 6
56727- 2 2 6 2 2 6 2 2 6 2 2 6
56728- 2 2 6 2 2 6 2 2 6 2 2 6
56729- 38 38 38 82 82 82 42 42 42 14 14 14
56730- 6 6 6 0 0 0 0 0 0 0 0 0
56731- 0 0 0 0 0 0 0 0 0 0 0 0
56732- 0 0 0 0 0 0 0 0 0 0 0 0
56733- 0 0 0 0 0 0 0 0 0 0 0 0
56734- 0 0 0 0 0 0 0 0 0 0 0 0
56735- 0 0 0 0 0 0 0 0 0 0 0 0
56736- 0 0 0 0 0 0 0 0 0 0 0 0
56737- 0 0 0 0 0 0 0 0 0 0 0 0
56738- 0 0 0 0 0 0 0 0 0 0 0 0
56739- 10 10 10 26 26 26 62 62 62 66 66 66
56740- 2 2 6 2 2 6 2 2 6 6 6 6
56741- 70 70 70 170 170 170 206 206 206 234 234 234
56742-246 246 246 250 250 250 250 250 250 238 238 238
56743-226 226 226 231 231 231 238 238 238 250 250 250
56744-250 250 250 250 250 250 246 246 246 231 231 231
56745-214 214 214 206 206 206 202 202 202 202 202 202
56746-198 198 198 202 202 202 182 182 182 18 18 18
56747- 2 2 6 2 2 6 2 2 6 2 2 6
56748- 2 2 6 2 2 6 2 2 6 2 2 6
56749- 2 2 6 62 62 62 66 66 66 30 30 30
56750- 10 10 10 0 0 0 0 0 0 0 0 0
56751- 0 0 0 0 0 0 0 0 0 0 0 0
56752- 0 0 0 0 0 0 0 0 0 0 0 0
56753- 0 0 0 0 0 0 0 0 0 0 0 0
56754- 0 0 0 0 0 0 0 0 0 0 0 0
56755- 0 0 0 0 0 0 0 0 0 0 0 0
56756- 0 0 0 0 0 0 0 0 0 0 0 0
56757- 0 0 0 0 0 0 0 0 0 0 0 0
56758- 0 0 0 0 0 0 0 0 0 0 0 0
56759- 14 14 14 42 42 42 82 82 82 18 18 18
56760- 2 2 6 2 2 6 2 2 6 10 10 10
56761- 94 94 94 182 182 182 218 218 218 242 242 242
56762-250 250 250 253 253 253 253 253 253 250 250 250
56763-234 234 234 253 253 253 253 253 253 253 253 253
56764-253 253 253 253 253 253 253 253 253 246 246 246
56765-238 238 238 226 226 226 210 210 210 202 202 202
56766-195 195 195 195 195 195 210 210 210 158 158 158
56767- 6 6 6 14 14 14 50 50 50 14 14 14
56768- 2 2 6 2 2 6 2 2 6 2 2 6
56769- 2 2 6 6 6 6 86 86 86 46 46 46
56770- 18 18 18 6 6 6 0 0 0 0 0 0
56771- 0 0 0 0 0 0 0 0 0 0 0 0
56772- 0 0 0 0 0 0 0 0 0 0 0 0
56773- 0 0 0 0 0 0 0 0 0 0 0 0
56774- 0 0 0 0 0 0 0 0 0 0 0 0
56775- 0 0 0 0 0 0 0 0 0 0 0 0
56776- 0 0 0 0 0 0 0 0 0 0 0 0
56777- 0 0 0 0 0 0 0 0 0 0 0 0
56778- 0 0 0 0 0 0 0 0 0 6 6 6
56779- 22 22 22 54 54 54 70 70 70 2 2 6
56780- 2 2 6 10 10 10 2 2 6 22 22 22
56781-166 166 166 231 231 231 250 250 250 253 253 253
56782-253 253 253 253 253 253 253 253 253 250 250 250
56783-242 242 242 253 253 253 253 253 253 253 253 253
56784-253 253 253 253 253 253 253 253 253 253 253 253
56785-253 253 253 253 253 253 253 253 253 246 246 246
56786-231 231 231 206 206 206 198 198 198 226 226 226
56787- 94 94 94 2 2 6 6 6 6 38 38 38
56788- 30 30 30 2 2 6 2 2 6 2 2 6
56789- 2 2 6 2 2 6 62 62 62 66 66 66
56790- 26 26 26 10 10 10 0 0 0 0 0 0
56791- 0 0 0 0 0 0 0 0 0 0 0 0
56792- 0 0 0 0 0 0 0 0 0 0 0 0
56793- 0 0 0 0 0 0 0 0 0 0 0 0
56794- 0 0 0 0 0 0 0 0 0 0 0 0
56795- 0 0 0 0 0 0 0 0 0 0 0 0
56796- 0 0 0 0 0 0 0 0 0 0 0 0
56797- 0 0 0 0 0 0 0 0 0 0 0 0
56798- 0 0 0 0 0 0 0 0 0 10 10 10
56799- 30 30 30 74 74 74 50 50 50 2 2 6
56800- 26 26 26 26 26 26 2 2 6 106 106 106
56801-238 238 238 253 253 253 253 253 253 253 253 253
56802-253 253 253 253 253 253 253 253 253 253 253 253
56803-253 253 253 253 253 253 253 253 253 253 253 253
56804-253 253 253 253 253 253 253 253 253 253 253 253
56805-253 253 253 253 253 253 253 253 253 253 253 253
56806-253 253 253 246 246 246 218 218 218 202 202 202
56807-210 210 210 14 14 14 2 2 6 2 2 6
56808- 30 30 30 22 22 22 2 2 6 2 2 6
56809- 2 2 6 2 2 6 18 18 18 86 86 86
56810- 42 42 42 14 14 14 0 0 0 0 0 0
56811- 0 0 0 0 0 0 0 0 0 0 0 0
56812- 0 0 0 0 0 0 0 0 0 0 0 0
56813- 0 0 0 0 0 0 0 0 0 0 0 0
56814- 0 0 0 0 0 0 0 0 0 0 0 0
56815- 0 0 0 0 0 0 0 0 0 0 0 0
56816- 0 0 0 0 0 0 0 0 0 0 0 0
56817- 0 0 0 0 0 0 0 0 0 0 0 0
56818- 0 0 0 0 0 0 0 0 0 14 14 14
56819- 42 42 42 90 90 90 22 22 22 2 2 6
56820- 42 42 42 2 2 6 18 18 18 218 218 218
56821-253 253 253 253 253 253 253 253 253 253 253 253
56822-253 253 253 253 253 253 253 253 253 253 253 253
56823-253 253 253 253 253 253 253 253 253 253 253 253
56824-253 253 253 253 253 253 253 253 253 253 253 253
56825-253 253 253 253 253 253 253 253 253 253 253 253
56826-253 253 253 253 253 253 250 250 250 221 221 221
56827-218 218 218 101 101 101 2 2 6 14 14 14
56828- 18 18 18 38 38 38 10 10 10 2 2 6
56829- 2 2 6 2 2 6 2 2 6 78 78 78
56830- 58 58 58 22 22 22 6 6 6 0 0 0
56831- 0 0 0 0 0 0 0 0 0 0 0 0
56832- 0 0 0 0 0 0 0 0 0 0 0 0
56833- 0 0 0 0 0 0 0 0 0 0 0 0
56834- 0 0 0 0 0 0 0 0 0 0 0 0
56835- 0 0 0 0 0 0 0 0 0 0 0 0
56836- 0 0 0 0 0 0 0 0 0 0 0 0
56837- 0 0 0 0 0 0 0 0 0 0 0 0
56838- 0 0 0 0 0 0 6 6 6 18 18 18
56839- 54 54 54 82 82 82 2 2 6 26 26 26
56840- 22 22 22 2 2 6 123 123 123 253 253 253
56841-253 253 253 253 253 253 253 253 253 253 253 253
56842-253 253 253 253 253 253 253 253 253 253 253 253
56843-253 253 253 253 253 253 253 253 253 253 253 253
56844-253 253 253 253 253 253 253 253 253 253 253 253
56845-253 253 253 253 253 253 253 253 253 253 253 253
56846-253 253 253 253 253 253 253 253 253 250 250 250
56847-238 238 238 198 198 198 6 6 6 38 38 38
56848- 58 58 58 26 26 26 38 38 38 2 2 6
56849- 2 2 6 2 2 6 2 2 6 46 46 46
56850- 78 78 78 30 30 30 10 10 10 0 0 0
56851- 0 0 0 0 0 0 0 0 0 0 0 0
56852- 0 0 0 0 0 0 0 0 0 0 0 0
56853- 0 0 0 0 0 0 0 0 0 0 0 0
56854- 0 0 0 0 0 0 0 0 0 0 0 0
56855- 0 0 0 0 0 0 0 0 0 0 0 0
56856- 0 0 0 0 0 0 0 0 0 0 0 0
56857- 0 0 0 0 0 0 0 0 0 0 0 0
56858- 0 0 0 0 0 0 10 10 10 30 30 30
56859- 74 74 74 58 58 58 2 2 6 42 42 42
56860- 2 2 6 22 22 22 231 231 231 253 253 253
56861-253 253 253 253 253 253 253 253 253 253 253 253
56862-253 253 253 253 253 253 253 253 253 250 250 250
56863-253 253 253 253 253 253 253 253 253 253 253 253
56864-253 253 253 253 253 253 253 253 253 253 253 253
56865-253 253 253 253 253 253 253 253 253 253 253 253
56866-253 253 253 253 253 253 253 253 253 253 253 253
56867-253 253 253 246 246 246 46 46 46 38 38 38
56868- 42 42 42 14 14 14 38 38 38 14 14 14
56869- 2 2 6 2 2 6 2 2 6 6 6 6
56870- 86 86 86 46 46 46 14 14 14 0 0 0
56871- 0 0 0 0 0 0 0 0 0 0 0 0
56872- 0 0 0 0 0 0 0 0 0 0 0 0
56873- 0 0 0 0 0 0 0 0 0 0 0 0
56874- 0 0 0 0 0 0 0 0 0 0 0 0
56875- 0 0 0 0 0 0 0 0 0 0 0 0
56876- 0 0 0 0 0 0 0 0 0 0 0 0
56877- 0 0 0 0 0 0 0 0 0 0 0 0
56878- 0 0 0 6 6 6 14 14 14 42 42 42
56879- 90 90 90 18 18 18 18 18 18 26 26 26
56880- 2 2 6 116 116 116 253 253 253 253 253 253
56881-253 253 253 253 253 253 253 253 253 253 253 253
56882-253 253 253 253 253 253 250 250 250 238 238 238
56883-253 253 253 253 253 253 253 253 253 253 253 253
56884-253 253 253 253 253 253 253 253 253 253 253 253
56885-253 253 253 253 253 253 253 253 253 253 253 253
56886-253 253 253 253 253 253 253 253 253 253 253 253
56887-253 253 253 253 253 253 94 94 94 6 6 6
56888- 2 2 6 2 2 6 10 10 10 34 34 34
56889- 2 2 6 2 2 6 2 2 6 2 2 6
56890- 74 74 74 58 58 58 22 22 22 6 6 6
56891- 0 0 0 0 0 0 0 0 0 0 0 0
56892- 0 0 0 0 0 0 0 0 0 0 0 0
56893- 0 0 0 0 0 0 0 0 0 0 0 0
56894- 0 0 0 0 0 0 0 0 0 0 0 0
56895- 0 0 0 0 0 0 0 0 0 0 0 0
56896- 0 0 0 0 0 0 0 0 0 0 0 0
56897- 0 0 0 0 0 0 0 0 0 0 0 0
56898- 0 0 0 10 10 10 26 26 26 66 66 66
56899- 82 82 82 2 2 6 38 38 38 6 6 6
56900- 14 14 14 210 210 210 253 253 253 253 253 253
56901-253 253 253 253 253 253 253 253 253 253 253 253
56902-253 253 253 253 253 253 246 246 246 242 242 242
56903-253 253 253 253 253 253 253 253 253 253 253 253
56904-253 253 253 253 253 253 253 253 253 253 253 253
56905-253 253 253 253 253 253 253 253 253 253 253 253
56906-253 253 253 253 253 253 253 253 253 253 253 253
56907-253 253 253 253 253 253 144 144 144 2 2 6
56908- 2 2 6 2 2 6 2 2 6 46 46 46
56909- 2 2 6 2 2 6 2 2 6 2 2 6
56910- 42 42 42 74 74 74 30 30 30 10 10 10
56911- 0 0 0 0 0 0 0 0 0 0 0 0
56912- 0 0 0 0 0 0 0 0 0 0 0 0
56913- 0 0 0 0 0 0 0 0 0 0 0 0
56914- 0 0 0 0 0 0 0 0 0 0 0 0
56915- 0 0 0 0 0 0 0 0 0 0 0 0
56916- 0 0 0 0 0 0 0 0 0 0 0 0
56917- 0 0 0 0 0 0 0 0 0 0 0 0
56918- 6 6 6 14 14 14 42 42 42 90 90 90
56919- 26 26 26 6 6 6 42 42 42 2 2 6
56920- 74 74 74 250 250 250 253 253 253 253 253 253
56921-253 253 253 253 253 253 253 253 253 253 253 253
56922-253 253 253 253 253 253 242 242 242 242 242 242
56923-253 253 253 253 253 253 253 253 253 253 253 253
56924-253 253 253 253 253 253 253 253 253 253 253 253
56925-253 253 253 253 253 253 253 253 253 253 253 253
56926-253 253 253 253 253 253 253 253 253 253 253 253
56927-253 253 253 253 253 253 182 182 182 2 2 6
56928- 2 2 6 2 2 6 2 2 6 46 46 46
56929- 2 2 6 2 2 6 2 2 6 2 2 6
56930- 10 10 10 86 86 86 38 38 38 10 10 10
56931- 0 0 0 0 0 0 0 0 0 0 0 0
56932- 0 0 0 0 0 0 0 0 0 0 0 0
56933- 0 0 0 0 0 0 0 0 0 0 0 0
56934- 0 0 0 0 0 0 0 0 0 0 0 0
56935- 0 0 0 0 0 0 0 0 0 0 0 0
56936- 0 0 0 0 0 0 0 0 0 0 0 0
56937- 0 0 0 0 0 0 0 0 0 0 0 0
56938- 10 10 10 26 26 26 66 66 66 82 82 82
56939- 2 2 6 22 22 22 18 18 18 2 2 6
56940-149 149 149 253 253 253 253 253 253 253 253 253
56941-253 253 253 253 253 253 253 253 253 253 253 253
56942-253 253 253 253 253 253 234 234 234 242 242 242
56943-253 253 253 253 253 253 253 253 253 253 253 253
56944-253 253 253 253 253 253 253 253 253 253 253 253
56945-253 253 253 253 253 253 253 253 253 253 253 253
56946-253 253 253 253 253 253 253 253 253 253 253 253
56947-253 253 253 253 253 253 206 206 206 2 2 6
56948- 2 2 6 2 2 6 2 2 6 38 38 38
56949- 2 2 6 2 2 6 2 2 6 2 2 6
56950- 6 6 6 86 86 86 46 46 46 14 14 14
56951- 0 0 0 0 0 0 0 0 0 0 0 0
56952- 0 0 0 0 0 0 0 0 0 0 0 0
56953- 0 0 0 0 0 0 0 0 0 0 0 0
56954- 0 0 0 0 0 0 0 0 0 0 0 0
56955- 0 0 0 0 0 0 0 0 0 0 0 0
56956- 0 0 0 0 0 0 0 0 0 0 0 0
56957- 0 0 0 0 0 0 0 0 0 6 6 6
56958- 18 18 18 46 46 46 86 86 86 18 18 18
56959- 2 2 6 34 34 34 10 10 10 6 6 6
56960-210 210 210 253 253 253 253 253 253 253 253 253
56961-253 253 253 253 253 253 253 253 253 253 253 253
56962-253 253 253 253 253 253 234 234 234 242 242 242
56963-253 253 253 253 253 253 253 253 253 253 253 253
56964-253 253 253 253 253 253 253 253 253 253 253 253
56965-253 253 253 253 253 253 253 253 253 253 253 253
56966-253 253 253 253 253 253 253 253 253 253 253 253
56967-253 253 253 253 253 253 221 221 221 6 6 6
56968- 2 2 6 2 2 6 6 6 6 30 30 30
56969- 2 2 6 2 2 6 2 2 6 2 2 6
56970- 2 2 6 82 82 82 54 54 54 18 18 18
56971- 6 6 6 0 0 0 0 0 0 0 0 0
56972- 0 0 0 0 0 0 0 0 0 0 0 0
56973- 0 0 0 0 0 0 0 0 0 0 0 0
56974- 0 0 0 0 0 0 0 0 0 0 0 0
56975- 0 0 0 0 0 0 0 0 0 0 0 0
56976- 0 0 0 0 0 0 0 0 0 0 0 0
56977- 0 0 0 0 0 0 0 0 0 10 10 10
56978- 26 26 26 66 66 66 62 62 62 2 2 6
56979- 2 2 6 38 38 38 10 10 10 26 26 26
56980-238 238 238 253 253 253 253 253 253 253 253 253
56981-253 253 253 253 253 253 253 253 253 253 253 253
56982-253 253 253 253 253 253 231 231 231 238 238 238
56983-253 253 253 253 253 253 253 253 253 253 253 253
56984-253 253 253 253 253 253 253 253 253 253 253 253
56985-253 253 253 253 253 253 253 253 253 253 253 253
56986-253 253 253 253 253 253 253 253 253 253 253 253
56987-253 253 253 253 253 253 231 231 231 6 6 6
56988- 2 2 6 2 2 6 10 10 10 30 30 30
56989- 2 2 6 2 2 6 2 2 6 2 2 6
56990- 2 2 6 66 66 66 58 58 58 22 22 22
56991- 6 6 6 0 0 0 0 0 0 0 0 0
56992- 0 0 0 0 0 0 0 0 0 0 0 0
56993- 0 0 0 0 0 0 0 0 0 0 0 0
56994- 0 0 0 0 0 0 0 0 0 0 0 0
56995- 0 0 0 0 0 0 0 0 0 0 0 0
56996- 0 0 0 0 0 0 0 0 0 0 0 0
56997- 0 0 0 0 0 0 0 0 0 10 10 10
56998- 38 38 38 78 78 78 6 6 6 2 2 6
56999- 2 2 6 46 46 46 14 14 14 42 42 42
57000-246 246 246 253 253 253 253 253 253 253 253 253
57001-253 253 253 253 253 253 253 253 253 253 253 253
57002-253 253 253 253 253 253 231 231 231 242 242 242
57003-253 253 253 253 253 253 253 253 253 253 253 253
57004-253 253 253 253 253 253 253 253 253 253 253 253
57005-253 253 253 253 253 253 253 253 253 253 253 253
57006-253 253 253 253 253 253 253 253 253 253 253 253
57007-253 253 253 253 253 253 234 234 234 10 10 10
57008- 2 2 6 2 2 6 22 22 22 14 14 14
57009- 2 2 6 2 2 6 2 2 6 2 2 6
57010- 2 2 6 66 66 66 62 62 62 22 22 22
57011- 6 6 6 0 0 0 0 0 0 0 0 0
57012- 0 0 0 0 0 0 0 0 0 0 0 0
57013- 0 0 0 0 0 0 0 0 0 0 0 0
57014- 0 0 0 0 0 0 0 0 0 0 0 0
57015- 0 0 0 0 0 0 0 0 0 0 0 0
57016- 0 0 0 0 0 0 0 0 0 0 0 0
57017- 0 0 0 0 0 0 6 6 6 18 18 18
57018- 50 50 50 74 74 74 2 2 6 2 2 6
57019- 14 14 14 70 70 70 34 34 34 62 62 62
57020-250 250 250 253 253 253 253 253 253 253 253 253
57021-253 253 253 253 253 253 253 253 253 253 253 253
57022-253 253 253 253 253 253 231 231 231 246 246 246
57023-253 253 253 253 253 253 253 253 253 253 253 253
57024-253 253 253 253 253 253 253 253 253 253 253 253
57025-253 253 253 253 253 253 253 253 253 253 253 253
57026-253 253 253 253 253 253 253 253 253 253 253 253
57027-253 253 253 253 253 253 234 234 234 14 14 14
57028- 2 2 6 2 2 6 30 30 30 2 2 6
57029- 2 2 6 2 2 6 2 2 6 2 2 6
57030- 2 2 6 66 66 66 62 62 62 22 22 22
57031- 6 6 6 0 0 0 0 0 0 0 0 0
57032- 0 0 0 0 0 0 0 0 0 0 0 0
57033- 0 0 0 0 0 0 0 0 0 0 0 0
57034- 0 0 0 0 0 0 0 0 0 0 0 0
57035- 0 0 0 0 0 0 0 0 0 0 0 0
57036- 0 0 0 0 0 0 0 0 0 0 0 0
57037- 0 0 0 0 0 0 6 6 6 18 18 18
57038- 54 54 54 62 62 62 2 2 6 2 2 6
57039- 2 2 6 30 30 30 46 46 46 70 70 70
57040-250 250 250 253 253 253 253 253 253 253 253 253
57041-253 253 253 253 253 253 253 253 253 253 253 253
57042-253 253 253 253 253 253 231 231 231 246 246 246
57043-253 253 253 253 253 253 253 253 253 253 253 253
57044-253 253 253 253 253 253 253 253 253 253 253 253
57045-253 253 253 253 253 253 253 253 253 253 253 253
57046-253 253 253 253 253 253 253 253 253 253 253 253
57047-253 253 253 253 253 253 226 226 226 10 10 10
57048- 2 2 6 6 6 6 30 30 30 2 2 6
57049- 2 2 6 2 2 6 2 2 6 2 2 6
57050- 2 2 6 66 66 66 58 58 58 22 22 22
57051- 6 6 6 0 0 0 0 0 0 0 0 0
57052- 0 0 0 0 0 0 0 0 0 0 0 0
57053- 0 0 0 0 0 0 0 0 0 0 0 0
57054- 0 0 0 0 0 0 0 0 0 0 0 0
57055- 0 0 0 0 0 0 0 0 0 0 0 0
57056- 0 0 0 0 0 0 0 0 0 0 0 0
57057- 0 0 0 0 0 0 6 6 6 22 22 22
57058- 58 58 58 62 62 62 2 2 6 2 2 6
57059- 2 2 6 2 2 6 30 30 30 78 78 78
57060-250 250 250 253 253 253 253 253 253 253 253 253
57061-253 253 253 253 253 253 253 253 253 253 253 253
57062-253 253 253 253 253 253 231 231 231 246 246 246
57063-253 253 253 253 253 253 253 253 253 253 253 253
57064-253 253 253 253 253 253 253 253 253 253 253 253
57065-253 253 253 253 253 253 253 253 253 253 253 253
57066-253 253 253 253 253 253 253 253 253 253 253 253
57067-253 253 253 253 253 253 206 206 206 2 2 6
57068- 22 22 22 34 34 34 18 14 6 22 22 22
57069- 26 26 26 18 18 18 6 6 6 2 2 6
57070- 2 2 6 82 82 82 54 54 54 18 18 18
57071- 6 6 6 0 0 0 0 0 0 0 0 0
57072- 0 0 0 0 0 0 0 0 0 0 0 0
57073- 0 0 0 0 0 0 0 0 0 0 0 0
57074- 0 0 0 0 0 0 0 0 0 0 0 0
57075- 0 0 0 0 0 0 0 0 0 0 0 0
57076- 0 0 0 0 0 0 0 0 0 0 0 0
57077- 0 0 0 0 0 0 6 6 6 26 26 26
57078- 62 62 62 106 106 106 74 54 14 185 133 11
57079-210 162 10 121 92 8 6 6 6 62 62 62
57080-238 238 238 253 253 253 253 253 253 253 253 253
57081-253 253 253 253 253 253 253 253 253 253 253 253
57082-253 253 253 253 253 253 231 231 231 246 246 246
57083-253 253 253 253 253 253 253 253 253 253 253 253
57084-253 253 253 253 253 253 253 253 253 253 253 253
57085-253 253 253 253 253 253 253 253 253 253 253 253
57086-253 253 253 253 253 253 253 253 253 253 253 253
57087-253 253 253 253 253 253 158 158 158 18 18 18
57088- 14 14 14 2 2 6 2 2 6 2 2 6
57089- 6 6 6 18 18 18 66 66 66 38 38 38
57090- 6 6 6 94 94 94 50 50 50 18 18 18
57091- 6 6 6 0 0 0 0 0 0 0 0 0
57092- 0 0 0 0 0 0 0 0 0 0 0 0
57093- 0 0 0 0 0 0 0 0 0 0 0 0
57094- 0 0 0 0 0 0 0 0 0 0 0 0
57095- 0 0 0 0 0 0 0 0 0 0 0 0
57096- 0 0 0 0 0 0 0 0 0 6 6 6
57097- 10 10 10 10 10 10 18 18 18 38 38 38
57098- 78 78 78 142 134 106 216 158 10 242 186 14
57099-246 190 14 246 190 14 156 118 10 10 10 10
57100- 90 90 90 238 238 238 253 253 253 253 253 253
57101-253 253 253 253 253 253 253 253 253 253 253 253
57102-253 253 253 253 253 253 231 231 231 250 250 250
57103-253 253 253 253 253 253 253 253 253 253 253 253
57104-253 253 253 253 253 253 253 253 253 253 253 253
57105-253 253 253 253 253 253 253 253 253 253 253 253
57106-253 253 253 253 253 253 253 253 253 246 230 190
57107-238 204 91 238 204 91 181 142 44 37 26 9
57108- 2 2 6 2 2 6 2 2 6 2 2 6
57109- 2 2 6 2 2 6 38 38 38 46 46 46
57110- 26 26 26 106 106 106 54 54 54 18 18 18
57111- 6 6 6 0 0 0 0 0 0 0 0 0
57112- 0 0 0 0 0 0 0 0 0 0 0 0
57113- 0 0 0 0 0 0 0 0 0 0 0 0
57114- 0 0 0 0 0 0 0 0 0 0 0 0
57115- 0 0 0 0 0 0 0 0 0 0 0 0
57116- 0 0 0 6 6 6 14 14 14 22 22 22
57117- 30 30 30 38 38 38 50 50 50 70 70 70
57118-106 106 106 190 142 34 226 170 11 242 186 14
57119-246 190 14 246 190 14 246 190 14 154 114 10
57120- 6 6 6 74 74 74 226 226 226 253 253 253
57121-253 253 253 253 253 253 253 253 253 253 253 253
57122-253 253 253 253 253 253 231 231 231 250 250 250
57123-253 253 253 253 253 253 253 253 253 253 253 253
57124-253 253 253 253 253 253 253 253 253 253 253 253
57125-253 253 253 253 253 253 253 253 253 253 253 253
57126-253 253 253 253 253 253 253 253 253 228 184 62
57127-241 196 14 241 208 19 232 195 16 38 30 10
57128- 2 2 6 2 2 6 2 2 6 2 2 6
57129- 2 2 6 6 6 6 30 30 30 26 26 26
57130-203 166 17 154 142 90 66 66 66 26 26 26
57131- 6 6 6 0 0 0 0 0 0 0 0 0
57132- 0 0 0 0 0 0 0 0 0 0 0 0
57133- 0 0 0 0 0 0 0 0 0 0 0 0
57134- 0 0 0 0 0 0 0 0 0 0 0 0
57135- 0 0 0 0 0 0 0 0 0 0 0 0
57136- 6 6 6 18 18 18 38 38 38 58 58 58
57137- 78 78 78 86 86 86 101 101 101 123 123 123
57138-175 146 61 210 150 10 234 174 13 246 186 14
57139-246 190 14 246 190 14 246 190 14 238 190 10
57140-102 78 10 2 2 6 46 46 46 198 198 198
57141-253 253 253 253 253 253 253 253 253 253 253 253
57142-253 253 253 253 253 253 234 234 234 242 242 242
57143-253 253 253 253 253 253 253 253 253 253 253 253
57144-253 253 253 253 253 253 253 253 253 253 253 253
57145-253 253 253 253 253 253 253 253 253 253 253 253
57146-253 253 253 253 253 253 253 253 253 224 178 62
57147-242 186 14 241 196 14 210 166 10 22 18 6
57148- 2 2 6 2 2 6 2 2 6 2 2 6
57149- 2 2 6 2 2 6 6 6 6 121 92 8
57150-238 202 15 232 195 16 82 82 82 34 34 34
57151- 10 10 10 0 0 0 0 0 0 0 0 0
57152- 0 0 0 0 0 0 0 0 0 0 0 0
57153- 0 0 0 0 0 0 0 0 0 0 0 0
57154- 0 0 0 0 0 0 0 0 0 0 0 0
57155- 0 0 0 0 0 0 0 0 0 0 0 0
57156- 14 14 14 38 38 38 70 70 70 154 122 46
57157-190 142 34 200 144 11 197 138 11 197 138 11
57158-213 154 11 226 170 11 242 186 14 246 190 14
57159-246 190 14 246 190 14 246 190 14 246 190 14
57160-225 175 15 46 32 6 2 2 6 22 22 22
57161-158 158 158 250 250 250 253 253 253 253 253 253
57162-253 253 253 253 253 253 253 253 253 253 253 253
57163-253 253 253 253 253 253 253 253 253 253 253 253
57164-253 253 253 253 253 253 253 253 253 253 253 253
57165-253 253 253 253 253 253 253 253 253 253 253 253
57166-253 253 253 250 250 250 242 242 242 224 178 62
57167-239 182 13 236 186 11 213 154 11 46 32 6
57168- 2 2 6 2 2 6 2 2 6 2 2 6
57169- 2 2 6 2 2 6 61 42 6 225 175 15
57170-238 190 10 236 186 11 112 100 78 42 42 42
57171- 14 14 14 0 0 0 0 0 0 0 0 0
57172- 0 0 0 0 0 0 0 0 0 0 0 0
57173- 0 0 0 0 0 0 0 0 0 0 0 0
57174- 0 0 0 0 0 0 0 0 0 0 0 0
57175- 0 0 0 0 0 0 0 0 0 6 6 6
57176- 22 22 22 54 54 54 154 122 46 213 154 11
57177-226 170 11 230 174 11 226 170 11 226 170 11
57178-236 178 12 242 186 14 246 190 14 246 190 14
57179-246 190 14 246 190 14 246 190 14 246 190 14
57180-241 196 14 184 144 12 10 10 10 2 2 6
57181- 6 6 6 116 116 116 242 242 242 253 253 253
57182-253 253 253 253 253 253 253 253 253 253 253 253
57183-253 253 253 253 253 253 253 253 253 253 253 253
57184-253 253 253 253 253 253 253 253 253 253 253 253
57185-253 253 253 253 253 253 253 253 253 253 253 253
57186-253 253 253 231 231 231 198 198 198 214 170 54
57187-236 178 12 236 178 12 210 150 10 137 92 6
57188- 18 14 6 2 2 6 2 2 6 2 2 6
57189- 6 6 6 70 47 6 200 144 11 236 178 12
57190-239 182 13 239 182 13 124 112 88 58 58 58
57191- 22 22 22 6 6 6 0 0 0 0 0 0
57192- 0 0 0 0 0 0 0 0 0 0 0 0
57193- 0 0 0 0 0 0 0 0 0 0 0 0
57194- 0 0 0 0 0 0 0 0 0 0 0 0
57195- 0 0 0 0 0 0 0 0 0 10 10 10
57196- 30 30 30 70 70 70 180 133 36 226 170 11
57197-239 182 13 242 186 14 242 186 14 246 186 14
57198-246 190 14 246 190 14 246 190 14 246 190 14
57199-246 190 14 246 190 14 246 190 14 246 190 14
57200-246 190 14 232 195 16 98 70 6 2 2 6
57201- 2 2 6 2 2 6 66 66 66 221 221 221
57202-253 253 253 253 253 253 253 253 253 253 253 253
57203-253 253 253 253 253 253 253 253 253 253 253 253
57204-253 253 253 253 253 253 253 253 253 253 253 253
57205-253 253 253 253 253 253 253 253 253 253 253 253
57206-253 253 253 206 206 206 198 198 198 214 166 58
57207-230 174 11 230 174 11 216 158 10 192 133 9
57208-163 110 8 116 81 8 102 78 10 116 81 8
57209-167 114 7 197 138 11 226 170 11 239 182 13
57210-242 186 14 242 186 14 162 146 94 78 78 78
57211- 34 34 34 14 14 14 6 6 6 0 0 0
57212- 0 0 0 0 0 0 0 0 0 0 0 0
57213- 0 0 0 0 0 0 0 0 0 0 0 0
57214- 0 0 0 0 0 0 0 0 0 0 0 0
57215- 0 0 0 0 0 0 0 0 0 6 6 6
57216- 30 30 30 78 78 78 190 142 34 226 170 11
57217-239 182 13 246 190 14 246 190 14 246 190 14
57218-246 190 14 246 190 14 246 190 14 246 190 14
57219-246 190 14 246 190 14 246 190 14 246 190 14
57220-246 190 14 241 196 14 203 166 17 22 18 6
57221- 2 2 6 2 2 6 2 2 6 38 38 38
57222-218 218 218 253 253 253 253 253 253 253 253 253
57223-253 253 253 253 253 253 253 253 253 253 253 253
57224-253 253 253 253 253 253 253 253 253 253 253 253
57225-253 253 253 253 253 253 253 253 253 253 253 253
57226-250 250 250 206 206 206 198 198 198 202 162 69
57227-226 170 11 236 178 12 224 166 10 210 150 10
57228-200 144 11 197 138 11 192 133 9 197 138 11
57229-210 150 10 226 170 11 242 186 14 246 190 14
57230-246 190 14 246 186 14 225 175 15 124 112 88
57231- 62 62 62 30 30 30 14 14 14 6 6 6
57232- 0 0 0 0 0 0 0 0 0 0 0 0
57233- 0 0 0 0 0 0 0 0 0 0 0 0
57234- 0 0 0 0 0 0 0 0 0 0 0 0
57235- 0 0 0 0 0 0 0 0 0 10 10 10
57236- 30 30 30 78 78 78 174 135 50 224 166 10
57237-239 182 13 246 190 14 246 190 14 246 190 14
57238-246 190 14 246 190 14 246 190 14 246 190 14
57239-246 190 14 246 190 14 246 190 14 246 190 14
57240-246 190 14 246 190 14 241 196 14 139 102 15
57241- 2 2 6 2 2 6 2 2 6 2 2 6
57242- 78 78 78 250 250 250 253 253 253 253 253 253
57243-253 253 253 253 253 253 253 253 253 253 253 253
57244-253 253 253 253 253 253 253 253 253 253 253 253
57245-253 253 253 253 253 253 253 253 253 253 253 253
57246-250 250 250 214 214 214 198 198 198 190 150 46
57247-219 162 10 236 178 12 234 174 13 224 166 10
57248-216 158 10 213 154 11 213 154 11 216 158 10
57249-226 170 11 239 182 13 246 190 14 246 190 14
57250-246 190 14 246 190 14 242 186 14 206 162 42
57251-101 101 101 58 58 58 30 30 30 14 14 14
57252- 6 6 6 0 0 0 0 0 0 0 0 0
57253- 0 0 0 0 0 0 0 0 0 0 0 0
57254- 0 0 0 0 0 0 0 0 0 0 0 0
57255- 0 0 0 0 0 0 0 0 0 10 10 10
57256- 30 30 30 74 74 74 174 135 50 216 158 10
57257-236 178 12 246 190 14 246 190 14 246 190 14
57258-246 190 14 246 190 14 246 190 14 246 190 14
57259-246 190 14 246 190 14 246 190 14 246 190 14
57260-246 190 14 246 190 14 241 196 14 226 184 13
57261- 61 42 6 2 2 6 2 2 6 2 2 6
57262- 22 22 22 238 238 238 253 253 253 253 253 253
57263-253 253 253 253 253 253 253 253 253 253 253 253
57264-253 253 253 253 253 253 253 253 253 253 253 253
57265-253 253 253 253 253 253 253 253 253 253 253 253
57266-253 253 253 226 226 226 187 187 187 180 133 36
57267-216 158 10 236 178 12 239 182 13 236 178 12
57268-230 174 11 226 170 11 226 170 11 230 174 11
57269-236 178 12 242 186 14 246 190 14 246 190 14
57270-246 190 14 246 190 14 246 186 14 239 182 13
57271-206 162 42 106 106 106 66 66 66 34 34 34
57272- 14 14 14 6 6 6 0 0 0 0 0 0
57273- 0 0 0 0 0 0 0 0 0 0 0 0
57274- 0 0 0 0 0 0 0 0 0 0 0 0
57275- 0 0 0 0 0 0 0 0 0 6 6 6
57276- 26 26 26 70 70 70 163 133 67 213 154 11
57277-236 178 12 246 190 14 246 190 14 246 190 14
57278-246 190 14 246 190 14 246 190 14 246 190 14
57279-246 190 14 246 190 14 246 190 14 246 190 14
57280-246 190 14 246 190 14 246 190 14 241 196 14
57281-190 146 13 18 14 6 2 2 6 2 2 6
57282- 46 46 46 246 246 246 253 253 253 253 253 253
57283-253 253 253 253 253 253 253 253 253 253 253 253
57284-253 253 253 253 253 253 253 253 253 253 253 253
57285-253 253 253 253 253 253 253 253 253 253 253 253
57286-253 253 253 221 221 221 86 86 86 156 107 11
57287-216 158 10 236 178 12 242 186 14 246 186 14
57288-242 186 14 239 182 13 239 182 13 242 186 14
57289-242 186 14 246 186 14 246 190 14 246 190 14
57290-246 190 14 246 190 14 246 190 14 246 190 14
57291-242 186 14 225 175 15 142 122 72 66 66 66
57292- 30 30 30 10 10 10 0 0 0 0 0 0
57293- 0 0 0 0 0 0 0 0 0 0 0 0
57294- 0 0 0 0 0 0 0 0 0 0 0 0
57295- 0 0 0 0 0 0 0 0 0 6 6 6
57296- 26 26 26 70 70 70 163 133 67 210 150 10
57297-236 178 12 246 190 14 246 190 14 246 190 14
57298-246 190 14 246 190 14 246 190 14 246 190 14
57299-246 190 14 246 190 14 246 190 14 246 190 14
57300-246 190 14 246 190 14 246 190 14 246 190 14
57301-232 195 16 121 92 8 34 34 34 106 106 106
57302-221 221 221 253 253 253 253 253 253 253 253 253
57303-253 253 253 253 253 253 253 253 253 253 253 253
57304-253 253 253 253 253 253 253 253 253 253 253 253
57305-253 253 253 253 253 253 253 253 253 253 253 253
57306-242 242 242 82 82 82 18 14 6 163 110 8
57307-216 158 10 236 178 12 242 186 14 246 190 14
57308-246 190 14 246 190 14 246 190 14 246 190 14
57309-246 190 14 246 190 14 246 190 14 246 190 14
57310-246 190 14 246 190 14 246 190 14 246 190 14
57311-246 190 14 246 190 14 242 186 14 163 133 67
57312- 46 46 46 18 18 18 6 6 6 0 0 0
57313- 0 0 0 0 0 0 0 0 0 0 0 0
57314- 0 0 0 0 0 0 0 0 0 0 0 0
57315- 0 0 0 0 0 0 0 0 0 10 10 10
57316- 30 30 30 78 78 78 163 133 67 210 150 10
57317-236 178 12 246 186 14 246 190 14 246 190 14
57318-246 190 14 246 190 14 246 190 14 246 190 14
57319-246 190 14 246 190 14 246 190 14 246 190 14
57320-246 190 14 246 190 14 246 190 14 246 190 14
57321-241 196 14 215 174 15 190 178 144 253 253 253
57322-253 253 253 253 253 253 253 253 253 253 253 253
57323-253 253 253 253 253 253 253 253 253 253 253 253
57324-253 253 253 253 253 253 253 253 253 253 253 253
57325-253 253 253 253 253 253 253 253 253 218 218 218
57326- 58 58 58 2 2 6 22 18 6 167 114 7
57327-216 158 10 236 178 12 246 186 14 246 190 14
57328-246 190 14 246 190 14 246 190 14 246 190 14
57329-246 190 14 246 190 14 246 190 14 246 190 14
57330-246 190 14 246 190 14 246 190 14 246 190 14
57331-246 190 14 246 186 14 242 186 14 190 150 46
57332- 54 54 54 22 22 22 6 6 6 0 0 0
57333- 0 0 0 0 0 0 0 0 0 0 0 0
57334- 0 0 0 0 0 0 0 0 0 0 0 0
57335- 0 0 0 0 0 0 0 0 0 14 14 14
57336- 38 38 38 86 86 86 180 133 36 213 154 11
57337-236 178 12 246 186 14 246 190 14 246 190 14
57338-246 190 14 246 190 14 246 190 14 246 190 14
57339-246 190 14 246 190 14 246 190 14 246 190 14
57340-246 190 14 246 190 14 246 190 14 246 190 14
57341-246 190 14 232 195 16 190 146 13 214 214 214
57342-253 253 253 253 253 253 253 253 253 253 253 253
57343-253 253 253 253 253 253 253 253 253 253 253 253
57344-253 253 253 253 253 253 253 253 253 253 253 253
57345-253 253 253 250 250 250 170 170 170 26 26 26
57346- 2 2 6 2 2 6 37 26 9 163 110 8
57347-219 162 10 239 182 13 246 186 14 246 190 14
57348-246 190 14 246 190 14 246 190 14 246 190 14
57349-246 190 14 246 190 14 246 190 14 246 190 14
57350-246 190 14 246 190 14 246 190 14 246 190 14
57351-246 186 14 236 178 12 224 166 10 142 122 72
57352- 46 46 46 18 18 18 6 6 6 0 0 0
57353- 0 0 0 0 0 0 0 0 0 0 0 0
57354- 0 0 0 0 0 0 0 0 0 0 0 0
57355- 0 0 0 0 0 0 6 6 6 18 18 18
57356- 50 50 50 109 106 95 192 133 9 224 166 10
57357-242 186 14 246 190 14 246 190 14 246 190 14
57358-246 190 14 246 190 14 246 190 14 246 190 14
57359-246 190 14 246 190 14 246 190 14 246 190 14
57360-246 190 14 246 190 14 246 190 14 246 190 14
57361-242 186 14 226 184 13 210 162 10 142 110 46
57362-226 226 226 253 253 253 253 253 253 253 253 253
57363-253 253 253 253 253 253 253 253 253 253 253 253
57364-253 253 253 253 253 253 253 253 253 253 253 253
57365-198 198 198 66 66 66 2 2 6 2 2 6
57366- 2 2 6 2 2 6 50 34 6 156 107 11
57367-219 162 10 239 182 13 246 186 14 246 190 14
57368-246 190 14 246 190 14 246 190 14 246 190 14
57369-246 190 14 246 190 14 246 190 14 246 190 14
57370-246 190 14 246 190 14 246 190 14 242 186 14
57371-234 174 13 213 154 11 154 122 46 66 66 66
57372- 30 30 30 10 10 10 0 0 0 0 0 0
57373- 0 0 0 0 0 0 0 0 0 0 0 0
57374- 0 0 0 0 0 0 0 0 0 0 0 0
57375- 0 0 0 0 0 0 6 6 6 22 22 22
57376- 58 58 58 154 121 60 206 145 10 234 174 13
57377-242 186 14 246 186 14 246 190 14 246 190 14
57378-246 190 14 246 190 14 246 190 14 246 190 14
57379-246 190 14 246 190 14 246 190 14 246 190 14
57380-246 190 14 246 190 14 246 190 14 246 190 14
57381-246 186 14 236 178 12 210 162 10 163 110 8
57382- 61 42 6 138 138 138 218 218 218 250 250 250
57383-253 253 253 253 253 253 253 253 253 250 250 250
57384-242 242 242 210 210 210 144 144 144 66 66 66
57385- 6 6 6 2 2 6 2 2 6 2 2 6
57386- 2 2 6 2 2 6 61 42 6 163 110 8
57387-216 158 10 236 178 12 246 190 14 246 190 14
57388-246 190 14 246 190 14 246 190 14 246 190 14
57389-246 190 14 246 190 14 246 190 14 246 190 14
57390-246 190 14 239 182 13 230 174 11 216 158 10
57391-190 142 34 124 112 88 70 70 70 38 38 38
57392- 18 18 18 6 6 6 0 0 0 0 0 0
57393- 0 0 0 0 0 0 0 0 0 0 0 0
57394- 0 0 0 0 0 0 0 0 0 0 0 0
57395- 0 0 0 0 0 0 6 6 6 22 22 22
57396- 62 62 62 168 124 44 206 145 10 224 166 10
57397-236 178 12 239 182 13 242 186 14 242 186 14
57398-246 186 14 246 190 14 246 190 14 246 190 14
57399-246 190 14 246 190 14 246 190 14 246 190 14
57400-246 190 14 246 190 14 246 190 14 246 190 14
57401-246 190 14 236 178 12 216 158 10 175 118 6
57402- 80 54 7 2 2 6 6 6 6 30 30 30
57403- 54 54 54 62 62 62 50 50 50 38 38 38
57404- 14 14 14 2 2 6 2 2 6 2 2 6
57405- 2 2 6 2 2 6 2 2 6 2 2 6
57406- 2 2 6 6 6 6 80 54 7 167 114 7
57407-213 154 11 236 178 12 246 190 14 246 190 14
57408-246 190 14 246 190 14 246 190 14 246 190 14
57409-246 190 14 242 186 14 239 182 13 239 182 13
57410-230 174 11 210 150 10 174 135 50 124 112 88
57411- 82 82 82 54 54 54 34 34 34 18 18 18
57412- 6 6 6 0 0 0 0 0 0 0 0 0
57413- 0 0 0 0 0 0 0 0 0 0 0 0
57414- 0 0 0 0 0 0 0 0 0 0 0 0
57415- 0 0 0 0 0 0 6 6 6 18 18 18
57416- 50 50 50 158 118 36 192 133 9 200 144 11
57417-216 158 10 219 162 10 224 166 10 226 170 11
57418-230 174 11 236 178 12 239 182 13 239 182 13
57419-242 186 14 246 186 14 246 190 14 246 190 14
57420-246 190 14 246 190 14 246 190 14 246 190 14
57421-246 186 14 230 174 11 210 150 10 163 110 8
57422-104 69 6 10 10 10 2 2 6 2 2 6
57423- 2 2 6 2 2 6 2 2 6 2 2 6
57424- 2 2 6 2 2 6 2 2 6 2 2 6
57425- 2 2 6 2 2 6 2 2 6 2 2 6
57426- 2 2 6 6 6 6 91 60 6 167 114 7
57427-206 145 10 230 174 11 242 186 14 246 190 14
57428-246 190 14 246 190 14 246 186 14 242 186 14
57429-239 182 13 230 174 11 224 166 10 213 154 11
57430-180 133 36 124 112 88 86 86 86 58 58 58
57431- 38 38 38 22 22 22 10 10 10 6 6 6
57432- 0 0 0 0 0 0 0 0 0 0 0 0
57433- 0 0 0 0 0 0 0 0 0 0 0 0
57434- 0 0 0 0 0 0 0 0 0 0 0 0
57435- 0 0 0 0 0 0 0 0 0 14 14 14
57436- 34 34 34 70 70 70 138 110 50 158 118 36
57437-167 114 7 180 123 7 192 133 9 197 138 11
57438-200 144 11 206 145 10 213 154 11 219 162 10
57439-224 166 10 230 174 11 239 182 13 242 186 14
57440-246 186 14 246 186 14 246 186 14 246 186 14
57441-239 182 13 216 158 10 185 133 11 152 99 6
57442-104 69 6 18 14 6 2 2 6 2 2 6
57443- 2 2 6 2 2 6 2 2 6 2 2 6
57444- 2 2 6 2 2 6 2 2 6 2 2 6
57445- 2 2 6 2 2 6 2 2 6 2 2 6
57446- 2 2 6 6 6 6 80 54 7 152 99 6
57447-192 133 9 219 162 10 236 178 12 239 182 13
57448-246 186 14 242 186 14 239 182 13 236 178 12
57449-224 166 10 206 145 10 192 133 9 154 121 60
57450- 94 94 94 62 62 62 42 42 42 22 22 22
57451- 14 14 14 6 6 6 0 0 0 0 0 0
57452- 0 0 0 0 0 0 0 0 0 0 0 0
57453- 0 0 0 0 0 0 0 0 0 0 0 0
57454- 0 0 0 0 0 0 0 0 0 0 0 0
57455- 0 0 0 0 0 0 0 0 0 6 6 6
57456- 18 18 18 34 34 34 58 58 58 78 78 78
57457-101 98 89 124 112 88 142 110 46 156 107 11
57458-163 110 8 167 114 7 175 118 6 180 123 7
57459-185 133 11 197 138 11 210 150 10 219 162 10
57460-226 170 11 236 178 12 236 178 12 234 174 13
57461-219 162 10 197 138 11 163 110 8 130 83 6
57462- 91 60 6 10 10 10 2 2 6 2 2 6
57463- 18 18 18 38 38 38 38 38 38 38 38 38
57464- 38 38 38 38 38 38 38 38 38 38 38 38
57465- 38 38 38 38 38 38 26 26 26 2 2 6
57466- 2 2 6 6 6 6 70 47 6 137 92 6
57467-175 118 6 200 144 11 219 162 10 230 174 11
57468-234 174 13 230 174 11 219 162 10 210 150 10
57469-192 133 9 163 110 8 124 112 88 82 82 82
57470- 50 50 50 30 30 30 14 14 14 6 6 6
57471- 0 0 0 0 0 0 0 0 0 0 0 0
57472- 0 0 0 0 0 0 0 0 0 0 0 0
57473- 0 0 0 0 0 0 0 0 0 0 0 0
57474- 0 0 0 0 0 0 0 0 0 0 0 0
57475- 0 0 0 0 0 0 0 0 0 0 0 0
57476- 6 6 6 14 14 14 22 22 22 34 34 34
57477- 42 42 42 58 58 58 74 74 74 86 86 86
57478-101 98 89 122 102 70 130 98 46 121 87 25
57479-137 92 6 152 99 6 163 110 8 180 123 7
57480-185 133 11 197 138 11 206 145 10 200 144 11
57481-180 123 7 156 107 11 130 83 6 104 69 6
57482- 50 34 6 54 54 54 110 110 110 101 98 89
57483- 86 86 86 82 82 82 78 78 78 78 78 78
57484- 78 78 78 78 78 78 78 78 78 78 78 78
57485- 78 78 78 82 82 82 86 86 86 94 94 94
57486-106 106 106 101 101 101 86 66 34 124 80 6
57487-156 107 11 180 123 7 192 133 9 200 144 11
57488-206 145 10 200 144 11 192 133 9 175 118 6
57489-139 102 15 109 106 95 70 70 70 42 42 42
57490- 22 22 22 10 10 10 0 0 0 0 0 0
57491- 0 0 0 0 0 0 0 0 0 0 0 0
57492- 0 0 0 0 0 0 0 0 0 0 0 0
57493- 0 0 0 0 0 0 0 0 0 0 0 0
57494- 0 0 0 0 0 0 0 0 0 0 0 0
57495- 0 0 0 0 0 0 0 0 0 0 0 0
57496- 0 0 0 0 0 0 6 6 6 10 10 10
57497- 14 14 14 22 22 22 30 30 30 38 38 38
57498- 50 50 50 62 62 62 74 74 74 90 90 90
57499-101 98 89 112 100 78 121 87 25 124 80 6
57500-137 92 6 152 99 6 152 99 6 152 99 6
57501-138 86 6 124 80 6 98 70 6 86 66 30
57502-101 98 89 82 82 82 58 58 58 46 46 46
57503- 38 38 38 34 34 34 34 34 34 34 34 34
57504- 34 34 34 34 34 34 34 34 34 34 34 34
57505- 34 34 34 34 34 34 38 38 38 42 42 42
57506- 54 54 54 82 82 82 94 86 76 91 60 6
57507-134 86 6 156 107 11 167 114 7 175 118 6
57508-175 118 6 167 114 7 152 99 6 121 87 25
57509-101 98 89 62 62 62 34 34 34 18 18 18
57510- 6 6 6 0 0 0 0 0 0 0 0 0
57511- 0 0 0 0 0 0 0 0 0 0 0 0
57512- 0 0 0 0 0 0 0 0 0 0 0 0
57513- 0 0 0 0 0 0 0 0 0 0 0 0
57514- 0 0 0 0 0 0 0 0 0 0 0 0
57515- 0 0 0 0 0 0 0 0 0 0 0 0
57516- 0 0 0 0 0 0 0 0 0 0 0 0
57517- 0 0 0 6 6 6 6 6 6 10 10 10
57518- 18 18 18 22 22 22 30 30 30 42 42 42
57519- 50 50 50 66 66 66 86 86 86 101 98 89
57520-106 86 58 98 70 6 104 69 6 104 69 6
57521-104 69 6 91 60 6 82 62 34 90 90 90
57522- 62 62 62 38 38 38 22 22 22 14 14 14
57523- 10 10 10 10 10 10 10 10 10 10 10 10
57524- 10 10 10 10 10 10 6 6 6 10 10 10
57525- 10 10 10 10 10 10 10 10 10 14 14 14
57526- 22 22 22 42 42 42 70 70 70 89 81 66
57527- 80 54 7 104 69 6 124 80 6 137 92 6
57528-134 86 6 116 81 8 100 82 52 86 86 86
57529- 58 58 58 30 30 30 14 14 14 6 6 6
57530- 0 0 0 0 0 0 0 0 0 0 0 0
57531- 0 0 0 0 0 0 0 0 0 0 0 0
57532- 0 0 0 0 0 0 0 0 0 0 0 0
57533- 0 0 0 0 0 0 0 0 0 0 0 0
57534- 0 0 0 0 0 0 0 0 0 0 0 0
57535- 0 0 0 0 0 0 0 0 0 0 0 0
57536- 0 0 0 0 0 0 0 0 0 0 0 0
57537- 0 0 0 0 0 0 0 0 0 0 0 0
57538- 0 0 0 6 6 6 10 10 10 14 14 14
57539- 18 18 18 26 26 26 38 38 38 54 54 54
57540- 70 70 70 86 86 86 94 86 76 89 81 66
57541- 89 81 66 86 86 86 74 74 74 50 50 50
57542- 30 30 30 14 14 14 6 6 6 0 0 0
57543- 0 0 0 0 0 0 0 0 0 0 0 0
57544- 0 0 0 0 0 0 0 0 0 0 0 0
57545- 0 0 0 0 0 0 0 0 0 0 0 0
57546- 6 6 6 18 18 18 34 34 34 58 58 58
57547- 82 82 82 89 81 66 89 81 66 89 81 66
57548- 94 86 66 94 86 76 74 74 74 50 50 50
57549- 26 26 26 14 14 14 6 6 6 0 0 0
57550- 0 0 0 0 0 0 0 0 0 0 0 0
57551- 0 0 0 0 0 0 0 0 0 0 0 0
57552- 0 0 0 0 0 0 0 0 0 0 0 0
57553- 0 0 0 0 0 0 0 0 0 0 0 0
57554- 0 0 0 0 0 0 0 0 0 0 0 0
57555- 0 0 0 0 0 0 0 0 0 0 0 0
57556- 0 0 0 0 0 0 0 0 0 0 0 0
57557- 0 0 0 0 0 0 0 0 0 0 0 0
57558- 0 0 0 0 0 0 0 0 0 0 0 0
57559- 6 6 6 6 6 6 14 14 14 18 18 18
57560- 30 30 30 38 38 38 46 46 46 54 54 54
57561- 50 50 50 42 42 42 30 30 30 18 18 18
57562- 10 10 10 0 0 0 0 0 0 0 0 0
57563- 0 0 0 0 0 0 0 0 0 0 0 0
57564- 0 0 0 0 0 0 0 0 0 0 0 0
57565- 0 0 0 0 0 0 0 0 0 0 0 0
57566- 0 0 0 6 6 6 14 14 14 26 26 26
57567- 38 38 38 50 50 50 58 58 58 58 58 58
57568- 54 54 54 42 42 42 30 30 30 18 18 18
57569- 10 10 10 0 0 0 0 0 0 0 0 0
57570- 0 0 0 0 0 0 0 0 0 0 0 0
57571- 0 0 0 0 0 0 0 0 0 0 0 0
57572- 0 0 0 0 0 0 0 0 0 0 0 0
57573- 0 0 0 0 0 0 0 0 0 0 0 0
57574- 0 0 0 0 0 0 0 0 0 0 0 0
57575- 0 0 0 0 0 0 0 0 0 0 0 0
57576- 0 0 0 0 0 0 0 0 0 0 0 0
57577- 0 0 0 0 0 0 0 0 0 0 0 0
57578- 0 0 0 0 0 0 0 0 0 0 0 0
57579- 0 0 0 0 0 0 0 0 0 6 6 6
57580- 6 6 6 10 10 10 14 14 14 18 18 18
57581- 18 18 18 14 14 14 10 10 10 6 6 6
57582- 0 0 0 0 0 0 0 0 0 0 0 0
57583- 0 0 0 0 0 0 0 0 0 0 0 0
57584- 0 0 0 0 0 0 0 0 0 0 0 0
57585- 0 0 0 0 0 0 0 0 0 0 0 0
57586- 0 0 0 0 0 0 0 0 0 6 6 6
57587- 14 14 14 18 18 18 22 22 22 22 22 22
57588- 18 18 18 14 14 14 10 10 10 6 6 6
57589- 0 0 0 0 0 0 0 0 0 0 0 0
57590- 0 0 0 0 0 0 0 0 0 0 0 0
57591- 0 0 0 0 0 0 0 0 0 0 0 0
57592- 0 0 0 0 0 0 0 0 0 0 0 0
57593- 0 0 0 0 0 0 0 0 0 0 0 0
57594+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57595+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57596+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57597+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57599+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57600+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57601+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57602+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57603+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57604+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57606+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57607+4 4 4 4 4 4
57608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57615+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57621+4 4 4 4 4 4
57622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57629+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57635+4 4 4 4 4 4
57636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57643+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57648+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57649+4 4 4 4 4 4
57650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57657+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57663+4 4 4 4 4 4
57664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57677+4 4 4 4 4 4
57678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57682+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
57683+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
57684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57687+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
57688+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57689+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
57690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57691+4 4 4 4 4 4
57692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57696+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
57697+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
57698+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57701+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
57702+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
57703+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
57704+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57705+4 4 4 4 4 4
57706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57710+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
57711+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
57712+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57715+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
57716+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
57717+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
57718+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
57719+4 4 4 4 4 4
57720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57723+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
57724+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
57725+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
57726+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
57727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57728+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57729+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
57730+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
57731+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
57732+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
57733+4 4 4 4 4 4
57734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57737+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
57738+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
57739+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
57740+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
57741+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57742+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
57743+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
57744+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
57745+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
57746+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
57747+4 4 4 4 4 4
57748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
57751+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
57752+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
57753+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
57754+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
57755+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
57756+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
57757+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
57758+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
57759+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
57760+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
57761+4 4 4 4 4 4
57762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57764+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
57765+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
57766+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
57767+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
57768+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
57769+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
57770+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
57771+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
57772+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
57773+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
57774+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
57775+4 4 4 4 4 4
57776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57778+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
57779+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
57780+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
57781+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
57782+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
57783+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
57784+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
57785+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
57786+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
57787+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
57788+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
57789+4 4 4 4 4 4
57790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57792+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
57793+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
57794+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
57795+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
57796+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
57797+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
57798+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
57799+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
57800+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
57801+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
57802+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57803+4 4 4 4 4 4
57804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57806+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
57807+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
57808+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
57809+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
57810+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
57811+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
57812+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
57813+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
57814+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
57815+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
57816+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
57817+4 4 4 4 4 4
57818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57819+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
57820+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
57821+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
57822+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
57823+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
57824+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
57825+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
57826+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
57827+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
57828+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
57829+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
57830+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
57831+4 4 4 4 4 4
57832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57833+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
57834+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
57835+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
57836+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
57837+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
57838+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
57839+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
57840+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
57841+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
57842+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
57843+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
57844+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
57845+0 0 0 4 4 4
57846+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57847+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
57848+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
57849+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
57850+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
57851+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
57852+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
57853+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
57854+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
57855+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
57856+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
57857+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
57858+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
57859+2 0 0 0 0 0
57860+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
57861+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
57862+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
57863+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
57864+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
57865+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
57866+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
57867+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
57868+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
57869+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
57870+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
57871+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
57872+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
57873+37 38 37 0 0 0
57874+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57875+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
57876+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
57877+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
57878+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
57879+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
57880+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
57881+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
57882+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
57883+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
57884+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
57885+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
57886+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
57887+85 115 134 4 0 0
57888+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
57889+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
57890+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
57891+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
57892+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
57893+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
57894+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
57895+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
57896+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
57897+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
57898+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
57899+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
57900+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
57901+60 73 81 4 0 0
57902+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
57903+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
57904+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
57905+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
57906+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
57907+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
57908+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
57909+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
57910+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
57911+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
57912+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
57913+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
57914+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
57915+16 19 21 4 0 0
57916+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
57917+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
57918+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
57919+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
57920+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
57921+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
57922+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
57923+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
57924+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
57925+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
57926+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
57927+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
57928+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
57929+4 0 0 4 3 3
57930+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
57931+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
57932+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
57933+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
57934+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
57935+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
57936+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
57937+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
57938+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
57939+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
57940+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
57941+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
57942+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
57943+3 2 2 4 4 4
57944+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
57945+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
57946+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
57947+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57948+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
57949+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
57950+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
57951+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
57952+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
57953+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
57954+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
57955+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
57956+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
57957+4 4 4 4 4 4
57958+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
57959+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
57960+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
57961+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
57962+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
57963+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
57964+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
57965+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
57966+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
57967+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
57968+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
57969+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
57970+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
57971+4 4 4 4 4 4
57972+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
57973+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
57974+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
57975+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
57976+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
57977+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57978+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
57979+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
57980+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
57981+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
57982+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
57983+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
57984+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
57985+5 5 5 5 5 5
57986+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
57987+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
57988+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
57989+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
57990+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
57991+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57992+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
57993+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
57994+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
57995+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
57996+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
57997+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
57998+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
57999+5 5 5 4 4 4
58000+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
58001+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
58002+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
58003+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
58004+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
58005+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
58006+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
58007+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
58008+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
58009+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
58010+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
58011+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
58012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58013+4 4 4 4 4 4
58014+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
58015+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
58016+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
58017+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
58018+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
58019+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58020+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58021+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
58022+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
58023+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
58024+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
58025+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
58026+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58027+4 4 4 4 4 4
58028+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
58029+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
58030+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
58031+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
58032+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
58033+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
58034+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
58035+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
58036+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
58037+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
58038+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
58039+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58040+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58041+4 4 4 4 4 4
58042+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
58043+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
58044+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
58045+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
58046+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
58047+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58048+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
58049+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
58050+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
58051+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
58052+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
58053+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58054+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58055+4 4 4 4 4 4
58056+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
58057+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
58058+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
58059+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
58060+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
58061+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
58062+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
58063+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
58064+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
58065+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
58066+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58067+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58068+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58069+4 4 4 4 4 4
58070+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
58071+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
58072+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
58073+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
58074+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
58075+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
58076+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
58077+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
58078+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
58079+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
58080+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
58081+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58082+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58083+4 4 4 4 4 4
58084+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
58085+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
58086+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
58087+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
58088+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
58089+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
58090+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
58091+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
58092+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
58093+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
58094+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
58095+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58096+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58097+4 4 4 4 4 4
58098+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
58099+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
58100+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
58101+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
58102+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
58103+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
58104+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
58105+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
58106+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
58107+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
58108+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58109+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58111+4 4 4 4 4 4
58112+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
58113+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
58114+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
58115+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
58116+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58117+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
58118+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
58119+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
58120+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
58121+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
58122+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58123+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58124+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58125+4 4 4 4 4 4
58126+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
58127+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
58128+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
58129+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
58130+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58131+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
58132+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
58133+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
58134+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
58135+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
58136+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58139+4 4 4 4 4 4
58140+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
58141+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
58142+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
58143+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
58144+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58145+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
58146+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
58147+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
58148+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
58149+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58150+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58151+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58153+4 4 4 4 4 4
58154+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
58155+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
58156+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
58157+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
58158+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
58159+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
58160+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
58161+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
58162+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58163+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58164+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58167+4 4 4 4 4 4
58168+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
58169+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
58170+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
58171+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
58172+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58173+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
58174+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
58175+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
58176+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
58177+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58178+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58181+4 4 4 4 4 4
58182+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
58183+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
58184+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
58185+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
58186+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
58187+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
58188+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
58189+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
58190+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58191+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58192+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58195+4 4 4 4 4 4
58196+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
58197+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
58198+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
58199+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
58200+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
58201+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
58202+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
58203+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
58204+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
58205+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58206+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58209+4 4 4 4 4 4
58210+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
58211+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
58212+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
58213+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
58214+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
58215+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
58216+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
58217+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
58218+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58219+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58220+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58223+4 4 4 4 4 4
58224+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
58225+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
58226+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
58227+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
58228+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
58229+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
58230+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
58231+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
58232+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
58233+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58234+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58237+4 4 4 4 4 4
58238+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
58239+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
58240+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
58241+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
58242+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
58243+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
58244+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
58245+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
58246+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58247+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58248+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58251+4 4 4 4 4 4
58252+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58253+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
58254+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
58255+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
58256+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
58257+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
58258+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
58259+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
58260+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
58261+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58262+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58265+4 4 4 4 4 4
58266+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
58267+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
58268+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
58269+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
58270+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
58271+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
58272+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58273+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
58274+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
58275+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58276+0 0 0 3 3 3 5 5 5 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 4 4 4
58278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58279+4 4 4 4 4 4
58280+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58281+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
58282+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
58283+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
58284+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
58285+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
58286+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
58287+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
58288+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
58289+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58290+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58293+4 4 4 4 4 4
58294+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
58295+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
58296+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
58297+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
58298+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
58299+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
58300+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
58301+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
58302+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
58303+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58304+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
58307+4 4 4 4 4 4
58308+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58309+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
58310+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
58311+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
58312+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
58313+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
58314+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
58315+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
58316+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
58317+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58318+0 0 0 3 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4
58321+4 4 4 4 4 4
58322+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
58323+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
58324+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
58325+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
58326+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
58327+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
58328+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
58329+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
58330+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
58331+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58332+0 0 0 3 3 3 5 5 5 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 4 4 4
58335+4 4 4 4 4 4
58336+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58337+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
58338+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
58339+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
58340+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
58341+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
58342+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
58343+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
58344+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
58345+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58346+0 0 0 3 3 3 5 5 5 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 4 4 4
58350+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
58351+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
58352+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
58353+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
58354+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
58355+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
58356+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
58357+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
58358+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
58359+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
58360+0 0 0 3 3 3 5 5 5 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 4 4 4
58364+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
58365+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
58366+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
58367+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
58368+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
58369+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
58370+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
58371+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
58372+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
58373+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
58374+0 0 0 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
58378+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
58379+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
58380+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
58381+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
58382+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
58383+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
58384+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58385+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
58386+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
58387+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
58388+4 3 3 5 5 5 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
58392+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
58393+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
58394+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
58395+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
58396+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
58397+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
58398+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
58399+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
58400+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
58401+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
58402+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58403+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58404+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58405+4 4 4 4 4 4
58406+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
58407+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
58408+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
58409+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
58410+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
58411+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
58412+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
58413+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
58414+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
58415+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
58416+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58417+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58418+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58419+4 4 4 4 4 4
58420+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58421+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
58422+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
58423+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
58424+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
58425+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
58426+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
58427+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
58428+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
58429+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58430+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58431+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58433+4 4 4 4 4 4
58434+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
58435+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
58436+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
58437+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
58438+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
58439+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
58440+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
58441+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
58442+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
58443+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
58444+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58445+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58447+4 4 4 4 4 4
58448+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
58449+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
58450+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
58451+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
58452+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
58453+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
58454+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
58455+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
58456+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
58457+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58458+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58459+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58460+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58461+4 4 4 4 4 4
58462+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
58463+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58464+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
58465+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
58466+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
58467+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
58468+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
58469+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
58470+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
58471+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58472+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58473+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58474+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58475+4 4 4 4 4 4
58476+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
58477+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
58478+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
58479+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
58480+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
58481+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
58482+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
58483+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
58484+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
58485+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58486+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58487+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58488+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58489+4 4 4 4 4 4
58490+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
58491+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
58492+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
58493+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
58494+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
58495+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
58496+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
58497+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
58498+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58499+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58500+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58501+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58502+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58503+4 4 4 4 4 4
58504+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
58505+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
58506+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58507+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
58508+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
58509+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
58510+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
58511+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
58512+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58513+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58514+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58515+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58516+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58517+4 4 4 4 4 4
58518+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58519+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
58520+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
58521+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
58522+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
58523+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
58524+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
58525+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58526+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58527+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58528+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58529+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58530+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58531+4 4 4 4 4 4
58532+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58533+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
58534+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58535+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
58536+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
58537+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
58538+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
58539+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
58540+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58541+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58542+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58543+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58544+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58545+4 4 4 4 4 4
58546+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58547+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
58548+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
58549+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
58550+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
58551+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
58552+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
58553+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
58554+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58555+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58556+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58557+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58558+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58559+4 4 4 4 4 4
58560+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58561+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
58562+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
58563+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
58564+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
58565+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
58566+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
58567+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58568+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58569+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58571+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58572+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58573+4 4 4 4 4 4
58574+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58575+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58576+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
58577+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
58578+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
58579+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
58580+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
58581+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58582+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58583+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58584+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58585+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58586+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58587+4 4 4 4 4 4
58588+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58589+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58590+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58591+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58592+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
58593+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
58594+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
58595+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58596+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58597+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58599+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58600+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58601+4 4 4 4 4 4
58602+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58603+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58604+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58605+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
58606+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58607+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
58608+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
58609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58615+4 4 4 4 4 4
58616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58619+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
58620+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58621+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
58622+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
58623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58629+4 4 4 4 4 4
58630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58633+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
58634+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
58635+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
58636+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
58637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58643+4 4 4 4 4 4
58644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58648+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
58649+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58650+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58657+4 4 4 4 4 4
58658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58662+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
58663+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
58664+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
58665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58671+4 4 4 4 4 4
58672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58676+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
58677+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
58678+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58685+4 4 4 4 4 4
58686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58690+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
58691+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
58692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58699+4 4 4 4 4 4
58700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58704+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58705+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
58706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58713+4 4 4 4 4 4
58714diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
58715index fef20db..d28b1ab 100644
58716--- a/drivers/xen/xenfs/xenstored.c
58717+++ b/drivers/xen/xenfs/xenstored.c
58718@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
58719 static int xsd_kva_open(struct inode *inode, struct file *file)
58720 {
58721 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
58722+#ifdef CONFIG_GRKERNSEC_HIDESYM
58723+ NULL);
58724+#else
58725 xen_store_interface);
58726+#endif
58727+
58728 if (!file->private_data)
58729 return -ENOMEM;
58730 return 0;
58731diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
58732index cc1cfae..41158ad 100644
58733--- a/fs/9p/vfs_addr.c
58734+++ b/fs/9p/vfs_addr.c
58735@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
58736
58737 retval = v9fs_file_write_internal(inode,
58738 v9inode->writeback_fid,
58739- (__force const char __user *)buffer,
58740+ (const char __force_user *)buffer,
58741 len, &offset, 0);
58742 if (retval > 0)
58743 retval = 0;
58744diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
58745index 7fa4f7a..a7ebf8c 100644
58746--- a/fs/9p/vfs_inode.c
58747+++ b/fs/9p/vfs_inode.c
58748@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
58749 void
58750 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
58751 {
58752- char *s = nd_get_link(nd);
58753+ const char *s = nd_get_link(nd);
58754
58755 p9_debug(P9_DEBUG_VFS, " %s %s\n",
58756 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
58757diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
58758index 370b24c..ff0be7b 100644
58759--- a/fs/Kconfig.binfmt
58760+++ b/fs/Kconfig.binfmt
58761@@ -103,7 +103,7 @@ config HAVE_AOUT
58762
58763 config BINFMT_AOUT
58764 tristate "Kernel support for a.out and ECOFF binaries"
58765- depends on HAVE_AOUT
58766+ depends on HAVE_AOUT && BROKEN
58767 ---help---
58768 A.out (Assembler.OUTput) is a set of formats for libraries and
58769 executables used in the earliest versions of UNIX. Linux used
58770diff --git a/fs/afs/inode.c b/fs/afs/inode.c
58771index 2946712..f737435 100644
58772--- a/fs/afs/inode.c
58773+++ b/fs/afs/inode.c
58774@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58775 struct afs_vnode *vnode;
58776 struct super_block *sb;
58777 struct inode *inode;
58778- static atomic_t afs_autocell_ino;
58779+ static atomic_unchecked_t afs_autocell_ino;
58780
58781 _enter("{%x:%u},%*.*s,",
58782 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
58783@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58784 data.fid.unique = 0;
58785 data.fid.vnode = 0;
58786
58787- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
58788+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
58789 afs_iget5_autocell_test, afs_iget5_set,
58790 &data);
58791 if (!inode) {
58792diff --git a/fs/aio.c b/fs/aio.c
58793index 0ff7c46..7f5d132 100644
58794--- a/fs/aio.c
58795+++ b/fs/aio.c
58796@@ -388,7 +388,7 @@ static int aio_setup_ring(struct kioctx *ctx)
58797 size += sizeof(struct io_event) * nr_events;
58798
58799 nr_pages = PFN_UP(size);
58800- if (nr_pages < 0)
58801+ if (nr_pages <= 0)
58802 return -EINVAL;
58803
58804 file = aio_private_file(ctx, nr_pages);
58805diff --git a/fs/attr.c b/fs/attr.c
58806index 6530ced..4a827e2 100644
58807--- a/fs/attr.c
58808+++ b/fs/attr.c
58809@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
58810 unsigned long limit;
58811
58812 limit = rlimit(RLIMIT_FSIZE);
58813+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
58814 if (limit != RLIM_INFINITY && offset > limit)
58815 goto out_sig;
58816 if (offset > inode->i_sb->s_maxbytes)
58817diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
58818index 116fd38..c04182da 100644
58819--- a/fs/autofs4/waitq.c
58820+++ b/fs/autofs4/waitq.c
58821@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
58822 {
58823 unsigned long sigpipe, flags;
58824 mm_segment_t fs;
58825- const char *data = (const char *)addr;
58826+ const char __user *data = (const char __force_user *)addr;
58827 ssize_t wr = 0;
58828
58829 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
58830@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
58831 return 1;
58832 }
58833
58834+#ifdef CONFIG_GRKERNSEC_HIDESYM
58835+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
58836+#endif
58837+
58838 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58839 enum autofs_notify notify)
58840 {
58841@@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58842
58843 /* If this is a direct mount request create a dummy name */
58844 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
58845+#ifdef CONFIG_GRKERNSEC_HIDESYM
58846+ /* this name does get written to userland via autofs4_write() */
58847+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
58848+#else
58849 qstr.len = sprintf(name, "%p", dentry);
58850+#endif
58851 else {
58852 qstr.len = autofs4_getpath(sbi, dentry, &name);
58853 if (!qstr.len) {
58854diff --git a/fs/befs/endian.h b/fs/befs/endian.h
58855index 2722387..56059b5 100644
58856--- a/fs/befs/endian.h
58857+++ b/fs/befs/endian.h
58858@@ -11,7 +11,7 @@
58859
58860 #include <asm/byteorder.h>
58861
58862-static inline u64
58863+static inline u64 __intentional_overflow(-1)
58864 fs64_to_cpu(const struct super_block *sb, fs64 n)
58865 {
58866 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58867@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
58868 return (__force fs64)cpu_to_be64(n);
58869 }
58870
58871-static inline u32
58872+static inline u32 __intentional_overflow(-1)
58873 fs32_to_cpu(const struct super_block *sb, fs32 n)
58874 {
58875 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58876@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
58877 return (__force fs32)cpu_to_be32(n);
58878 }
58879
58880-static inline u16
58881+static inline u16 __intentional_overflow(-1)
58882 fs16_to_cpu(const struct super_block *sb, fs16 n)
58883 {
58884 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58885diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
58886index ca0ba15..0fa3257 100644
58887--- a/fs/binfmt_aout.c
58888+++ b/fs/binfmt_aout.c
58889@@ -16,6 +16,7 @@
58890 #include <linux/string.h>
58891 #include <linux/fs.h>
58892 #include <linux/file.h>
58893+#include <linux/security.h>
58894 #include <linux/stat.h>
58895 #include <linux/fcntl.h>
58896 #include <linux/ptrace.h>
58897@@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
58898 #endif
58899 # define START_STACK(u) ((void __user *)u.start_stack)
58900
58901+ memset(&dump, 0, sizeof(dump));
58902+
58903 fs = get_fs();
58904 set_fs(KERNEL_DS);
58905 has_dumped = 1;
58906@@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
58907
58908 /* If the size of the dump file exceeds the rlimit, then see what would happen
58909 if we wrote the stack, but not the data area. */
58910+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
58911 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
58912 dump.u_dsize = 0;
58913
58914 /* Make sure we have enough room to write the stack and data areas. */
58915+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
58916 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
58917 dump.u_ssize = 0;
58918
58919@@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
58920 rlim = rlimit(RLIMIT_DATA);
58921 if (rlim >= RLIM_INFINITY)
58922 rlim = ~0;
58923+
58924+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
58925 if (ex.a_data + ex.a_bss > rlim)
58926 return -ENOMEM;
58927
58928@@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
58929
58930 install_exec_creds(bprm);
58931
58932+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58933+ current->mm->pax_flags = 0UL;
58934+#endif
58935+
58936+#ifdef CONFIG_PAX_PAGEEXEC
58937+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
58938+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
58939+
58940+#ifdef CONFIG_PAX_EMUTRAMP
58941+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
58942+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
58943+#endif
58944+
58945+#ifdef CONFIG_PAX_MPROTECT
58946+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
58947+ current->mm->pax_flags |= MF_PAX_MPROTECT;
58948+#endif
58949+
58950+ }
58951+#endif
58952+
58953 if (N_MAGIC(ex) == OMAGIC) {
58954 unsigned long text_addr, map_size;
58955 loff_t pos;
58956@@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
58957 }
58958
58959 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
58960- PROT_READ | PROT_WRITE | PROT_EXEC,
58961+ PROT_READ | PROT_WRITE,
58962 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
58963 fd_offset + ex.a_text);
58964 if (error != N_DATADDR(ex)) {
58965diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
58966index 3892c1a..4e27c04 100644
58967--- a/fs/binfmt_elf.c
58968+++ b/fs/binfmt_elf.c
58969@@ -34,6 +34,7 @@
58970 #include <linux/utsname.h>
58971 #include <linux/coredump.h>
58972 #include <linux/sched.h>
58973+#include <linux/xattr.h>
58974 #include <asm/uaccess.h>
58975 #include <asm/param.h>
58976 #include <asm/page.h>
58977@@ -47,7 +48,7 @@
58978
58979 static int load_elf_binary(struct linux_binprm *bprm);
58980 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
58981- int, int, unsigned long);
58982+ int, int, unsigned long) __intentional_overflow(-1);
58983
58984 #ifdef CONFIG_USELIB
58985 static int load_elf_library(struct file *);
58986@@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
58987 #define elf_core_dump NULL
58988 #endif
58989
58990+#ifdef CONFIG_PAX_MPROTECT
58991+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
58992+#endif
58993+
58994+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58995+static void elf_handle_mmap(struct file *file);
58996+#endif
58997+
58998 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
58999 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
59000 #else
59001@@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
59002 .load_binary = load_elf_binary,
59003 .load_shlib = load_elf_library,
59004 .core_dump = elf_core_dump,
59005+
59006+#ifdef CONFIG_PAX_MPROTECT
59007+ .handle_mprotect= elf_handle_mprotect,
59008+#endif
59009+
59010+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59011+ .handle_mmap = elf_handle_mmap,
59012+#endif
59013+
59014 .min_coredump = ELF_EXEC_PAGESIZE,
59015 };
59016
59017@@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
59018
59019 static int set_brk(unsigned long start, unsigned long end)
59020 {
59021+ unsigned long e = end;
59022+
59023 start = ELF_PAGEALIGN(start);
59024 end = ELF_PAGEALIGN(end);
59025 if (end > start) {
59026@@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
59027 if (BAD_ADDR(addr))
59028 return addr;
59029 }
59030- current->mm->start_brk = current->mm->brk = end;
59031+ current->mm->start_brk = current->mm->brk = e;
59032 return 0;
59033 }
59034
59035@@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
59036 elf_addr_t __user *u_rand_bytes;
59037 const char *k_platform = ELF_PLATFORM;
59038 const char *k_base_platform = ELF_BASE_PLATFORM;
59039- unsigned char k_rand_bytes[16];
59040+ u32 k_rand_bytes[4];
59041 int items;
59042 elf_addr_t *elf_info;
59043 int ei_index = 0;
59044 const struct cred *cred = current_cred();
59045 struct vm_area_struct *vma;
59046+ unsigned long saved_auxv[AT_VECTOR_SIZE];
59047
59048 /*
59049 * In some cases (e.g. Hyper-Threading), we want to avoid L1
59050@@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
59051 * Generate 16 random bytes for userspace PRNG seeding.
59052 */
59053 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
59054- u_rand_bytes = (elf_addr_t __user *)
59055- STACK_ALLOC(p, sizeof(k_rand_bytes));
59056+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
59057+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
59058+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
59059+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
59060+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
59061+ u_rand_bytes = (elf_addr_t __user *) p;
59062 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
59063 return -EFAULT;
59064
59065@@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
59066 return -EFAULT;
59067 current->mm->env_end = p;
59068
59069+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
59070+
59071 /* Put the elf_info on the stack in the right place. */
59072 sp = (elf_addr_t __user *)envp + 1;
59073- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
59074+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
59075 return -EFAULT;
59076 return 0;
59077 }
59078@@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
59079 an ELF header */
59080
59081 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59082- struct file *interpreter, unsigned long *interp_map_addr,
59083- unsigned long no_base)
59084+ struct file *interpreter, unsigned long no_base)
59085 {
59086 struct elf_phdr *elf_phdata;
59087 struct elf_phdr *eppnt;
59088- unsigned long load_addr = 0;
59089+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
59090 int load_addr_set = 0;
59091 unsigned long last_bss = 0, elf_bss = 0;
59092- unsigned long error = ~0UL;
59093+ unsigned long error = -EINVAL;
59094 unsigned long total_size;
59095 int retval, i, size;
59096
59097@@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59098 goto out_close;
59099 }
59100
59101+#ifdef CONFIG_PAX_SEGMEXEC
59102+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
59103+ pax_task_size = SEGMEXEC_TASK_SIZE;
59104+#endif
59105+
59106 eppnt = elf_phdata;
59107 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
59108 if (eppnt->p_type == PT_LOAD) {
59109@@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59110 map_addr = elf_map(interpreter, load_addr + vaddr,
59111 eppnt, elf_prot, elf_type, total_size);
59112 total_size = 0;
59113- if (!*interp_map_addr)
59114- *interp_map_addr = map_addr;
59115 error = map_addr;
59116 if (BAD_ADDR(map_addr))
59117 goto out_close;
59118@@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59119 k = load_addr + eppnt->p_vaddr;
59120 if (BAD_ADDR(k) ||
59121 eppnt->p_filesz > eppnt->p_memsz ||
59122- eppnt->p_memsz > TASK_SIZE ||
59123- TASK_SIZE - eppnt->p_memsz < k) {
59124+ eppnt->p_memsz > pax_task_size ||
59125+ pax_task_size - eppnt->p_memsz < k) {
59126 error = -ENOMEM;
59127 goto out_close;
59128 }
59129@@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
59130 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
59131
59132 /* Map the last of the bss segment */
59133- error = vm_brk(elf_bss, last_bss - elf_bss);
59134- if (BAD_ADDR(error))
59135- goto out_close;
59136+ if (last_bss > elf_bss) {
59137+ error = vm_brk(elf_bss, last_bss - elf_bss);
59138+ if (BAD_ADDR(error))
59139+ goto out_close;
59140+ }
59141 }
59142
59143 error = load_addr;
59144@@ -543,6 +574,336 @@ out:
59145 return error;
59146 }
59147
59148+#ifdef CONFIG_PAX_PT_PAX_FLAGS
59149+#ifdef CONFIG_PAX_SOFTMODE
59150+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
59151+{
59152+ unsigned long pax_flags = 0UL;
59153+
59154+#ifdef CONFIG_PAX_PAGEEXEC
59155+ if (elf_phdata->p_flags & PF_PAGEEXEC)
59156+ pax_flags |= MF_PAX_PAGEEXEC;
59157+#endif
59158+
59159+#ifdef CONFIG_PAX_SEGMEXEC
59160+ if (elf_phdata->p_flags & PF_SEGMEXEC)
59161+ pax_flags |= MF_PAX_SEGMEXEC;
59162+#endif
59163+
59164+#ifdef CONFIG_PAX_EMUTRAMP
59165+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
59166+ pax_flags |= MF_PAX_EMUTRAMP;
59167+#endif
59168+
59169+#ifdef CONFIG_PAX_MPROTECT
59170+ if (elf_phdata->p_flags & PF_MPROTECT)
59171+ pax_flags |= MF_PAX_MPROTECT;
59172+#endif
59173+
59174+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59175+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
59176+ pax_flags |= MF_PAX_RANDMMAP;
59177+#endif
59178+
59179+ return pax_flags;
59180+}
59181+#endif
59182+
59183+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
59184+{
59185+ unsigned long pax_flags = 0UL;
59186+
59187+#ifdef CONFIG_PAX_PAGEEXEC
59188+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
59189+ pax_flags |= MF_PAX_PAGEEXEC;
59190+#endif
59191+
59192+#ifdef CONFIG_PAX_SEGMEXEC
59193+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
59194+ pax_flags |= MF_PAX_SEGMEXEC;
59195+#endif
59196+
59197+#ifdef CONFIG_PAX_EMUTRAMP
59198+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
59199+ pax_flags |= MF_PAX_EMUTRAMP;
59200+#endif
59201+
59202+#ifdef CONFIG_PAX_MPROTECT
59203+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
59204+ pax_flags |= MF_PAX_MPROTECT;
59205+#endif
59206+
59207+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59208+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
59209+ pax_flags |= MF_PAX_RANDMMAP;
59210+#endif
59211+
59212+ return pax_flags;
59213+}
59214+#endif
59215+
59216+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
59217+#ifdef CONFIG_PAX_SOFTMODE
59218+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
59219+{
59220+ unsigned long pax_flags = 0UL;
59221+
59222+#ifdef CONFIG_PAX_PAGEEXEC
59223+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
59224+ pax_flags |= MF_PAX_PAGEEXEC;
59225+#endif
59226+
59227+#ifdef CONFIG_PAX_SEGMEXEC
59228+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
59229+ pax_flags |= MF_PAX_SEGMEXEC;
59230+#endif
59231+
59232+#ifdef CONFIG_PAX_EMUTRAMP
59233+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
59234+ pax_flags |= MF_PAX_EMUTRAMP;
59235+#endif
59236+
59237+#ifdef CONFIG_PAX_MPROTECT
59238+ if (pax_flags_softmode & MF_PAX_MPROTECT)
59239+ pax_flags |= MF_PAX_MPROTECT;
59240+#endif
59241+
59242+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59243+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
59244+ pax_flags |= MF_PAX_RANDMMAP;
59245+#endif
59246+
59247+ return pax_flags;
59248+}
59249+#endif
59250+
59251+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
59252+{
59253+ unsigned long pax_flags = 0UL;
59254+
59255+#ifdef CONFIG_PAX_PAGEEXEC
59256+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
59257+ pax_flags |= MF_PAX_PAGEEXEC;
59258+#endif
59259+
59260+#ifdef CONFIG_PAX_SEGMEXEC
59261+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
59262+ pax_flags |= MF_PAX_SEGMEXEC;
59263+#endif
59264+
59265+#ifdef CONFIG_PAX_EMUTRAMP
59266+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
59267+ pax_flags |= MF_PAX_EMUTRAMP;
59268+#endif
59269+
59270+#ifdef CONFIG_PAX_MPROTECT
59271+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
59272+ pax_flags |= MF_PAX_MPROTECT;
59273+#endif
59274+
59275+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
59276+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
59277+ pax_flags |= MF_PAX_RANDMMAP;
59278+#endif
59279+
59280+ return pax_flags;
59281+}
59282+#endif
59283+
59284+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59285+static unsigned long pax_parse_defaults(void)
59286+{
59287+ unsigned long pax_flags = 0UL;
59288+
59289+#ifdef CONFIG_PAX_SOFTMODE
59290+ if (pax_softmode)
59291+ return pax_flags;
59292+#endif
59293+
59294+#ifdef CONFIG_PAX_PAGEEXEC
59295+ pax_flags |= MF_PAX_PAGEEXEC;
59296+#endif
59297+
59298+#ifdef CONFIG_PAX_SEGMEXEC
59299+ pax_flags |= MF_PAX_SEGMEXEC;
59300+#endif
59301+
59302+#ifdef CONFIG_PAX_MPROTECT
59303+ pax_flags |= MF_PAX_MPROTECT;
59304+#endif
59305+
59306+#ifdef CONFIG_PAX_RANDMMAP
59307+ if (randomize_va_space)
59308+ pax_flags |= MF_PAX_RANDMMAP;
59309+#endif
59310+
59311+ return pax_flags;
59312+}
59313+
59314+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
59315+{
59316+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
59317+
59318+#ifdef CONFIG_PAX_EI_PAX
59319+
59320+#ifdef CONFIG_PAX_SOFTMODE
59321+ if (pax_softmode)
59322+ return pax_flags;
59323+#endif
59324+
59325+ pax_flags = 0UL;
59326+
59327+#ifdef CONFIG_PAX_PAGEEXEC
59328+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
59329+ pax_flags |= MF_PAX_PAGEEXEC;
59330+#endif
59331+
59332+#ifdef CONFIG_PAX_SEGMEXEC
59333+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
59334+ pax_flags |= MF_PAX_SEGMEXEC;
59335+#endif
59336+
59337+#ifdef CONFIG_PAX_EMUTRAMP
59338+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
59339+ pax_flags |= MF_PAX_EMUTRAMP;
59340+#endif
59341+
59342+#ifdef CONFIG_PAX_MPROTECT
59343+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
59344+ pax_flags |= MF_PAX_MPROTECT;
59345+#endif
59346+
59347+#ifdef CONFIG_PAX_ASLR
59348+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
59349+ pax_flags |= MF_PAX_RANDMMAP;
59350+#endif
59351+
59352+#endif
59353+
59354+ return pax_flags;
59355+
59356+}
59357+
59358+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
59359+{
59360+
59361+#ifdef CONFIG_PAX_PT_PAX_FLAGS
59362+ unsigned long i;
59363+
59364+ for (i = 0UL; i < elf_ex->e_phnum; i++)
59365+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
59366+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
59367+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
59368+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
59369+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
59370+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
59371+ return PAX_PARSE_FLAGS_FALLBACK;
59372+
59373+#ifdef CONFIG_PAX_SOFTMODE
59374+ if (pax_softmode)
59375+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
59376+ else
59377+#endif
59378+
59379+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
59380+ break;
59381+ }
59382+#endif
59383+
59384+ return PAX_PARSE_FLAGS_FALLBACK;
59385+}
59386+
59387+static unsigned long pax_parse_xattr_pax(struct file * const file)
59388+{
59389+
59390+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
59391+ ssize_t xattr_size, i;
59392+ unsigned char xattr_value[sizeof("pemrs") - 1];
59393+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
59394+
59395+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
59396+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
59397+ return PAX_PARSE_FLAGS_FALLBACK;
59398+
59399+ for (i = 0; i < xattr_size; i++)
59400+ switch (xattr_value[i]) {
59401+ default:
59402+ return PAX_PARSE_FLAGS_FALLBACK;
59403+
59404+#define parse_flag(option1, option2, flag) \
59405+ case option1: \
59406+ if (pax_flags_hardmode & MF_PAX_##flag) \
59407+ return PAX_PARSE_FLAGS_FALLBACK;\
59408+ pax_flags_hardmode |= MF_PAX_##flag; \
59409+ break; \
59410+ case option2: \
59411+ if (pax_flags_softmode & MF_PAX_##flag) \
59412+ return PAX_PARSE_FLAGS_FALLBACK;\
59413+ pax_flags_softmode |= MF_PAX_##flag; \
59414+ break;
59415+
59416+ parse_flag('p', 'P', PAGEEXEC);
59417+ parse_flag('e', 'E', EMUTRAMP);
59418+ parse_flag('m', 'M', MPROTECT);
59419+ parse_flag('r', 'R', RANDMMAP);
59420+ parse_flag('s', 'S', SEGMEXEC);
59421+
59422+#undef parse_flag
59423+ }
59424+
59425+ if (pax_flags_hardmode & pax_flags_softmode)
59426+ return PAX_PARSE_FLAGS_FALLBACK;
59427+
59428+#ifdef CONFIG_PAX_SOFTMODE
59429+ if (pax_softmode)
59430+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
59431+ else
59432+#endif
59433+
59434+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
59435+#else
59436+ return PAX_PARSE_FLAGS_FALLBACK;
59437+#endif
59438+
59439+}
59440+
59441+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
59442+{
59443+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
59444+
59445+ pax_flags = pax_parse_defaults();
59446+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
59447+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
59448+ xattr_pax_flags = pax_parse_xattr_pax(file);
59449+
59450+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
59451+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
59452+ pt_pax_flags != xattr_pax_flags)
59453+ return -EINVAL;
59454+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59455+ pax_flags = xattr_pax_flags;
59456+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59457+ pax_flags = pt_pax_flags;
59458+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59459+ pax_flags = ei_pax_flags;
59460+
59461+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
59462+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59463+ if ((__supported_pte_mask & _PAGE_NX))
59464+ pax_flags &= ~MF_PAX_SEGMEXEC;
59465+ else
59466+ pax_flags &= ~MF_PAX_PAGEEXEC;
59467+ }
59468+#endif
59469+
59470+ if (0 > pax_check_flags(&pax_flags))
59471+ return -EINVAL;
59472+
59473+ current->mm->pax_flags = pax_flags;
59474+ return 0;
59475+}
59476+#endif
59477+
59478 /*
59479 * These are the functions used to load ELF style executables and shared
59480 * libraries. There is no binary dependent code anywhere else.
59481@@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
59482 {
59483 unsigned int random_variable = 0;
59484
59485+#ifdef CONFIG_PAX_RANDUSTACK
59486+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
59487+ return stack_top - current->mm->delta_stack;
59488+#endif
59489+
59490 if ((current->flags & PF_RANDOMIZE) &&
59491 !(current->personality & ADDR_NO_RANDOMIZE)) {
59492 random_variable = get_random_int() & STACK_RND_MASK;
59493@@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59494 unsigned long load_addr = 0, load_bias = 0;
59495 int load_addr_set = 0;
59496 char * elf_interpreter = NULL;
59497- unsigned long error;
59498+ unsigned long error = 0;
59499 struct elf_phdr *elf_ppnt, *elf_phdata;
59500 unsigned long elf_bss, elf_brk;
59501 int retval, i;
59502@@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59503 struct elfhdr elf_ex;
59504 struct elfhdr interp_elf_ex;
59505 } *loc;
59506+ unsigned long pax_task_size;
59507
59508 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
59509 if (!loc) {
59510@@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
59511 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
59512 may depend on the personality. */
59513 SET_PERSONALITY(loc->elf_ex);
59514+
59515+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59516+ current->mm->pax_flags = 0UL;
59517+#endif
59518+
59519+#ifdef CONFIG_PAX_DLRESOLVE
59520+ current->mm->call_dl_resolve = 0UL;
59521+#endif
59522+
59523+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
59524+ current->mm->call_syscall = 0UL;
59525+#endif
59526+
59527+#ifdef CONFIG_PAX_ASLR
59528+ current->mm->delta_mmap = 0UL;
59529+ current->mm->delta_stack = 0UL;
59530+#endif
59531+
59532+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59533+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
59534+ send_sig(SIGKILL, current, 0);
59535+ goto out_free_dentry;
59536+ }
59537+#endif
59538+
59539+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
59540+ pax_set_initial_flags(bprm);
59541+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
59542+ if (pax_set_initial_flags_func)
59543+ (pax_set_initial_flags_func)(bprm);
59544+#endif
59545+
59546+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59547+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
59548+ current->mm->context.user_cs_limit = PAGE_SIZE;
59549+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
59550+ }
59551+#endif
59552+
59553+#ifdef CONFIG_PAX_SEGMEXEC
59554+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
59555+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
59556+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
59557+ pax_task_size = SEGMEXEC_TASK_SIZE;
59558+ current->mm->def_flags |= VM_NOHUGEPAGE;
59559+ } else
59560+#endif
59561+
59562+ pax_task_size = TASK_SIZE;
59563+
59564+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
59565+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59566+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
59567+ put_cpu();
59568+ }
59569+#endif
59570+
59571+#ifdef CONFIG_PAX_ASLR
59572+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
59573+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
59574+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
59575+ }
59576+#endif
59577+
59578+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59579+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59580+ executable_stack = EXSTACK_DISABLE_X;
59581+ current->personality &= ~READ_IMPLIES_EXEC;
59582+ } else
59583+#endif
59584+
59585 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
59586 current->personality |= READ_IMPLIES_EXEC;
59587
59588@@ -815,6 +1253,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
59589 #else
59590 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
59591 #endif
59592+
59593+#ifdef CONFIG_PAX_RANDMMAP
59594+ /* PaX: randomize base address at the default exe base if requested */
59595+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
59596+#ifdef CONFIG_SPARC64
59597+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
59598+#else
59599+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
59600+#endif
59601+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
59602+ elf_flags |= MAP_FIXED;
59603+ }
59604+#endif
59605+
59606 }
59607
59608 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
59609@@ -847,9 +1299,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
59610 * allowed task size. Note that p_filesz must always be
59611 * <= p_memsz so it is only necessary to check p_memsz.
59612 */
59613- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
59614- elf_ppnt->p_memsz > TASK_SIZE ||
59615- TASK_SIZE - elf_ppnt->p_memsz < k) {
59616+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
59617+ elf_ppnt->p_memsz > pax_task_size ||
59618+ pax_task_size - elf_ppnt->p_memsz < k) {
59619 /* set_brk can never work. Avoid overflows. */
59620 send_sig(SIGKILL, current, 0);
59621 retval = -EINVAL;
59622@@ -888,17 +1340,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
59623 goto out_free_dentry;
59624 }
59625 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
59626- send_sig(SIGSEGV, current, 0);
59627- retval = -EFAULT; /* Nobody gets to see this, but.. */
59628- goto out_free_dentry;
59629+ /*
59630+ * This bss-zeroing can fail if the ELF
59631+ * file specifies odd protections. So
59632+ * we don't check the return value
59633+ */
59634 }
59635
59636+#ifdef CONFIG_PAX_RANDMMAP
59637+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
59638+ unsigned long start, size, flags;
59639+ vm_flags_t vm_flags;
59640+
59641+ start = ELF_PAGEALIGN(elf_brk);
59642+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
59643+ flags = MAP_FIXED | MAP_PRIVATE;
59644+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
59645+
59646+ down_write(&current->mm->mmap_sem);
59647+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
59648+ retval = -ENOMEM;
59649+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
59650+// if (current->personality & ADDR_NO_RANDOMIZE)
59651+// vm_flags |= VM_READ | VM_MAYREAD;
59652+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
59653+ retval = IS_ERR_VALUE(start) ? start : 0;
59654+ }
59655+ up_write(&current->mm->mmap_sem);
59656+ if (retval == 0)
59657+ retval = set_brk(start + size, start + size + PAGE_SIZE);
59658+ if (retval < 0) {
59659+ send_sig(SIGKILL, current, 0);
59660+ goto out_free_dentry;
59661+ }
59662+ }
59663+#endif
59664+
59665 if (elf_interpreter) {
59666- unsigned long interp_map_addr = 0;
59667-
59668 elf_entry = load_elf_interp(&loc->interp_elf_ex,
59669 interpreter,
59670- &interp_map_addr,
59671 load_bias);
59672 if (!IS_ERR((void *)elf_entry)) {
59673 /*
59674@@ -1130,7 +1610,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
59675 * Decide what to dump of a segment, part, all or none.
59676 */
59677 static unsigned long vma_dump_size(struct vm_area_struct *vma,
59678- unsigned long mm_flags)
59679+ unsigned long mm_flags, long signr)
59680 {
59681 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
59682
59683@@ -1168,7 +1648,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
59684 if (vma->vm_file == NULL)
59685 return 0;
59686
59687- if (FILTER(MAPPED_PRIVATE))
59688+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
59689 goto whole;
59690
59691 /*
59692@@ -1375,9 +1855,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
59693 {
59694 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
59695 int i = 0;
59696- do
59697+ do {
59698 i += 2;
59699- while (auxv[i - 2] != AT_NULL);
59700+ } while (auxv[i - 2] != AT_NULL);
59701 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
59702 }
59703
59704@@ -1386,7 +1866,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
59705 {
59706 mm_segment_t old_fs = get_fs();
59707 set_fs(KERNEL_DS);
59708- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
59709+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
59710 set_fs(old_fs);
59711 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
59712 }
59713@@ -2010,14 +2490,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
59714 }
59715
59716 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
59717- unsigned long mm_flags)
59718+ struct coredump_params *cprm)
59719 {
59720 struct vm_area_struct *vma;
59721 size_t size = 0;
59722
59723 for (vma = first_vma(current, gate_vma); vma != NULL;
59724 vma = next_vma(vma, gate_vma))
59725- size += vma_dump_size(vma, mm_flags);
59726+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59727 return size;
59728 }
59729
59730@@ -2108,7 +2588,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59731
59732 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
59733
59734- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
59735+ offset += elf_core_vma_data_size(gate_vma, cprm);
59736 offset += elf_core_extra_data_size();
59737 e_shoff = offset;
59738
59739@@ -2136,7 +2616,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59740 phdr.p_offset = offset;
59741 phdr.p_vaddr = vma->vm_start;
59742 phdr.p_paddr = 0;
59743- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
59744+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59745 phdr.p_memsz = vma->vm_end - vma->vm_start;
59746 offset += phdr.p_filesz;
59747 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
59748@@ -2169,7 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59749 unsigned long addr;
59750 unsigned long end;
59751
59752- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
59753+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59754
59755 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
59756 struct page *page;
59757@@ -2210,6 +2690,167 @@ out:
59758
59759 #endif /* CONFIG_ELF_CORE */
59760
59761+#ifdef CONFIG_PAX_MPROTECT
59762+/* PaX: non-PIC ELF libraries need relocations on their executable segments
59763+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
59764+ * we'll remove VM_MAYWRITE for good on RELRO segments.
59765+ *
59766+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
59767+ * basis because we want to allow the common case and not the special ones.
59768+ */
59769+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
59770+{
59771+ struct elfhdr elf_h;
59772+ struct elf_phdr elf_p;
59773+ unsigned long i;
59774+ unsigned long oldflags;
59775+ bool is_textrel_rw, is_textrel_rx, is_relro;
59776+
59777+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
59778+ return;
59779+
59780+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
59781+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
59782+
59783+#ifdef CONFIG_PAX_ELFRELOCS
59784+ /* possible TEXTREL */
59785+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
59786+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
59787+#else
59788+ is_textrel_rw = false;
59789+ is_textrel_rx = false;
59790+#endif
59791+
59792+ /* possible RELRO */
59793+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
59794+
59795+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
59796+ return;
59797+
59798+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59799+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59800+
59801+#ifdef CONFIG_PAX_ETEXECRELOCS
59802+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59803+#else
59804+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
59805+#endif
59806+
59807+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59808+ !elf_check_arch(&elf_h) ||
59809+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59810+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59811+ return;
59812+
59813+ for (i = 0UL; i < elf_h.e_phnum; i++) {
59814+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59815+ return;
59816+ switch (elf_p.p_type) {
59817+ case PT_DYNAMIC:
59818+ if (!is_textrel_rw && !is_textrel_rx)
59819+ continue;
59820+ i = 0UL;
59821+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
59822+ elf_dyn dyn;
59823+
59824+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
59825+ break;
59826+ if (dyn.d_tag == DT_NULL)
59827+ break;
59828+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
59829+ gr_log_textrel(vma);
59830+ if (is_textrel_rw)
59831+ vma->vm_flags |= VM_MAYWRITE;
59832+ else
59833+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
59834+ vma->vm_flags &= ~VM_MAYWRITE;
59835+ break;
59836+ }
59837+ i++;
59838+ }
59839+ is_textrel_rw = false;
59840+ is_textrel_rx = false;
59841+ continue;
59842+
59843+ case PT_GNU_RELRO:
59844+ if (!is_relro)
59845+ continue;
59846+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
59847+ vma->vm_flags &= ~VM_MAYWRITE;
59848+ is_relro = false;
59849+ continue;
59850+
59851+#ifdef CONFIG_PAX_PT_PAX_FLAGS
59852+ case PT_PAX_FLAGS: {
59853+ const char *msg_mprotect = "", *msg_emutramp = "";
59854+ char *buffer_lib, *buffer_exe;
59855+
59856+ if (elf_p.p_flags & PF_NOMPROTECT)
59857+ msg_mprotect = "MPROTECT disabled";
59858+
59859+#ifdef CONFIG_PAX_EMUTRAMP
59860+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
59861+ msg_emutramp = "EMUTRAMP enabled";
59862+#endif
59863+
59864+ if (!msg_mprotect[0] && !msg_emutramp[0])
59865+ continue;
59866+
59867+ if (!printk_ratelimit())
59868+ continue;
59869+
59870+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
59871+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
59872+ if (buffer_lib && buffer_exe) {
59873+ char *path_lib, *path_exe;
59874+
59875+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
59876+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
59877+
59878+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
59879+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
59880+
59881+ }
59882+ free_page((unsigned long)buffer_exe);
59883+ free_page((unsigned long)buffer_lib);
59884+ continue;
59885+ }
59886+#endif
59887+
59888+ }
59889+ }
59890+}
59891+#endif
59892+
59893+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59894+
59895+extern int grsec_enable_log_rwxmaps;
59896+
59897+static void elf_handle_mmap(struct file *file)
59898+{
59899+ struct elfhdr elf_h;
59900+ struct elf_phdr elf_p;
59901+ unsigned long i;
59902+
59903+ if (!grsec_enable_log_rwxmaps)
59904+ return;
59905+
59906+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59907+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59908+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
59909+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59910+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59911+ return;
59912+
59913+ for (i = 0UL; i < elf_h.e_phnum; i++) {
59914+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59915+ return;
59916+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
59917+ gr_log_ptgnustack(file);
59918+ }
59919+}
59920+#endif
59921+
59922 static int __init init_elf_binfmt(void)
59923 {
59924 register_binfmt(&elf_format);
59925diff --git a/fs/block_dev.c b/fs/block_dev.c
59926index 6d72746..536d1db 100644
59927--- a/fs/block_dev.c
59928+++ b/fs/block_dev.c
59929@@ -701,7 +701,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
59930 else if (bdev->bd_contains == bdev)
59931 return true; /* is a whole device which isn't held */
59932
59933- else if (whole->bd_holder == bd_may_claim)
59934+ else if (whole->bd_holder == (void *)bd_may_claim)
59935 return true; /* is a partition of a device that is being partitioned */
59936 else if (whole->bd_holder != NULL)
59937 return false; /* is a partition of a held device */
59938diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
59939index 8bbcc24..6f10d78 100644
59940--- a/fs/btrfs/ctree.c
59941+++ b/fs/btrfs/ctree.c
59942@@ -1174,9 +1174,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
59943 free_extent_buffer(buf);
59944 add_root_to_dirty_list(root);
59945 } else {
59946- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
59947- parent_start = parent->start;
59948- else
59949+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
59950+ if (parent)
59951+ parent_start = parent->start;
59952+ else
59953+ parent_start = 0;
59954+ } else
59955 parent_start = 0;
59956
59957 WARN_ON(trans->transid != btrfs_header_generation(parent));
59958diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
59959index a2e90f8..5135e5f 100644
59960--- a/fs/btrfs/delayed-inode.c
59961+++ b/fs/btrfs/delayed-inode.c
59962@@ -462,7 +462,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
59963
59964 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
59965 {
59966- int seq = atomic_inc_return(&delayed_root->items_seq);
59967+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
59968 if ((atomic_dec_return(&delayed_root->items) <
59969 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
59970 waitqueue_active(&delayed_root->wait))
59971@@ -1412,7 +1412,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
59972
59973 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
59974 {
59975- int val = atomic_read(&delayed_root->items_seq);
59976+ int val = atomic_read_unchecked(&delayed_root->items_seq);
59977
59978 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
59979 return 1;
59980@@ -1436,7 +1436,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
59981 int seq;
59982 int ret;
59983
59984- seq = atomic_read(&delayed_root->items_seq);
59985+ seq = atomic_read_unchecked(&delayed_root->items_seq);
59986
59987 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
59988 if (ret)
59989diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
59990index f70119f..ab5894d 100644
59991--- a/fs/btrfs/delayed-inode.h
59992+++ b/fs/btrfs/delayed-inode.h
59993@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
59994 */
59995 struct list_head prepare_list;
59996 atomic_t items; /* for delayed items */
59997- atomic_t items_seq; /* for delayed items */
59998+ atomic_unchecked_t items_seq; /* for delayed items */
59999 int nodes; /* for delayed nodes */
60000 wait_queue_head_t wait;
60001 };
60002@@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
60003 struct btrfs_delayed_root *delayed_root)
60004 {
60005 atomic_set(&delayed_root->items, 0);
60006- atomic_set(&delayed_root->items_seq, 0);
60007+ atomic_set_unchecked(&delayed_root->items_seq, 0);
60008 delayed_root->nodes = 0;
60009 spin_lock_init(&delayed_root->lock);
60010 init_waitqueue_head(&delayed_root->wait);
60011diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
60012index b765d41..5a8b0c3 100644
60013--- a/fs/btrfs/ioctl.c
60014+++ b/fs/btrfs/ioctl.c
60015@@ -3975,9 +3975,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
60016 for (i = 0; i < num_types; i++) {
60017 struct btrfs_space_info *tmp;
60018
60019+ /* Don't copy in more than we allocated */
60020 if (!slot_count)
60021 break;
60022
60023+ slot_count--;
60024+
60025 info = NULL;
60026 rcu_read_lock();
60027 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
60028@@ -3999,10 +4002,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
60029 memcpy(dest, &space, sizeof(space));
60030 dest++;
60031 space_args.total_spaces++;
60032- slot_count--;
60033 }
60034- if (!slot_count)
60035- break;
60036 }
60037 up_read(&info->groups_sem);
60038 }
60039diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
60040index c4124de..d7613eb6 100644
60041--- a/fs/btrfs/super.c
60042+++ b/fs/btrfs/super.c
60043@@ -270,7 +270,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
60044 function, line, errstr);
60045 return;
60046 }
60047- ACCESS_ONCE(trans->transaction->aborted) = errno;
60048+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
60049 /* Wake up anybody who may be waiting on this transaction */
60050 wake_up(&root->fs_info->transaction_wait);
60051 wake_up(&root->fs_info->transaction_blocked_wait);
60052diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
60053index 12e5355..cdf30c6 100644
60054--- a/fs/btrfs/sysfs.c
60055+++ b/fs/btrfs/sysfs.c
60056@@ -475,7 +475,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
60057 for (set = 0; set < FEAT_MAX; set++) {
60058 int i;
60059 struct attribute *attrs[2];
60060- struct attribute_group agroup = {
60061+ attribute_group_no_const agroup = {
60062 .name = "features",
60063 .attrs = attrs,
60064 };
60065diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h
60066index e2e798a..f454c18 100644
60067--- a/fs/btrfs/tree-log.h
60068+++ b/fs/btrfs/tree-log.h
60069@@ -41,7 +41,7 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx)
60070 static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info,
60071 struct btrfs_trans_handle *trans)
60072 {
60073- ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid;
60074+ ACCESS_ONCE_RW(fs_info->last_trans_log_full_commit) = trans->transid;
60075 }
60076
60077 static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info,
60078diff --git a/fs/buffer.c b/fs/buffer.c
60079index 72daaa5..60ffeb9 100644
60080--- a/fs/buffer.c
60081+++ b/fs/buffer.c
60082@@ -3432,7 +3432,7 @@ void __init buffer_init(void)
60083 bh_cachep = kmem_cache_create("buffer_head",
60084 sizeof(struct buffer_head), 0,
60085 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
60086- SLAB_MEM_SPREAD),
60087+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
60088 NULL);
60089
60090 /*
60091diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
60092index fbb08e9..0fda764 100644
60093--- a/fs/cachefiles/bind.c
60094+++ b/fs/cachefiles/bind.c
60095@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
60096 args);
60097
60098 /* start by checking things over */
60099- ASSERT(cache->fstop_percent >= 0 &&
60100- cache->fstop_percent < cache->fcull_percent &&
60101+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
60102 cache->fcull_percent < cache->frun_percent &&
60103 cache->frun_percent < 100);
60104
60105- ASSERT(cache->bstop_percent >= 0 &&
60106- cache->bstop_percent < cache->bcull_percent &&
60107+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
60108 cache->bcull_percent < cache->brun_percent &&
60109 cache->brun_percent < 100);
60110
60111diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
60112index ce1b115..4a6852c 100644
60113--- a/fs/cachefiles/daemon.c
60114+++ b/fs/cachefiles/daemon.c
60115@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
60116 if (n > buflen)
60117 return -EMSGSIZE;
60118
60119- if (copy_to_user(_buffer, buffer, n) != 0)
60120+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
60121 return -EFAULT;
60122
60123 return n;
60124@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
60125 if (test_bit(CACHEFILES_DEAD, &cache->flags))
60126 return -EIO;
60127
60128- if (datalen < 0 || datalen > PAGE_SIZE - 1)
60129+ if (datalen > PAGE_SIZE - 1)
60130 return -EOPNOTSUPP;
60131
60132 /* drag the command string into the kernel so we can parse it */
60133@@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
60134 if (args[0] != '%' || args[1] != '\0')
60135 return -EINVAL;
60136
60137- if (fstop < 0 || fstop >= cache->fcull_percent)
60138+ if (fstop >= cache->fcull_percent)
60139 return cachefiles_daemon_range_error(cache, args);
60140
60141 cache->fstop_percent = fstop;
60142@@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
60143 if (args[0] != '%' || args[1] != '\0')
60144 return -EINVAL;
60145
60146- if (bstop < 0 || bstop >= cache->bcull_percent)
60147+ if (bstop >= cache->bcull_percent)
60148 return cachefiles_daemon_range_error(cache, args);
60149
60150 cache->bstop_percent = bstop;
60151diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
60152index 8c52472..c4e3a69 100644
60153--- a/fs/cachefiles/internal.h
60154+++ b/fs/cachefiles/internal.h
60155@@ -66,7 +66,7 @@ struct cachefiles_cache {
60156 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
60157 struct rb_root active_nodes; /* active nodes (can't be culled) */
60158 rwlock_t active_lock; /* lock for active_nodes */
60159- atomic_t gravecounter; /* graveyard uniquifier */
60160+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
60161 unsigned frun_percent; /* when to stop culling (% files) */
60162 unsigned fcull_percent; /* when to start culling (% files) */
60163 unsigned fstop_percent; /* when to stop allocating (% files) */
60164@@ -178,19 +178,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
60165 * proc.c
60166 */
60167 #ifdef CONFIG_CACHEFILES_HISTOGRAM
60168-extern atomic_t cachefiles_lookup_histogram[HZ];
60169-extern atomic_t cachefiles_mkdir_histogram[HZ];
60170-extern atomic_t cachefiles_create_histogram[HZ];
60171+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
60172+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
60173+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
60174
60175 extern int __init cachefiles_proc_init(void);
60176 extern void cachefiles_proc_cleanup(void);
60177 static inline
60178-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
60179+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
60180 {
60181 unsigned long jif = jiffies - start_jif;
60182 if (jif >= HZ)
60183 jif = HZ - 1;
60184- atomic_inc(&histogram[jif]);
60185+ atomic_inc_unchecked(&histogram[jif]);
60186 }
60187
60188 #else
60189diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
60190index dad7d95..07475af 100644
60191--- a/fs/cachefiles/namei.c
60192+++ b/fs/cachefiles/namei.c
60193@@ -312,7 +312,7 @@ try_again:
60194 /* first step is to make up a grave dentry in the graveyard */
60195 sprintf(nbuffer, "%08x%08x",
60196 (uint32_t) get_seconds(),
60197- (uint32_t) atomic_inc_return(&cache->gravecounter));
60198+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
60199
60200 /* do the multiway lock magic */
60201 trap = lock_rename(cache->graveyard, dir);
60202diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
60203index eccd339..4c1d995 100644
60204--- a/fs/cachefiles/proc.c
60205+++ b/fs/cachefiles/proc.c
60206@@ -14,9 +14,9 @@
60207 #include <linux/seq_file.h>
60208 #include "internal.h"
60209
60210-atomic_t cachefiles_lookup_histogram[HZ];
60211-atomic_t cachefiles_mkdir_histogram[HZ];
60212-atomic_t cachefiles_create_histogram[HZ];
60213+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
60214+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
60215+atomic_unchecked_t cachefiles_create_histogram[HZ];
60216
60217 /*
60218 * display the latency histogram
60219@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
60220 return 0;
60221 default:
60222 index = (unsigned long) v - 3;
60223- x = atomic_read(&cachefiles_lookup_histogram[index]);
60224- y = atomic_read(&cachefiles_mkdir_histogram[index]);
60225- z = atomic_read(&cachefiles_create_histogram[index]);
60226+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
60227+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
60228+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
60229 if (x == 0 && y == 0 && z == 0)
60230 return 0;
60231
60232diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
60233index 25e745b..220e604 100644
60234--- a/fs/cachefiles/rdwr.c
60235+++ b/fs/cachefiles/rdwr.c
60236@@ -937,7 +937,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
60237 old_fs = get_fs();
60238 set_fs(KERNEL_DS);
60239 ret = file->f_op->write(
60240- file, (const void __user *) data, len, &pos);
60241+ file, (const void __force_user *) data, len, &pos);
60242 set_fs(old_fs);
60243 kunmap(page);
60244 file_end_write(file);
60245diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
60246index c29d6ae..719b9bb 100644
60247--- a/fs/ceph/dir.c
60248+++ b/fs/ceph/dir.c
60249@@ -129,6 +129,8 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
60250 struct dentry *dentry, *last;
60251 struct ceph_dentry_info *di;
60252 int err = 0;
60253+ char d_name[DNAME_INLINE_LEN];
60254+ const unsigned char *name;
60255
60256 /* claim ref on last dentry we returned */
60257 last = fi->dentry;
60258@@ -192,7 +194,12 @@ more:
60259
60260 dout(" %llu (%llu) dentry %p %.*s %p\n", di->offset, ctx->pos,
60261 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
60262- if (!dir_emit(ctx, dentry->d_name.name,
60263+ name = dentry->d_name.name;
60264+ if (name == dentry->d_iname) {
60265+ memcpy(d_name, name, dentry->d_name.len);
60266+ name = d_name;
60267+ }
60268+ if (!dir_emit(ctx, name,
60269 dentry->d_name.len,
60270 ceph_translate_ino(dentry->d_sb, dentry->d_inode->i_ino),
60271 dentry->d_inode->i_mode >> 12)) {
60272@@ -250,7 +257,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
60273 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
60274 struct ceph_mds_client *mdsc = fsc->mdsc;
60275 unsigned frag = fpos_frag(ctx->pos);
60276- int off = fpos_off(ctx->pos);
60277+ unsigned int off = fpos_off(ctx->pos);
60278 int err;
60279 u32 ftype;
60280 struct ceph_mds_reply_info_parsed *rinfo;
60281diff --git a/fs/ceph/ioctl.c b/fs/ceph/ioctl.c
60282index a822a6e..4644256 100644
60283--- a/fs/ceph/ioctl.c
60284+++ b/fs/ceph/ioctl.c
60285@@ -41,7 +41,7 @@ static long __validate_layout(struct ceph_mds_client *mdsc,
60286 /* validate striping parameters */
60287 if ((l->object_size & ~PAGE_MASK) ||
60288 (l->stripe_unit & ~PAGE_MASK) ||
60289- (l->stripe_unit != 0 &&
60290+ ((unsigned)l->stripe_unit != 0 &&
60291 ((unsigned)l->object_size % (unsigned)l->stripe_unit)))
60292 return -EINVAL;
60293
60294diff --git a/fs/ceph/super.c b/fs/ceph/super.c
60295index f6e1237..796ffd1 100644
60296--- a/fs/ceph/super.c
60297+++ b/fs/ceph/super.c
60298@@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
60299 /*
60300 * construct our own bdi so we can control readahead, etc.
60301 */
60302-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
60303+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
60304
60305 static int ceph_register_bdi(struct super_block *sb,
60306 struct ceph_fs_client *fsc)
60307@@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
60308 default_backing_dev_info.ra_pages;
60309
60310 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
60311- atomic_long_inc_return(&bdi_seq));
60312+ atomic_long_inc_return_unchecked(&bdi_seq));
60313 if (!err)
60314 sb->s_bdi = &fsc->backing_dev_info;
60315 return err;
60316diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
60317index 44ec726..bcb06a3 100644
60318--- a/fs/cifs/cifs_debug.c
60319+++ b/fs/cifs/cifs_debug.c
60320@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
60321
60322 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
60323 #ifdef CONFIG_CIFS_STATS2
60324- atomic_set(&totBufAllocCount, 0);
60325- atomic_set(&totSmBufAllocCount, 0);
60326+ atomic_set_unchecked(&totBufAllocCount, 0);
60327+ atomic_set_unchecked(&totSmBufAllocCount, 0);
60328 #endif /* CONFIG_CIFS_STATS2 */
60329 spin_lock(&cifs_tcp_ses_lock);
60330 list_for_each(tmp1, &cifs_tcp_ses_list) {
60331@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
60332 tcon = list_entry(tmp3,
60333 struct cifs_tcon,
60334 tcon_list);
60335- atomic_set(&tcon->num_smbs_sent, 0);
60336+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
60337 if (server->ops->clear_stats)
60338 server->ops->clear_stats(tcon);
60339 }
60340@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
60341 smBufAllocCount.counter, cifs_min_small);
60342 #ifdef CONFIG_CIFS_STATS2
60343 seq_printf(m, "Total Large %d Small %d Allocations\n",
60344- atomic_read(&totBufAllocCount),
60345- atomic_read(&totSmBufAllocCount));
60346+ atomic_read_unchecked(&totBufAllocCount),
60347+ atomic_read_unchecked(&totSmBufAllocCount));
60348 #endif /* CONFIG_CIFS_STATS2 */
60349
60350 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
60351@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
60352 if (tcon->need_reconnect)
60353 seq_puts(m, "\tDISCONNECTED ");
60354 seq_printf(m, "\nSMBs: %d",
60355- atomic_read(&tcon->num_smbs_sent));
60356+ atomic_read_unchecked(&tcon->num_smbs_sent));
60357 if (server->ops->print_stats)
60358 server->ops->print_stats(m, tcon);
60359 }
60360diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
60361index 889b984..fcb8431 100644
60362--- a/fs/cifs/cifsfs.c
60363+++ b/fs/cifs/cifsfs.c
60364@@ -1092,7 +1092,7 @@ cifs_init_request_bufs(void)
60365 */
60366 cifs_req_cachep = kmem_cache_create("cifs_request",
60367 CIFSMaxBufSize + max_hdr_size, 0,
60368- SLAB_HWCACHE_ALIGN, NULL);
60369+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
60370 if (cifs_req_cachep == NULL)
60371 return -ENOMEM;
60372
60373@@ -1119,7 +1119,7 @@ cifs_init_request_bufs(void)
60374 efficient to alloc 1 per page off the slab compared to 17K (5page)
60375 alloc of large cifs buffers even when page debugging is on */
60376 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
60377- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
60378+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
60379 NULL);
60380 if (cifs_sm_req_cachep == NULL) {
60381 mempool_destroy(cifs_req_poolp);
60382@@ -1204,8 +1204,8 @@ init_cifs(void)
60383 atomic_set(&bufAllocCount, 0);
60384 atomic_set(&smBufAllocCount, 0);
60385 #ifdef CONFIG_CIFS_STATS2
60386- atomic_set(&totBufAllocCount, 0);
60387- atomic_set(&totSmBufAllocCount, 0);
60388+ atomic_set_unchecked(&totBufAllocCount, 0);
60389+ atomic_set_unchecked(&totSmBufAllocCount, 0);
60390 #endif /* CONFIG_CIFS_STATS2 */
60391
60392 atomic_set(&midCount, 0);
60393diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
60394index 25b8392..01e46dc 100644
60395--- a/fs/cifs/cifsglob.h
60396+++ b/fs/cifs/cifsglob.h
60397@@ -821,35 +821,35 @@ struct cifs_tcon {
60398 __u16 Flags; /* optional support bits */
60399 enum statusEnum tidStatus;
60400 #ifdef CONFIG_CIFS_STATS
60401- atomic_t num_smbs_sent;
60402+ atomic_unchecked_t num_smbs_sent;
60403 union {
60404 struct {
60405- atomic_t num_writes;
60406- atomic_t num_reads;
60407- atomic_t num_flushes;
60408- atomic_t num_oplock_brks;
60409- atomic_t num_opens;
60410- atomic_t num_closes;
60411- atomic_t num_deletes;
60412- atomic_t num_mkdirs;
60413- atomic_t num_posixopens;
60414- atomic_t num_posixmkdirs;
60415- atomic_t num_rmdirs;
60416- atomic_t num_renames;
60417- atomic_t num_t2renames;
60418- atomic_t num_ffirst;
60419- atomic_t num_fnext;
60420- atomic_t num_fclose;
60421- atomic_t num_hardlinks;
60422- atomic_t num_symlinks;
60423- atomic_t num_locks;
60424- atomic_t num_acl_get;
60425- atomic_t num_acl_set;
60426+ atomic_unchecked_t num_writes;
60427+ atomic_unchecked_t num_reads;
60428+ atomic_unchecked_t num_flushes;
60429+ atomic_unchecked_t num_oplock_brks;
60430+ atomic_unchecked_t num_opens;
60431+ atomic_unchecked_t num_closes;
60432+ atomic_unchecked_t num_deletes;
60433+ atomic_unchecked_t num_mkdirs;
60434+ atomic_unchecked_t num_posixopens;
60435+ atomic_unchecked_t num_posixmkdirs;
60436+ atomic_unchecked_t num_rmdirs;
60437+ atomic_unchecked_t num_renames;
60438+ atomic_unchecked_t num_t2renames;
60439+ atomic_unchecked_t num_ffirst;
60440+ atomic_unchecked_t num_fnext;
60441+ atomic_unchecked_t num_fclose;
60442+ atomic_unchecked_t num_hardlinks;
60443+ atomic_unchecked_t num_symlinks;
60444+ atomic_unchecked_t num_locks;
60445+ atomic_unchecked_t num_acl_get;
60446+ atomic_unchecked_t num_acl_set;
60447 } cifs_stats;
60448 #ifdef CONFIG_CIFS_SMB2
60449 struct {
60450- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
60451- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
60452+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
60453+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
60454 } smb2_stats;
60455 #endif /* CONFIG_CIFS_SMB2 */
60456 } stats;
60457@@ -1190,7 +1190,7 @@ convert_delimiter(char *path, char delim)
60458 }
60459
60460 #ifdef CONFIG_CIFS_STATS
60461-#define cifs_stats_inc atomic_inc
60462+#define cifs_stats_inc atomic_inc_unchecked
60463
60464 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
60465 unsigned int bytes)
60466@@ -1557,8 +1557,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
60467 /* Various Debug counters */
60468 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
60469 #ifdef CONFIG_CIFS_STATS2
60470-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
60471-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
60472+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
60473+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
60474 #endif
60475 GLOBAL_EXTERN atomic_t smBufAllocCount;
60476 GLOBAL_EXTERN atomic_t midCount;
60477diff --git a/fs/cifs/file.c b/fs/cifs/file.c
60478index 5f29354..359bc0d 100644
60479--- a/fs/cifs/file.c
60480+++ b/fs/cifs/file.c
60481@@ -2056,10 +2056,14 @@ static int cifs_writepages(struct address_space *mapping,
60482 index = mapping->writeback_index; /* Start from prev offset */
60483 end = -1;
60484 } else {
60485- index = wbc->range_start >> PAGE_CACHE_SHIFT;
60486- end = wbc->range_end >> PAGE_CACHE_SHIFT;
60487- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
60488+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
60489 range_whole = true;
60490+ index = 0;
60491+ end = ULONG_MAX;
60492+ } else {
60493+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
60494+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
60495+ }
60496 scanned = true;
60497 }
60498 server = cifs_sb_master_tcon(cifs_sb)->ses->server;
60499diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
60500index b7415d5..3984ec0 100644
60501--- a/fs/cifs/misc.c
60502+++ b/fs/cifs/misc.c
60503@@ -170,7 +170,7 @@ cifs_buf_get(void)
60504 memset(ret_buf, 0, buf_size + 3);
60505 atomic_inc(&bufAllocCount);
60506 #ifdef CONFIG_CIFS_STATS2
60507- atomic_inc(&totBufAllocCount);
60508+ atomic_inc_unchecked(&totBufAllocCount);
60509 #endif /* CONFIG_CIFS_STATS2 */
60510 }
60511
60512@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
60513 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
60514 atomic_inc(&smBufAllocCount);
60515 #ifdef CONFIG_CIFS_STATS2
60516- atomic_inc(&totSmBufAllocCount);
60517+ atomic_inc_unchecked(&totSmBufAllocCount);
60518 #endif /* CONFIG_CIFS_STATS2 */
60519
60520 }
60521diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
60522index 52131d8..fd79e97 100644
60523--- a/fs/cifs/smb1ops.c
60524+++ b/fs/cifs/smb1ops.c
60525@@ -626,27 +626,27 @@ static void
60526 cifs_clear_stats(struct cifs_tcon *tcon)
60527 {
60528 #ifdef CONFIG_CIFS_STATS
60529- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
60530- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
60531- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
60532- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
60533- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
60534- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
60535- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
60536- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
60537- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
60538- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
60539- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
60540- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
60541- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
60542- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
60543- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
60544- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
60545- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
60546- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
60547- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
60548- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
60549- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
60550+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
60551+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
60552+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
60553+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
60554+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
60555+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
60556+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
60557+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
60558+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
60559+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
60560+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
60561+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
60562+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
60563+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
60564+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
60565+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
60566+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
60567+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
60568+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
60569+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
60570+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
60571 #endif
60572 }
60573
60574@@ -655,36 +655,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
60575 {
60576 #ifdef CONFIG_CIFS_STATS
60577 seq_printf(m, " Oplocks breaks: %d",
60578- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
60579+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
60580 seq_printf(m, "\nReads: %d Bytes: %llu",
60581- atomic_read(&tcon->stats.cifs_stats.num_reads),
60582+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
60583 (long long)(tcon->bytes_read));
60584 seq_printf(m, "\nWrites: %d Bytes: %llu",
60585- atomic_read(&tcon->stats.cifs_stats.num_writes),
60586+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
60587 (long long)(tcon->bytes_written));
60588 seq_printf(m, "\nFlushes: %d",
60589- atomic_read(&tcon->stats.cifs_stats.num_flushes));
60590+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
60591 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
60592- atomic_read(&tcon->stats.cifs_stats.num_locks),
60593- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
60594- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
60595+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
60596+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
60597+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
60598 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
60599- atomic_read(&tcon->stats.cifs_stats.num_opens),
60600- atomic_read(&tcon->stats.cifs_stats.num_closes),
60601- atomic_read(&tcon->stats.cifs_stats.num_deletes));
60602+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
60603+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
60604+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
60605 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
60606- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
60607- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
60608+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
60609+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
60610 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
60611- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
60612- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
60613+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
60614+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
60615 seq_printf(m, "\nRenames: %d T2 Renames %d",
60616- atomic_read(&tcon->stats.cifs_stats.num_renames),
60617- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
60618+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
60619+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
60620 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
60621- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
60622- atomic_read(&tcon->stats.cifs_stats.num_fnext),
60623- atomic_read(&tcon->stats.cifs_stats.num_fclose));
60624+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
60625+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
60626+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
60627 #endif
60628 }
60629
60630diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
60631index f522193..586121b 100644
60632--- a/fs/cifs/smb2ops.c
60633+++ b/fs/cifs/smb2ops.c
60634@@ -414,8 +414,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
60635 #ifdef CONFIG_CIFS_STATS
60636 int i;
60637 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
60638- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
60639- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
60640+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
60641+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
60642 }
60643 #endif
60644 }
60645@@ -455,65 +455,65 @@ static void
60646 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
60647 {
60648 #ifdef CONFIG_CIFS_STATS
60649- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
60650- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
60651+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
60652+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
60653 seq_printf(m, "\nNegotiates: %d sent %d failed",
60654- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
60655- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
60656+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
60657+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
60658 seq_printf(m, "\nSessionSetups: %d sent %d failed",
60659- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
60660- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
60661+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
60662+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
60663 seq_printf(m, "\nLogoffs: %d sent %d failed",
60664- atomic_read(&sent[SMB2_LOGOFF_HE]),
60665- atomic_read(&failed[SMB2_LOGOFF_HE]));
60666+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
60667+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
60668 seq_printf(m, "\nTreeConnects: %d sent %d failed",
60669- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
60670- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
60671+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
60672+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
60673 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
60674- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
60675- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
60676+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
60677+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
60678 seq_printf(m, "\nCreates: %d sent %d failed",
60679- atomic_read(&sent[SMB2_CREATE_HE]),
60680- atomic_read(&failed[SMB2_CREATE_HE]));
60681+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
60682+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
60683 seq_printf(m, "\nCloses: %d sent %d failed",
60684- atomic_read(&sent[SMB2_CLOSE_HE]),
60685- atomic_read(&failed[SMB2_CLOSE_HE]));
60686+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
60687+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
60688 seq_printf(m, "\nFlushes: %d sent %d failed",
60689- atomic_read(&sent[SMB2_FLUSH_HE]),
60690- atomic_read(&failed[SMB2_FLUSH_HE]));
60691+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
60692+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
60693 seq_printf(m, "\nReads: %d sent %d failed",
60694- atomic_read(&sent[SMB2_READ_HE]),
60695- atomic_read(&failed[SMB2_READ_HE]));
60696+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
60697+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
60698 seq_printf(m, "\nWrites: %d sent %d failed",
60699- atomic_read(&sent[SMB2_WRITE_HE]),
60700- atomic_read(&failed[SMB2_WRITE_HE]));
60701+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
60702+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
60703 seq_printf(m, "\nLocks: %d sent %d failed",
60704- atomic_read(&sent[SMB2_LOCK_HE]),
60705- atomic_read(&failed[SMB2_LOCK_HE]));
60706+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
60707+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
60708 seq_printf(m, "\nIOCTLs: %d sent %d failed",
60709- atomic_read(&sent[SMB2_IOCTL_HE]),
60710- atomic_read(&failed[SMB2_IOCTL_HE]));
60711+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
60712+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
60713 seq_printf(m, "\nCancels: %d sent %d failed",
60714- atomic_read(&sent[SMB2_CANCEL_HE]),
60715- atomic_read(&failed[SMB2_CANCEL_HE]));
60716+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
60717+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
60718 seq_printf(m, "\nEchos: %d sent %d failed",
60719- atomic_read(&sent[SMB2_ECHO_HE]),
60720- atomic_read(&failed[SMB2_ECHO_HE]));
60721+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
60722+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
60723 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
60724- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
60725- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
60726+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
60727+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
60728 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
60729- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
60730- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
60731+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
60732+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
60733 seq_printf(m, "\nQueryInfos: %d sent %d failed",
60734- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
60735- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
60736+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
60737+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
60738 seq_printf(m, "\nSetInfos: %d sent %d failed",
60739- atomic_read(&sent[SMB2_SET_INFO_HE]),
60740- atomic_read(&failed[SMB2_SET_INFO_HE]));
60741+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
60742+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
60743 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
60744- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
60745- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
60746+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
60747+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
60748 #endif
60749 }
60750
60751diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
60752index 74b3a66..0c709f3 100644
60753--- a/fs/cifs/smb2pdu.c
60754+++ b/fs/cifs/smb2pdu.c
60755@@ -2143,8 +2143,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
60756 default:
60757 cifs_dbg(VFS, "info level %u isn't supported\n",
60758 srch_inf->info_level);
60759- rc = -EINVAL;
60760- goto qdir_exit;
60761+ return -EINVAL;
60762 }
60763
60764 req->FileIndex = cpu_to_le32(index);
60765diff --git a/fs/coda/cache.c b/fs/coda/cache.c
60766index 278f8fd..e69c52d 100644
60767--- a/fs/coda/cache.c
60768+++ b/fs/coda/cache.c
60769@@ -24,7 +24,7 @@
60770 #include "coda_linux.h"
60771 #include "coda_cache.h"
60772
60773-static atomic_t permission_epoch = ATOMIC_INIT(0);
60774+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
60775
60776 /* replace or extend an acl cache hit */
60777 void coda_cache_enter(struct inode *inode, int mask)
60778@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
60779 struct coda_inode_info *cii = ITOC(inode);
60780
60781 spin_lock(&cii->c_lock);
60782- cii->c_cached_epoch = atomic_read(&permission_epoch);
60783+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
60784 if (!uid_eq(cii->c_uid, current_fsuid())) {
60785 cii->c_uid = current_fsuid();
60786 cii->c_cached_perm = mask;
60787@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
60788 {
60789 struct coda_inode_info *cii = ITOC(inode);
60790 spin_lock(&cii->c_lock);
60791- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
60792+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
60793 spin_unlock(&cii->c_lock);
60794 }
60795
60796 /* remove all acl caches */
60797 void coda_cache_clear_all(struct super_block *sb)
60798 {
60799- atomic_inc(&permission_epoch);
60800+ atomic_inc_unchecked(&permission_epoch);
60801 }
60802
60803
60804@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
60805 spin_lock(&cii->c_lock);
60806 hit = (mask & cii->c_cached_perm) == mask &&
60807 uid_eq(cii->c_uid, current_fsuid()) &&
60808- cii->c_cached_epoch == atomic_read(&permission_epoch);
60809+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
60810 spin_unlock(&cii->c_lock);
60811
60812 return hit;
60813diff --git a/fs/compat.c b/fs/compat.c
60814index 66d3d3c..9c10175 100644
60815--- a/fs/compat.c
60816+++ b/fs/compat.c
60817@@ -54,7 +54,7 @@
60818 #include <asm/ioctls.h>
60819 #include "internal.h"
60820
60821-int compat_log = 1;
60822+int compat_log = 0;
60823
60824 int compat_printk(const char *fmt, ...)
60825 {
60826@@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
60827
60828 set_fs(KERNEL_DS);
60829 /* The __user pointer cast is valid because of the set_fs() */
60830- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
60831+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
60832 set_fs(oldfs);
60833 /* truncating is ok because it's a user address */
60834 if (!ret)
60835@@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
60836 goto out;
60837
60838 ret = -EINVAL;
60839- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
60840+ if (nr_segs > UIO_MAXIOV)
60841 goto out;
60842 if (nr_segs > fast_segs) {
60843 ret = -ENOMEM;
60844@@ -850,6 +850,7 @@ struct compat_old_linux_dirent {
60845 struct compat_readdir_callback {
60846 struct dir_context ctx;
60847 struct compat_old_linux_dirent __user *dirent;
60848+ struct file * file;
60849 int result;
60850 };
60851
60852@@ -867,6 +868,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
60853 buf->result = -EOVERFLOW;
60854 return -EOVERFLOW;
60855 }
60856+
60857+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60858+ return 0;
60859+
60860 buf->result++;
60861 dirent = buf->dirent;
60862 if (!access_ok(VERIFY_WRITE, dirent,
60863@@ -898,6 +903,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60864 if (!f.file)
60865 return -EBADF;
60866
60867+ buf.file = f.file;
60868 error = iterate_dir(f.file, &buf.ctx);
60869 if (buf.result)
60870 error = buf.result;
60871@@ -917,6 +923,7 @@ struct compat_getdents_callback {
60872 struct dir_context ctx;
60873 struct compat_linux_dirent __user *current_dir;
60874 struct compat_linux_dirent __user *previous;
60875+ struct file * file;
60876 int count;
60877 int error;
60878 };
60879@@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
60880 buf->error = -EOVERFLOW;
60881 return -EOVERFLOW;
60882 }
60883+
60884+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60885+ return 0;
60886+
60887 dirent = buf->previous;
60888 if (dirent) {
60889 if (__put_user(offset, &dirent->d_off))
60890@@ -983,6 +994,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
60891 if (!f.file)
60892 return -EBADF;
60893
60894+ buf.file = f.file;
60895 error = iterate_dir(f.file, &buf.ctx);
60896 if (error >= 0)
60897 error = buf.error;
60898@@ -1003,6 +1015,7 @@ struct compat_getdents_callback64 {
60899 struct dir_context ctx;
60900 struct linux_dirent64 __user *current_dir;
60901 struct linux_dirent64 __user *previous;
60902+ struct file * file;
60903 int count;
60904 int error;
60905 };
60906@@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
60907 buf->error = -EINVAL; /* only used if we fail.. */
60908 if (reclen > buf->count)
60909 return -EINVAL;
60910+
60911+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60912+ return 0;
60913+
60914 dirent = buf->previous;
60915
60916 if (dirent) {
60917@@ -1068,6 +1085,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60918 if (!f.file)
60919 return -EBADF;
60920
60921+ buf.file = f.file;
60922 error = iterate_dir(f.file, &buf.ctx);
60923 if (error >= 0)
60924 error = buf.error;
60925diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
60926index 4d24d17..4f8c09e 100644
60927--- a/fs/compat_binfmt_elf.c
60928+++ b/fs/compat_binfmt_elf.c
60929@@ -30,11 +30,13 @@
60930 #undef elf_phdr
60931 #undef elf_shdr
60932 #undef elf_note
60933+#undef elf_dyn
60934 #undef elf_addr_t
60935 #define elfhdr elf32_hdr
60936 #define elf_phdr elf32_phdr
60937 #define elf_shdr elf32_shdr
60938 #define elf_note elf32_note
60939+#define elf_dyn Elf32_Dyn
60940 #define elf_addr_t Elf32_Addr
60941
60942 /*
60943diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
60944index afec645..9c65620 100644
60945--- a/fs/compat_ioctl.c
60946+++ b/fs/compat_ioctl.c
60947@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
60948 return -EFAULT;
60949 if (__get_user(udata, &ss32->iomem_base))
60950 return -EFAULT;
60951- ss.iomem_base = compat_ptr(udata);
60952+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
60953 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
60954 __get_user(ss.port_high, &ss32->port_high))
60955 return -EFAULT;
60956@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
60957 for (i = 0; i < nmsgs; i++) {
60958 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
60959 return -EFAULT;
60960- if (get_user(datap, &umsgs[i].buf) ||
60961- put_user(compat_ptr(datap), &tmsgs[i].buf))
60962+ if (get_user(datap, (compat_caddr_t __user *)&umsgs[i].buf) ||
60963+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
60964 return -EFAULT;
60965 }
60966 return sys_ioctl(fd, cmd, (unsigned long)tdata);
60967@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
60968 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
60969 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
60970 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
60971- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
60972+ copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
60973 return -EFAULT;
60974
60975 return ioctl_preallocate(file, p);
60976@@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
60977 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
60978 {
60979 unsigned int a, b;
60980- a = *(unsigned int *)p;
60981- b = *(unsigned int *)q;
60982+ a = *(const unsigned int *)p;
60983+ b = *(const unsigned int *)q;
60984 if (a > b)
60985 return 1;
60986 if (a < b)
60987diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
60988index 668dcab..daebcd6 100644
60989--- a/fs/configfs/dir.c
60990+++ b/fs/configfs/dir.c
60991@@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60992 }
60993 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
60994 struct configfs_dirent *next;
60995- const char *name;
60996+ const unsigned char * name;
60997+ char d_name[sizeof(next->s_dentry->d_iname)];
60998 int len;
60999 struct inode *inode = NULL;
61000
61001@@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
61002 continue;
61003
61004 name = configfs_get_name(next);
61005- len = strlen(name);
61006+ if (next->s_dentry && name == next->s_dentry->d_iname) {
61007+ len = next->s_dentry->d_name.len;
61008+ memcpy(d_name, name, len);
61009+ name = d_name;
61010+ } else
61011+ len = strlen(name);
61012
61013 /*
61014 * We'll have a dentry and an inode for
61015diff --git a/fs/coredump.c b/fs/coredump.c
61016index a93f7e6..d58bcbe 100644
61017--- a/fs/coredump.c
61018+++ b/fs/coredump.c
61019@@ -442,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
61020 struct pipe_inode_info *pipe = file->private_data;
61021
61022 pipe_lock(pipe);
61023- pipe->readers++;
61024- pipe->writers--;
61025+ atomic_inc(&pipe->readers);
61026+ atomic_dec(&pipe->writers);
61027 wake_up_interruptible_sync(&pipe->wait);
61028 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
61029 pipe_unlock(pipe);
61030@@ -452,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
61031 * We actually want wait_event_freezable() but then we need
61032 * to clear TIF_SIGPENDING and improve dump_interrupted().
61033 */
61034- wait_event_interruptible(pipe->wait, pipe->readers == 1);
61035+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
61036
61037 pipe_lock(pipe);
61038- pipe->readers--;
61039- pipe->writers++;
61040+ atomic_dec(&pipe->readers);
61041+ atomic_inc(&pipe->writers);
61042 pipe_unlock(pipe);
61043 }
61044
61045@@ -503,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
61046 struct files_struct *displaced;
61047 bool need_nonrelative = false;
61048 bool core_dumped = false;
61049- static atomic_t core_dump_count = ATOMIC_INIT(0);
61050+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
61051+ long signr = siginfo->si_signo;
61052+ int dumpable;
61053 struct coredump_params cprm = {
61054 .siginfo = siginfo,
61055 .regs = signal_pt_regs(),
61056@@ -516,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
61057 .mm_flags = mm->flags,
61058 };
61059
61060- audit_core_dumps(siginfo->si_signo);
61061+ audit_core_dumps(signr);
61062+
61063+ dumpable = __get_dumpable(cprm.mm_flags);
61064+
61065+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
61066+ gr_handle_brute_attach(dumpable);
61067
61068 binfmt = mm->binfmt;
61069 if (!binfmt || !binfmt->core_dump)
61070 goto fail;
61071- if (!__get_dumpable(cprm.mm_flags))
61072+ if (!dumpable)
61073 goto fail;
61074
61075 cred = prepare_creds();
61076@@ -540,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
61077 need_nonrelative = true;
61078 }
61079
61080- retval = coredump_wait(siginfo->si_signo, &core_state);
61081+ retval = coredump_wait(signr, &core_state);
61082 if (retval < 0)
61083 goto fail_creds;
61084
61085@@ -583,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
61086 }
61087 cprm.limit = RLIM_INFINITY;
61088
61089- dump_count = atomic_inc_return(&core_dump_count);
61090+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
61091 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
61092 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
61093 task_tgid_vnr(current), current->comm);
61094@@ -615,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
61095 } else {
61096 struct inode *inode;
61097
61098+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
61099+
61100 if (cprm.limit < binfmt->min_coredump)
61101 goto fail_unlock;
61102
61103@@ -673,7 +682,7 @@ close_fail:
61104 filp_close(cprm.file, NULL);
61105 fail_dropcount:
61106 if (ispipe)
61107- atomic_dec(&core_dump_count);
61108+ atomic_dec_unchecked(&core_dump_count);
61109 fail_unlock:
61110 kfree(cn.corename);
61111 coredump_finish(mm, core_dumped);
61112@@ -694,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
61113 struct file *file = cprm->file;
61114 loff_t pos = file->f_pos;
61115 ssize_t n;
61116+
61117+ gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
61118 if (cprm->written + nr > cprm->limit)
61119 return 0;
61120 while (nr) {
61121diff --git a/fs/dcache.c b/fs/dcache.c
61122index 34b40be8..2003532 100644
61123--- a/fs/dcache.c
61124+++ b/fs/dcache.c
61125@@ -478,7 +478,7 @@ static void __dentry_kill(struct dentry *dentry)
61126 * dentry_iput drops the locks, at which point nobody (except
61127 * transient RCU lookups) can reach this dentry.
61128 */
61129- BUG_ON((int)dentry->d_lockref.count > 0);
61130+ BUG_ON((int)__lockref_read(&dentry->d_lockref) > 0);
61131 this_cpu_dec(nr_dentry);
61132 if (dentry->d_op && dentry->d_op->d_release)
61133 dentry->d_op->d_release(dentry);
61134@@ -531,7 +531,7 @@ static inline struct dentry *lock_parent(struct dentry *dentry)
61135 struct dentry *parent = dentry->d_parent;
61136 if (IS_ROOT(dentry))
61137 return NULL;
61138- if (unlikely((int)dentry->d_lockref.count < 0))
61139+ if (unlikely((int)__lockref_read(&dentry->d_lockref) < 0))
61140 return NULL;
61141 if (likely(spin_trylock(&parent->d_lock)))
61142 return parent;
61143@@ -608,7 +608,7 @@ repeat:
61144 dentry->d_flags |= DCACHE_REFERENCED;
61145 dentry_lru_add(dentry);
61146
61147- dentry->d_lockref.count--;
61148+ __lockref_dec(&dentry->d_lockref);
61149 spin_unlock(&dentry->d_lock);
61150 return;
61151
61152@@ -663,7 +663,7 @@ int d_invalidate(struct dentry * dentry)
61153 * We also need to leave mountpoints alone,
61154 * directory or not.
61155 */
61156- if (dentry->d_lockref.count > 1 && dentry->d_inode) {
61157+ if (__lockref_read(&dentry->d_lockref) > 1 && dentry->d_inode) {
61158 if (S_ISDIR(dentry->d_inode->i_mode) || d_mountpoint(dentry)) {
61159 spin_unlock(&dentry->d_lock);
61160 return -EBUSY;
61161@@ -679,7 +679,7 @@ EXPORT_SYMBOL(d_invalidate);
61162 /* This must be called with d_lock held */
61163 static inline void __dget_dlock(struct dentry *dentry)
61164 {
61165- dentry->d_lockref.count++;
61166+ __lockref_inc(&dentry->d_lockref);
61167 }
61168
61169 static inline void __dget(struct dentry *dentry)
61170@@ -720,8 +720,8 @@ repeat:
61171 goto repeat;
61172 }
61173 rcu_read_unlock();
61174- BUG_ON(!ret->d_lockref.count);
61175- ret->d_lockref.count++;
61176+ BUG_ON(!__lockref_read(&ret->d_lockref));
61177+ __lockref_inc(&ret->d_lockref);
61178 spin_unlock(&ret->d_lock);
61179 return ret;
61180 }
61181@@ -798,7 +798,7 @@ restart:
61182 spin_lock(&inode->i_lock);
61183 hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) {
61184 spin_lock(&dentry->d_lock);
61185- if (!dentry->d_lockref.count) {
61186+ if (!__lockref_read(&dentry->d_lockref)) {
61187 /*
61188 * inform the fs via d_prune that this dentry
61189 * is about to be unhashed and destroyed.
61190@@ -841,7 +841,7 @@ static void shrink_dentry_list(struct list_head *list)
61191 * We found an inuse dentry which was not removed from
61192 * the LRU because of laziness during lookup. Do not free it.
61193 */
61194- if ((int)dentry->d_lockref.count > 0) {
61195+ if ((int)__lockref_read(&dentry->d_lockref) > 0) {
61196 spin_unlock(&dentry->d_lock);
61197 if (parent)
61198 spin_unlock(&parent->d_lock);
61199@@ -879,8 +879,8 @@ static void shrink_dentry_list(struct list_head *list)
61200 dentry = parent;
61201 while (dentry && !lockref_put_or_lock(&dentry->d_lockref)) {
61202 parent = lock_parent(dentry);
61203- if (dentry->d_lockref.count != 1) {
61204- dentry->d_lockref.count--;
61205+ if (__lockref_read(&dentry->d_lockref) != 1) {
61206+ __lockref_inc(&dentry->d_lockref);
61207 spin_unlock(&dentry->d_lock);
61208 if (parent)
61209 spin_unlock(&parent->d_lock);
61210@@ -920,7 +920,7 @@ dentry_lru_isolate(struct list_head *item, spinlock_t *lru_lock, void *arg)
61211 * counts, just remove them from the LRU. Otherwise give them
61212 * another pass through the LRU.
61213 */
61214- if (dentry->d_lockref.count) {
61215+ if (__lockref_read(&dentry->d_lockref) > 0) {
61216 d_lru_isolate(dentry);
61217 spin_unlock(&dentry->d_lock);
61218 return LRU_REMOVED;
61219@@ -1149,6 +1149,7 @@ out_unlock:
61220 return;
61221
61222 rename_retry:
61223+ done_seqretry(&rename_lock, seq);
61224 if (!retry)
61225 return;
61226 seq = 1;
61227@@ -1255,7 +1256,7 @@ static enum d_walk_ret select_collect(void *_data, struct dentry *dentry)
61228 } else {
61229 if (dentry->d_flags & DCACHE_LRU_LIST)
61230 d_lru_del(dentry);
61231- if (!dentry->d_lockref.count) {
61232+ if (!__lockref_read(&dentry->d_lockref)) {
61233 d_shrink_add(dentry, &data->dispose);
61234 data->found++;
61235 }
61236@@ -1303,7 +1304,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
61237 return D_WALK_CONTINUE;
61238
61239 /* root with refcount 1 is fine */
61240- if (dentry == _data && dentry->d_lockref.count == 1)
61241+ if (dentry == _data && __lockref_read(&dentry->d_lockref) == 1)
61242 return D_WALK_CONTINUE;
61243
61244 printk(KERN_ERR "BUG: Dentry %p{i=%lx,n=%pd} "
61245@@ -1312,7 +1313,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
61246 dentry->d_inode ?
61247 dentry->d_inode->i_ino : 0UL,
61248 dentry,
61249- dentry->d_lockref.count,
61250+ __lockref_read(&dentry->d_lockref),
61251 dentry->d_sb->s_type->name,
61252 dentry->d_sb->s_id);
61253 WARN_ON(1);
61254@@ -1438,7 +1439,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
61255 */
61256 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
61257 if (name->len > DNAME_INLINE_LEN-1) {
61258- dname = kmalloc(name->len + 1, GFP_KERNEL);
61259+ dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
61260 if (!dname) {
61261 kmem_cache_free(dentry_cache, dentry);
61262 return NULL;
61263@@ -1456,7 +1457,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
61264 smp_wmb();
61265 dentry->d_name.name = dname;
61266
61267- dentry->d_lockref.count = 1;
61268+ __lockref_set(&dentry->d_lockref, 1);
61269 dentry->d_flags = 0;
61270 spin_lock_init(&dentry->d_lock);
61271 seqcount_init(&dentry->d_seq);
61272@@ -2196,7 +2197,7 @@ struct dentry *__d_lookup(const struct dentry *parent, const struct qstr *name)
61273 goto next;
61274 }
61275
61276- dentry->d_lockref.count++;
61277+ __lockref_inc(&dentry->d_lockref);
61278 found = dentry;
61279 spin_unlock(&dentry->d_lock);
61280 break;
61281@@ -2295,7 +2296,7 @@ again:
61282 spin_lock(&dentry->d_lock);
61283 inode = dentry->d_inode;
61284 isdir = S_ISDIR(inode->i_mode);
61285- if (dentry->d_lockref.count == 1) {
61286+ if (__lockref_read(&dentry->d_lockref) == 1) {
61287 if (!spin_trylock(&inode->i_lock)) {
61288 spin_unlock(&dentry->d_lock);
61289 cpu_relax();
61290@@ -3307,7 +3308,7 @@ static enum d_walk_ret d_genocide_kill(void *data, struct dentry *dentry)
61291
61292 if (!(dentry->d_flags & DCACHE_GENOCIDE)) {
61293 dentry->d_flags |= DCACHE_GENOCIDE;
61294- dentry->d_lockref.count--;
61295+ __lockref_dec(&dentry->d_lockref);
61296 }
61297 }
61298 return D_WALK_CONTINUE;
61299@@ -3423,7 +3424,8 @@ void __init vfs_caches_init(unsigned long mempages)
61300 mempages -= reserve;
61301
61302 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
61303- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
61304+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
61305+ SLAB_NO_SANITIZE, NULL);
61306
61307 dcache_init();
61308 inode_init();
61309diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
61310index 1e3b99d..6512101 100644
61311--- a/fs/debugfs/inode.c
61312+++ b/fs/debugfs/inode.c
61313@@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
61314 */
61315 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
61316 {
61317+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
61318+ return __create_file(name, S_IFDIR | S_IRWXU,
61319+#else
61320 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
61321+#endif
61322 parent, NULL, NULL);
61323 }
61324 EXPORT_SYMBOL_GPL(debugfs_create_dir);
61325diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
61326index 57ee4c5..ecb13b0 100644
61327--- a/fs/ecryptfs/inode.c
61328+++ b/fs/ecryptfs/inode.c
61329@@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
61330 old_fs = get_fs();
61331 set_fs(get_ds());
61332 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
61333- (char __user *)lower_buf,
61334+ (char __force_user *)lower_buf,
61335 PATH_MAX);
61336 set_fs(old_fs);
61337 if (rc < 0)
61338diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
61339index e4141f2..d8263e8 100644
61340--- a/fs/ecryptfs/miscdev.c
61341+++ b/fs/ecryptfs/miscdev.c
61342@@ -304,7 +304,7 @@ check_list:
61343 goto out_unlock_msg_ctx;
61344 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
61345 if (msg_ctx->msg) {
61346- if (copy_to_user(&buf[i], packet_length, packet_length_size))
61347+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
61348 goto out_unlock_msg_ctx;
61349 i += packet_length_size;
61350 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
61351diff --git a/fs/exec.c b/fs/exec.c
61352index a2b42a9..1e924b3 100644
61353--- a/fs/exec.c
61354+++ b/fs/exec.c
61355@@ -56,8 +56,20 @@
61356 #include <linux/pipe_fs_i.h>
61357 #include <linux/oom.h>
61358 #include <linux/compat.h>
61359+#include <linux/random.h>
61360+#include <linux/seq_file.h>
61361+#include <linux/coredump.h>
61362+#include <linux/mman.h>
61363+
61364+#ifdef CONFIG_PAX_REFCOUNT
61365+#include <linux/kallsyms.h>
61366+#include <linux/kdebug.h>
61367+#endif
61368+
61369+#include <trace/events/fs.h>
61370
61371 #include <asm/uaccess.h>
61372+#include <asm/sections.h>
61373 #include <asm/mmu_context.h>
61374 #include <asm/tlb.h>
61375
61376@@ -66,19 +78,34 @@
61377
61378 #include <trace/events/sched.h>
61379
61380+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
61381+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
61382+{
61383+ 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");
61384+}
61385+#endif
61386+
61387+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
61388+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
61389+EXPORT_SYMBOL(pax_set_initial_flags_func);
61390+#endif
61391+
61392 int suid_dumpable = 0;
61393
61394 static LIST_HEAD(formats);
61395 static DEFINE_RWLOCK(binfmt_lock);
61396
61397+extern int gr_process_kernel_exec_ban(void);
61398+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
61399+
61400 void __register_binfmt(struct linux_binfmt * fmt, int insert)
61401 {
61402 BUG_ON(!fmt);
61403 if (WARN_ON(!fmt->load_binary))
61404 return;
61405 write_lock(&binfmt_lock);
61406- insert ? list_add(&fmt->lh, &formats) :
61407- list_add_tail(&fmt->lh, &formats);
61408+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
61409+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
61410 write_unlock(&binfmt_lock);
61411 }
61412
61413@@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
61414 void unregister_binfmt(struct linux_binfmt * fmt)
61415 {
61416 write_lock(&binfmt_lock);
61417- list_del(&fmt->lh);
61418+ pax_list_del((struct list_head *)&fmt->lh);
61419 write_unlock(&binfmt_lock);
61420 }
61421
61422@@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61423 int write)
61424 {
61425 struct page *page;
61426- int ret;
61427
61428-#ifdef CONFIG_STACK_GROWSUP
61429- if (write) {
61430- ret = expand_downwards(bprm->vma, pos);
61431- if (ret < 0)
61432- return NULL;
61433- }
61434-#endif
61435- ret = get_user_pages(current, bprm->mm, pos,
61436- 1, write, 1, &page, NULL);
61437- if (ret <= 0)
61438+ if (0 > expand_downwards(bprm->vma, pos))
61439+ return NULL;
61440+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
61441 return NULL;
61442
61443 if (write) {
61444@@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61445 if (size <= ARG_MAX)
61446 return page;
61447
61448+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61449+ // only allow 512KB for argv+env on suid/sgid binaries
61450+ // to prevent easy ASLR exhaustion
61451+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
61452+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
61453+ (size > (512 * 1024))) {
61454+ put_page(page);
61455+ return NULL;
61456+ }
61457+#endif
61458+
61459 /*
61460 * Limit to 1/4-th the stack size for the argv+env strings.
61461 * This ensures that:
61462@@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61463 vma->vm_end = STACK_TOP_MAX;
61464 vma->vm_start = vma->vm_end - PAGE_SIZE;
61465 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
61466+
61467+#ifdef CONFIG_PAX_SEGMEXEC
61468+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
61469+#endif
61470+
61471 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
61472 INIT_LIST_HEAD(&vma->anon_vma_chain);
61473
61474@@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61475 mm->stack_vm = mm->total_vm = 1;
61476 up_write(&mm->mmap_sem);
61477 bprm->p = vma->vm_end - sizeof(void *);
61478+
61479+#ifdef CONFIG_PAX_RANDUSTACK
61480+ if (randomize_va_space)
61481+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
61482+#endif
61483+
61484 return 0;
61485 err:
61486 up_write(&mm->mmap_sem);
61487@@ -395,7 +436,7 @@ struct user_arg_ptr {
61488 } ptr;
61489 };
61490
61491-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61492+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61493 {
61494 const char __user *native;
61495
61496@@ -404,14 +445,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61497 compat_uptr_t compat;
61498
61499 if (get_user(compat, argv.ptr.compat + nr))
61500- return ERR_PTR(-EFAULT);
61501+ return (const char __force_user *)ERR_PTR(-EFAULT);
61502
61503 return compat_ptr(compat);
61504 }
61505 #endif
61506
61507 if (get_user(native, argv.ptr.native + nr))
61508- return ERR_PTR(-EFAULT);
61509+ return (const char __force_user *)ERR_PTR(-EFAULT);
61510
61511 return native;
61512 }
61513@@ -430,7 +471,7 @@ static int count(struct user_arg_ptr argv, int max)
61514 if (!p)
61515 break;
61516
61517- if (IS_ERR(p))
61518+ if (IS_ERR((const char __force_kernel *)p))
61519 return -EFAULT;
61520
61521 if (i >= max)
61522@@ -465,7 +506,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
61523
61524 ret = -EFAULT;
61525 str = get_user_arg_ptr(argv, argc);
61526- if (IS_ERR(str))
61527+ if (IS_ERR((const char __force_kernel *)str))
61528 goto out;
61529
61530 len = strnlen_user(str, MAX_ARG_STRLEN);
61531@@ -547,7 +588,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
61532 int r;
61533 mm_segment_t oldfs = get_fs();
61534 struct user_arg_ptr argv = {
61535- .ptr.native = (const char __user *const __user *)__argv,
61536+ .ptr.native = (const char __user * const __force_user *)__argv,
61537 };
61538
61539 set_fs(KERNEL_DS);
61540@@ -582,7 +623,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61541 unsigned long new_end = old_end - shift;
61542 struct mmu_gather tlb;
61543
61544- BUG_ON(new_start > new_end);
61545+ if (new_start >= new_end || new_start < mmap_min_addr)
61546+ return -ENOMEM;
61547
61548 /*
61549 * ensure there are no vmas between where we want to go
61550@@ -591,6 +633,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61551 if (vma != find_vma(mm, new_start))
61552 return -EFAULT;
61553
61554+#ifdef CONFIG_PAX_SEGMEXEC
61555+ BUG_ON(pax_find_mirror_vma(vma));
61556+#endif
61557+
61558 /*
61559 * cover the whole range: [new_start, old_end)
61560 */
61561@@ -671,10 +717,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61562 stack_top = arch_align_stack(stack_top);
61563 stack_top = PAGE_ALIGN(stack_top);
61564
61565- if (unlikely(stack_top < mmap_min_addr) ||
61566- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
61567- return -ENOMEM;
61568-
61569 stack_shift = vma->vm_end - stack_top;
61570
61571 bprm->p -= stack_shift;
61572@@ -686,8 +728,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
61573 bprm->exec -= stack_shift;
61574
61575 down_write(&mm->mmap_sem);
61576+
61577+ /* Move stack pages down in memory. */
61578+ if (stack_shift) {
61579+ ret = shift_arg_pages(vma, stack_shift);
61580+ if (ret)
61581+ goto out_unlock;
61582+ }
61583+
61584 vm_flags = VM_STACK_FLAGS;
61585
61586+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61587+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
61588+ vm_flags &= ~VM_EXEC;
61589+
61590+#ifdef CONFIG_PAX_MPROTECT
61591+ if (mm->pax_flags & MF_PAX_MPROTECT)
61592+ vm_flags &= ~VM_MAYEXEC;
61593+#endif
61594+
61595+ }
61596+#endif
61597+
61598 /*
61599 * Adjust stack execute permissions; explicitly enable for
61600 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
61601@@ -706,13 +768,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61602 goto out_unlock;
61603 BUG_ON(prev != vma);
61604
61605- /* Move stack pages down in memory. */
61606- if (stack_shift) {
61607- ret = shift_arg_pages(vma, stack_shift);
61608- if (ret)
61609- goto out_unlock;
61610- }
61611-
61612 /* mprotect_fixup is overkill to remove the temporary stack flags */
61613 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
61614
61615@@ -736,6 +791,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
61616 #endif
61617 current->mm->start_stack = bprm->p;
61618 ret = expand_stack(vma, stack_base);
61619+
61620+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
61621+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
61622+ unsigned long size;
61623+ vm_flags_t vm_flags;
61624+
61625+ size = STACK_TOP - vma->vm_end;
61626+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
61627+
61628+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
61629+
61630+#ifdef CONFIG_X86
61631+ if (!ret) {
61632+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
61633+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
61634+ }
61635+#endif
61636+
61637+ }
61638+#endif
61639+
61640 if (ret)
61641 ret = -EFAULT;
61642
61643@@ -771,6 +847,8 @@ static struct file *do_open_exec(struct filename *name)
61644
61645 fsnotify_open(file);
61646
61647+ trace_open_exec(name->name);
61648+
61649 err = deny_write_access(file);
61650 if (err)
61651 goto exit;
61652@@ -800,7 +878,7 @@ int kernel_read(struct file *file, loff_t offset,
61653 old_fs = get_fs();
61654 set_fs(get_ds());
61655 /* The cast to a user pointer is valid due to the set_fs() */
61656- result = vfs_read(file, (void __user *)addr, count, &pos);
61657+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
61658 set_fs(old_fs);
61659 return result;
61660 }
61661@@ -845,6 +923,7 @@ static int exec_mmap(struct mm_struct *mm)
61662 tsk->mm = mm;
61663 tsk->active_mm = mm;
61664 activate_mm(active_mm, mm);
61665+ populate_stack();
61666 tsk->mm->vmacache_seqnum = 0;
61667 vmacache_flush(tsk);
61668 task_unlock(tsk);
61669@@ -1243,7 +1322,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
61670 }
61671 rcu_read_unlock();
61672
61673- if (p->fs->users > n_fs)
61674+ if (atomic_read(&p->fs->users) > n_fs)
61675 bprm->unsafe |= LSM_UNSAFE_SHARE;
61676 else
61677 p->fs->in_exec = 1;
61678@@ -1419,6 +1498,31 @@ static int exec_binprm(struct linux_binprm *bprm)
61679 return ret;
61680 }
61681
61682+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61683+static DEFINE_PER_CPU(u64, exec_counter);
61684+static int __init init_exec_counters(void)
61685+{
61686+ unsigned int cpu;
61687+
61688+ for_each_possible_cpu(cpu) {
61689+ per_cpu(exec_counter, cpu) = (u64)cpu;
61690+ }
61691+
61692+ return 0;
61693+}
61694+early_initcall(init_exec_counters);
61695+static inline void increment_exec_counter(void)
61696+{
61697+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
61698+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
61699+}
61700+#else
61701+static inline void increment_exec_counter(void) {}
61702+#endif
61703+
61704+extern void gr_handle_exec_args(struct linux_binprm *bprm,
61705+ struct user_arg_ptr argv);
61706+
61707 /*
61708 * sys_execve() executes a new program.
61709 */
61710@@ -1426,6 +1530,11 @@ static int do_execve_common(struct filename *filename,
61711 struct user_arg_ptr argv,
61712 struct user_arg_ptr envp)
61713 {
61714+#ifdef CONFIG_GRKERNSEC
61715+ struct file *old_exec_file;
61716+ struct acl_subject_label *old_acl;
61717+ struct rlimit old_rlim[RLIM_NLIMITS];
61718+#endif
61719 struct linux_binprm *bprm;
61720 struct file *file;
61721 struct files_struct *displaced;
61722@@ -1434,6 +1543,8 @@ static int do_execve_common(struct filename *filename,
61723 if (IS_ERR(filename))
61724 return PTR_ERR(filename);
61725
61726+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
61727+
61728 /*
61729 * We move the actual failure in case of RLIMIT_NPROC excess from
61730 * set*uid() to execve() because too many poorly written programs
61731@@ -1471,11 +1582,21 @@ static int do_execve_common(struct filename *filename,
61732 if (IS_ERR(file))
61733 goto out_unmark;
61734
61735+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
61736+ retval = -EPERM;
61737+ goto out_unmark;
61738+ }
61739+
61740 sched_exec();
61741
61742 bprm->file = file;
61743 bprm->filename = bprm->interp = filename->name;
61744
61745+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
61746+ retval = -EACCES;
61747+ goto out_unmark;
61748+ }
61749+
61750 retval = bprm_mm_init(bprm);
61751 if (retval)
61752 goto out_unmark;
61753@@ -1492,24 +1613,70 @@ static int do_execve_common(struct filename *filename,
61754 if (retval < 0)
61755 goto out;
61756
61757+#ifdef CONFIG_GRKERNSEC
61758+ old_acl = current->acl;
61759+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
61760+ old_exec_file = current->exec_file;
61761+ get_file(file);
61762+ current->exec_file = file;
61763+#endif
61764+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61765+ /* limit suid stack to 8MB
61766+ * we saved the old limits above and will restore them if this exec fails
61767+ */
61768+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
61769+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
61770+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
61771+#endif
61772+
61773+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
61774+ retval = -EPERM;
61775+ goto out_fail;
61776+ }
61777+
61778+ if (!gr_tpe_allow(file)) {
61779+ retval = -EACCES;
61780+ goto out_fail;
61781+ }
61782+
61783+ if (gr_check_crash_exec(file)) {
61784+ retval = -EACCES;
61785+ goto out_fail;
61786+ }
61787+
61788+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
61789+ bprm->unsafe);
61790+ if (retval < 0)
61791+ goto out_fail;
61792+
61793 retval = copy_strings_kernel(1, &bprm->filename, bprm);
61794 if (retval < 0)
61795- goto out;
61796+ goto out_fail;
61797
61798 bprm->exec = bprm->p;
61799 retval = copy_strings(bprm->envc, envp, bprm);
61800 if (retval < 0)
61801- goto out;
61802+ goto out_fail;
61803
61804 retval = copy_strings(bprm->argc, argv, bprm);
61805 if (retval < 0)
61806- goto out;
61807+ goto out_fail;
61808+
61809+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
61810+
61811+ gr_handle_exec_args(bprm, argv);
61812
61813 retval = exec_binprm(bprm);
61814 if (retval < 0)
61815- goto out;
61816+ goto out_fail;
61817+#ifdef CONFIG_GRKERNSEC
61818+ if (old_exec_file)
61819+ fput(old_exec_file);
61820+#endif
61821
61822 /* execve succeeded */
61823+
61824+ increment_exec_counter();
61825 current->fs->in_exec = 0;
61826 current->in_execve = 0;
61827 acct_update_integrals(current);
61828@@ -1520,6 +1687,14 @@ static int do_execve_common(struct filename *filename,
61829 put_files_struct(displaced);
61830 return retval;
61831
61832+out_fail:
61833+#ifdef CONFIG_GRKERNSEC
61834+ current->acl = old_acl;
61835+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
61836+ fput(current->exec_file);
61837+ current->exec_file = old_exec_file;
61838+#endif
61839+
61840 out:
61841 if (bprm->mm) {
61842 acct_arg_size(bprm, 0);
61843@@ -1611,3 +1786,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
61844 return compat_do_execve(getname(filename), argv, envp);
61845 }
61846 #endif
61847+
61848+int pax_check_flags(unsigned long *flags)
61849+{
61850+ int retval = 0;
61851+
61852+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
61853+ if (*flags & MF_PAX_SEGMEXEC)
61854+ {
61855+ *flags &= ~MF_PAX_SEGMEXEC;
61856+ retval = -EINVAL;
61857+ }
61858+#endif
61859+
61860+ if ((*flags & MF_PAX_PAGEEXEC)
61861+
61862+#ifdef CONFIG_PAX_PAGEEXEC
61863+ && (*flags & MF_PAX_SEGMEXEC)
61864+#endif
61865+
61866+ )
61867+ {
61868+ *flags &= ~MF_PAX_PAGEEXEC;
61869+ retval = -EINVAL;
61870+ }
61871+
61872+ if ((*flags & MF_PAX_MPROTECT)
61873+
61874+#ifdef CONFIG_PAX_MPROTECT
61875+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61876+#endif
61877+
61878+ )
61879+ {
61880+ *flags &= ~MF_PAX_MPROTECT;
61881+ retval = -EINVAL;
61882+ }
61883+
61884+ if ((*flags & MF_PAX_EMUTRAMP)
61885+
61886+#ifdef CONFIG_PAX_EMUTRAMP
61887+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61888+#endif
61889+
61890+ )
61891+ {
61892+ *flags &= ~MF_PAX_EMUTRAMP;
61893+ retval = -EINVAL;
61894+ }
61895+
61896+ return retval;
61897+}
61898+
61899+EXPORT_SYMBOL(pax_check_flags);
61900+
61901+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61902+char *pax_get_path(const struct path *path, char *buf, int buflen)
61903+{
61904+ char *pathname = d_path(path, buf, buflen);
61905+
61906+ if (IS_ERR(pathname))
61907+ goto toolong;
61908+
61909+ pathname = mangle_path(buf, pathname, "\t\n\\");
61910+ if (!pathname)
61911+ goto toolong;
61912+
61913+ *pathname = 0;
61914+ return buf;
61915+
61916+toolong:
61917+ return "<path too long>";
61918+}
61919+EXPORT_SYMBOL(pax_get_path);
61920+
61921+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
61922+{
61923+ struct task_struct *tsk = current;
61924+ struct mm_struct *mm = current->mm;
61925+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
61926+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
61927+ char *path_exec = NULL;
61928+ char *path_fault = NULL;
61929+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
61930+ siginfo_t info = { };
61931+
61932+ if (buffer_exec && buffer_fault) {
61933+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
61934+
61935+ down_read(&mm->mmap_sem);
61936+ vma = mm->mmap;
61937+ while (vma && (!vma_exec || !vma_fault)) {
61938+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
61939+ vma_exec = vma;
61940+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
61941+ vma_fault = vma;
61942+ vma = vma->vm_next;
61943+ }
61944+ if (vma_exec)
61945+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
61946+ if (vma_fault) {
61947+ start = vma_fault->vm_start;
61948+ end = vma_fault->vm_end;
61949+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
61950+ if (vma_fault->vm_file)
61951+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
61952+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
61953+ path_fault = "<heap>";
61954+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
61955+ path_fault = "<stack>";
61956+ else
61957+ path_fault = "<anonymous mapping>";
61958+ }
61959+ up_read(&mm->mmap_sem);
61960+ }
61961+ if (tsk->signal->curr_ip)
61962+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
61963+ else
61964+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
61965+ 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),
61966+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
61967+ free_page((unsigned long)buffer_exec);
61968+ free_page((unsigned long)buffer_fault);
61969+ pax_report_insns(regs, pc, sp);
61970+ info.si_signo = SIGKILL;
61971+ info.si_errno = 0;
61972+ info.si_code = SI_KERNEL;
61973+ info.si_pid = 0;
61974+ info.si_uid = 0;
61975+ do_coredump(&info);
61976+}
61977+#endif
61978+
61979+#ifdef CONFIG_PAX_REFCOUNT
61980+void pax_report_refcount_overflow(struct pt_regs *regs)
61981+{
61982+ if (current->signal->curr_ip)
61983+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
61984+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
61985+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61986+ else
61987+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
61988+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61989+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
61990+ preempt_disable();
61991+ show_regs(regs);
61992+ preempt_enable();
61993+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
61994+}
61995+#endif
61996+
61997+#ifdef CONFIG_PAX_USERCOPY
61998+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
61999+static noinline int check_stack_object(const void *obj, unsigned long len)
62000+{
62001+ const void * const stack = task_stack_page(current);
62002+ const void * const stackend = stack + THREAD_SIZE;
62003+
62004+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
62005+ const void *frame = NULL;
62006+ const void *oldframe;
62007+#endif
62008+
62009+ if (obj + len < obj)
62010+ return -1;
62011+
62012+ if (obj + len <= stack || stackend <= obj)
62013+ return 0;
62014+
62015+ if (obj < stack || stackend < obj + len)
62016+ return -1;
62017+
62018+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
62019+ oldframe = __builtin_frame_address(1);
62020+ if (oldframe)
62021+ frame = __builtin_frame_address(2);
62022+ /*
62023+ low ----------------------------------------------> high
62024+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
62025+ ^----------------^
62026+ allow copies only within here
62027+ */
62028+ while (stack <= frame && frame < stackend) {
62029+ /* if obj + len extends past the last frame, this
62030+ check won't pass and the next frame will be 0,
62031+ causing us to bail out and correctly report
62032+ the copy as invalid
62033+ */
62034+ if (obj + len <= frame)
62035+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
62036+ oldframe = frame;
62037+ frame = *(const void * const *)frame;
62038+ }
62039+ return -1;
62040+#else
62041+ return 1;
62042+#endif
62043+}
62044+
62045+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
62046+{
62047+ if (current->signal->curr_ip)
62048+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
62049+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
62050+ else
62051+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
62052+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
62053+ dump_stack();
62054+ gr_handle_kernel_exploit();
62055+ do_group_exit(SIGKILL);
62056+}
62057+#endif
62058+
62059+#ifdef CONFIG_PAX_USERCOPY
62060+
62061+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
62062+{
62063+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
62064+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
62065+#ifdef CONFIG_MODULES
62066+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
62067+#else
62068+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
62069+#endif
62070+
62071+#else
62072+ unsigned long textlow = (unsigned long)_stext;
62073+ unsigned long texthigh = (unsigned long)_etext;
62074+
62075+#ifdef CONFIG_X86_64
62076+ /* check against linear mapping as well */
62077+ if (high > (unsigned long)__va(__pa(textlow)) &&
62078+ low < (unsigned long)__va(__pa(texthigh)))
62079+ return true;
62080+#endif
62081+
62082+#endif
62083+
62084+ if (high <= textlow || low >= texthigh)
62085+ return false;
62086+ else
62087+ return true;
62088+}
62089+#endif
62090+
62091+void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
62092+{
62093+#ifdef CONFIG_PAX_USERCOPY
62094+ const char *type;
62095+#endif
62096+
62097+#ifndef CONFIG_STACK_GROWSUP
62098+ unsigned long stackstart = (unsigned long)task_stack_page(current);
62099+ unsigned long currentsp = (unsigned long)&stackstart;
62100+ if (unlikely((currentsp < stackstart + 512 ||
62101+ currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
62102+ BUG();
62103+#endif
62104+
62105+#ifndef CONFIG_PAX_USERCOPY_DEBUG
62106+ if (const_size)
62107+ return;
62108+#endif
62109+
62110+#ifdef CONFIG_PAX_USERCOPY
62111+ if (!n)
62112+ return;
62113+
62114+ type = check_heap_object(ptr, n);
62115+ if (!type) {
62116+ int ret = check_stack_object(ptr, n);
62117+ if (ret == 1 || ret == 2)
62118+ return;
62119+ if (ret == 0) {
62120+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
62121+ type = "<kernel text>";
62122+ else
62123+ return;
62124+ } else
62125+ type = "<process stack>";
62126+ }
62127+
62128+ pax_report_usercopy(ptr, n, to_user, type);
62129+#endif
62130+
62131+}
62132+EXPORT_SYMBOL(__check_object_size);
62133+
62134+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
62135+void pax_track_stack(void)
62136+{
62137+ unsigned long sp = (unsigned long)&sp;
62138+ if (sp < current_thread_info()->lowest_stack &&
62139+ sp > (unsigned long)task_stack_page(current))
62140+ current_thread_info()->lowest_stack = sp;
62141+ if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
62142+ BUG();
62143+}
62144+EXPORT_SYMBOL(pax_track_stack);
62145+#endif
62146+
62147+#ifdef CONFIG_PAX_SIZE_OVERFLOW
62148+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
62149+{
62150+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
62151+ dump_stack();
62152+ do_group_exit(SIGKILL);
62153+}
62154+EXPORT_SYMBOL(report_size_overflow);
62155+#endif
62156diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
62157index 9f9992b..8b59411 100644
62158--- a/fs/ext2/balloc.c
62159+++ b/fs/ext2/balloc.c
62160@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
62161
62162 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
62163 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
62164- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
62165+ if (free_blocks < root_blocks + 1 &&
62166 !uid_eq(sbi->s_resuid, current_fsuid()) &&
62167 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
62168- !in_group_p (sbi->s_resgid))) {
62169+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
62170 return 0;
62171 }
62172 return 1;
62173diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
62174index 9142614..97484fa 100644
62175--- a/fs/ext2/xattr.c
62176+++ b/fs/ext2/xattr.c
62177@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
62178 struct buffer_head *bh = NULL;
62179 struct ext2_xattr_entry *entry;
62180 char *end;
62181- size_t rest = buffer_size;
62182+ size_t rest = buffer_size, total_size = 0;
62183 int error;
62184
62185 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
62186@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
62187 buffer += size;
62188 }
62189 rest -= size;
62190+ total_size += size;
62191 }
62192 }
62193- error = buffer_size - rest; /* total size */
62194+ error = total_size;
62195
62196 cleanup:
62197 brelse(bh);
62198diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
62199index 158b5d4..2432610 100644
62200--- a/fs/ext3/balloc.c
62201+++ b/fs/ext3/balloc.c
62202@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
62203
62204 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
62205 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
62206- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
62207+ if (free_blocks < root_blocks + 1 &&
62208 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
62209 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
62210- !in_group_p (sbi->s_resgid))) {
62211+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
62212 return 0;
62213 }
62214 return 1;
62215diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
62216index c6874be..f8a6ae8 100644
62217--- a/fs/ext3/xattr.c
62218+++ b/fs/ext3/xattr.c
62219@@ -330,7 +330,7 @@ static int
62220 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
62221 char *buffer, size_t buffer_size)
62222 {
62223- size_t rest = buffer_size;
62224+ size_t rest = buffer_size, total_size = 0;
62225
62226 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
62227 const struct xattr_handler *handler =
62228@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
62229 buffer += size;
62230 }
62231 rest -= size;
62232+ total_size += size;
62233 }
62234 }
62235- return buffer_size - rest;
62236+ return total_size;
62237 }
62238
62239 static int
62240diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
62241index e069155..b825b08 100644
62242--- a/fs/ext4/balloc.c
62243+++ b/fs/ext4/balloc.c
62244@@ -557,8 +557,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
62245 /* Hm, nope. Are (enough) root reserved clusters available? */
62246 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
62247 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
62248- capable(CAP_SYS_RESOURCE) ||
62249- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
62250+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
62251+ capable_nolog(CAP_SYS_RESOURCE)) {
62252
62253 if (free_clusters >= (nclusters + dirty_clusters +
62254 resv_clusters))
62255diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
62256index 96ac9d3..1c30e7e6 100644
62257--- a/fs/ext4/ext4.h
62258+++ b/fs/ext4/ext4.h
62259@@ -1275,19 +1275,19 @@ struct ext4_sb_info {
62260 unsigned long s_mb_last_start;
62261
62262 /* stats for buddy allocator */
62263- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
62264- atomic_t s_bal_success; /* we found long enough chunks */
62265- atomic_t s_bal_allocated; /* in blocks */
62266- atomic_t s_bal_ex_scanned; /* total extents scanned */
62267- atomic_t s_bal_goals; /* goal hits */
62268- atomic_t s_bal_breaks; /* too long searches */
62269- atomic_t s_bal_2orders; /* 2^order hits */
62270+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
62271+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
62272+ atomic_unchecked_t s_bal_allocated; /* in blocks */
62273+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
62274+ atomic_unchecked_t s_bal_goals; /* goal hits */
62275+ atomic_unchecked_t s_bal_breaks; /* too long searches */
62276+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
62277 spinlock_t s_bal_lock;
62278 unsigned long s_mb_buddies_generated;
62279 unsigned long long s_mb_generation_time;
62280- atomic_t s_mb_lost_chunks;
62281- atomic_t s_mb_preallocated;
62282- atomic_t s_mb_discarded;
62283+ atomic_unchecked_t s_mb_lost_chunks;
62284+ atomic_unchecked_t s_mb_preallocated;
62285+ atomic_unchecked_t s_mb_discarded;
62286 atomic_t s_lock_busy;
62287
62288 /* locality groups */
62289diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
62290index 8b0f9ef..cb9f620 100644
62291--- a/fs/ext4/mballoc.c
62292+++ b/fs/ext4/mballoc.c
62293@@ -1901,7 +1901,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
62294 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
62295
62296 if (EXT4_SB(sb)->s_mb_stats)
62297- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
62298+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
62299
62300 break;
62301 }
62302@@ -2211,7 +2211,7 @@ repeat:
62303 ac->ac_status = AC_STATUS_CONTINUE;
62304 ac->ac_flags |= EXT4_MB_HINT_FIRST;
62305 cr = 3;
62306- atomic_inc(&sbi->s_mb_lost_chunks);
62307+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
62308 goto repeat;
62309 }
62310 }
62311@@ -2717,25 +2717,25 @@ int ext4_mb_release(struct super_block *sb)
62312 if (sbi->s_mb_stats) {
62313 ext4_msg(sb, KERN_INFO,
62314 "mballoc: %u blocks %u reqs (%u success)",
62315- atomic_read(&sbi->s_bal_allocated),
62316- atomic_read(&sbi->s_bal_reqs),
62317- atomic_read(&sbi->s_bal_success));
62318+ atomic_read_unchecked(&sbi->s_bal_allocated),
62319+ atomic_read_unchecked(&sbi->s_bal_reqs),
62320+ atomic_read_unchecked(&sbi->s_bal_success));
62321 ext4_msg(sb, KERN_INFO,
62322 "mballoc: %u extents scanned, %u goal hits, "
62323 "%u 2^N hits, %u breaks, %u lost",
62324- atomic_read(&sbi->s_bal_ex_scanned),
62325- atomic_read(&sbi->s_bal_goals),
62326- atomic_read(&sbi->s_bal_2orders),
62327- atomic_read(&sbi->s_bal_breaks),
62328- atomic_read(&sbi->s_mb_lost_chunks));
62329+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
62330+ atomic_read_unchecked(&sbi->s_bal_goals),
62331+ atomic_read_unchecked(&sbi->s_bal_2orders),
62332+ atomic_read_unchecked(&sbi->s_bal_breaks),
62333+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
62334 ext4_msg(sb, KERN_INFO,
62335 "mballoc: %lu generated and it took %Lu",
62336 sbi->s_mb_buddies_generated,
62337 sbi->s_mb_generation_time);
62338 ext4_msg(sb, KERN_INFO,
62339 "mballoc: %u preallocated, %u discarded",
62340- atomic_read(&sbi->s_mb_preallocated),
62341- atomic_read(&sbi->s_mb_discarded));
62342+ atomic_read_unchecked(&sbi->s_mb_preallocated),
62343+ atomic_read_unchecked(&sbi->s_mb_discarded));
62344 }
62345
62346 free_percpu(sbi->s_locality_groups);
62347@@ -3192,16 +3192,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
62348 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
62349
62350 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
62351- atomic_inc(&sbi->s_bal_reqs);
62352- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
62353+ atomic_inc_unchecked(&sbi->s_bal_reqs);
62354+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
62355 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
62356- atomic_inc(&sbi->s_bal_success);
62357- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
62358+ atomic_inc_unchecked(&sbi->s_bal_success);
62359+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
62360 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
62361 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
62362- atomic_inc(&sbi->s_bal_goals);
62363+ atomic_inc_unchecked(&sbi->s_bal_goals);
62364 if (ac->ac_found > sbi->s_mb_max_to_scan)
62365- atomic_inc(&sbi->s_bal_breaks);
62366+ atomic_inc_unchecked(&sbi->s_bal_breaks);
62367 }
62368
62369 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
62370@@ -3628,7 +3628,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
62371 trace_ext4_mb_new_inode_pa(ac, pa);
62372
62373 ext4_mb_use_inode_pa(ac, pa);
62374- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
62375+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
62376
62377 ei = EXT4_I(ac->ac_inode);
62378 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62379@@ -3688,7 +3688,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
62380 trace_ext4_mb_new_group_pa(ac, pa);
62381
62382 ext4_mb_use_group_pa(ac, pa);
62383- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62384+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62385
62386 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62387 lg = ac->ac_lg;
62388@@ -3777,7 +3777,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
62389 * from the bitmap and continue.
62390 */
62391 }
62392- atomic_add(free, &sbi->s_mb_discarded);
62393+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
62394
62395 return err;
62396 }
62397@@ -3795,7 +3795,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
62398 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
62399 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
62400 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
62401- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62402+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62403 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
62404
62405 return 0;
62406diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
62407index 8313ca3..8a37d08 100644
62408--- a/fs/ext4/mmp.c
62409+++ b/fs/ext4/mmp.c
62410@@ -111,7 +111,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
62411 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
62412 const char *function, unsigned int line, const char *msg)
62413 {
62414- __ext4_warning(sb, function, line, msg);
62415+ __ext4_warning(sb, function, line, "%s", msg);
62416 __ext4_warning(sb, function, line,
62417 "MMP failure info: last update time: %llu, last update "
62418 "node: %s, last update device: %s\n",
62419diff --git a/fs/ext4/super.c b/fs/ext4/super.c
62420index b1f0ac7..77e9a05 100644
62421--- a/fs/ext4/super.c
62422+++ b/fs/ext4/super.c
62423@@ -1274,7 +1274,7 @@ static ext4_fsblk_t get_sb_block(void **data)
62424 }
62425
62426 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
62427-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62428+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62429 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
62430
62431 #ifdef CONFIG_QUOTA
62432@@ -2454,7 +2454,7 @@ struct ext4_attr {
62433 int offset;
62434 int deprecated_val;
62435 } u;
62436-};
62437+} __do_const;
62438
62439 static int parse_strtoull(const char *buf,
62440 unsigned long long max, unsigned long long *value)
62441diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
62442index 2d1e5803..1b082d415 100644
62443--- a/fs/ext4/xattr.c
62444+++ b/fs/ext4/xattr.c
62445@@ -399,7 +399,7 @@ static int
62446 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62447 char *buffer, size_t buffer_size)
62448 {
62449- size_t rest = buffer_size;
62450+ size_t rest = buffer_size, total_size = 0;
62451
62452 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
62453 const struct xattr_handler *handler =
62454@@ -416,9 +416,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62455 buffer += size;
62456 }
62457 rest -= size;
62458+ total_size += size;
62459 }
62460 }
62461- return buffer_size - rest;
62462+ return total_size;
62463 }
62464
62465 static int
62466diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
62467index 6df8d3d..b8b92c2 100644
62468--- a/fs/fat/namei_vfat.c
62469+++ b/fs/fat/namei_vfat.c
62470@@ -736,7 +736,12 @@ static struct dentry *vfat_lookup(struct inode *dir, struct dentry *dentry,
62471 }
62472
62473 alias = d_find_alias(inode);
62474- if (alias && !vfat_d_anon_disconn(alias)) {
62475+ /*
62476+ * Checking "alias->d_parent == dentry->d_parent" to make sure
62477+ * FS is not corrupted (especially double linked dir).
62478+ */
62479+ if (alias && alias->d_parent == dentry->d_parent &&
62480+ !vfat_d_anon_disconn(alias)) {
62481 /*
62482 * This inode has non anonymous-DCACHE_DISCONNECTED
62483 * dentry. This means, the user did ->lookup() by an
62484@@ -755,12 +760,9 @@ static struct dentry *vfat_lookup(struct inode *dir, struct dentry *dentry,
62485
62486 out:
62487 mutex_unlock(&MSDOS_SB(sb)->s_lock);
62488- dentry->d_time = dentry->d_parent->d_inode->i_version;
62489- dentry = d_splice_alias(inode, dentry);
62490- if (dentry)
62491- dentry->d_time = dentry->d_parent->d_inode->i_version;
62492- return dentry;
62493-
62494+ if (!inode)
62495+ dentry->d_time = dir->i_version;
62496+ return d_splice_alias(inode, dentry);
62497 error:
62498 mutex_unlock(&MSDOS_SB(sb)->s_lock);
62499 return ERR_PTR(err);
62500@@ -793,7 +795,6 @@ static int vfat_create(struct inode *dir, struct dentry *dentry, umode_t mode,
62501 inode->i_mtime = inode->i_atime = inode->i_ctime = ts;
62502 /* timestamp is already written, so mark_inode_dirty() is unneeded. */
62503
62504- dentry->d_time = dentry->d_parent->d_inode->i_version;
62505 d_instantiate(dentry, inode);
62506 out:
62507 mutex_unlock(&MSDOS_SB(sb)->s_lock);
62508@@ -824,6 +825,7 @@ static int vfat_rmdir(struct inode *dir, struct dentry *dentry)
62509 clear_nlink(inode);
62510 inode->i_mtime = inode->i_atime = CURRENT_TIME_SEC;
62511 fat_detach(inode);
62512+ dentry->d_time = dir->i_version;
62513 out:
62514 mutex_unlock(&MSDOS_SB(sb)->s_lock);
62515
62516@@ -849,6 +851,7 @@ static int vfat_unlink(struct inode *dir, struct dentry *dentry)
62517 clear_nlink(inode);
62518 inode->i_mtime = inode->i_atime = CURRENT_TIME_SEC;
62519 fat_detach(inode);
62520+ dentry->d_time = dir->i_version;
62521 out:
62522 mutex_unlock(&MSDOS_SB(sb)->s_lock);
62523
62524@@ -889,7 +892,6 @@ static int vfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
62525 inode->i_mtime = inode->i_atime = inode->i_ctime = ts;
62526 /* timestamp is already written, so mark_inode_dirty() is unneeded. */
62527
62528- dentry->d_time = dentry->d_parent->d_inode->i_version;
62529 d_instantiate(dentry, inode);
62530
62531 mutex_unlock(&MSDOS_SB(sb)->s_lock);
62532diff --git a/fs/fcntl.c b/fs/fcntl.c
62533index 22d1c3d..600cf7e 100644
62534--- a/fs/fcntl.c
62535+++ b/fs/fcntl.c
62536@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
62537 if (err)
62538 return err;
62539
62540+ if (gr_handle_chroot_fowner(pid, type))
62541+ return -ENOENT;
62542+ if (gr_check_protected_task_fowner(pid, type))
62543+ return -EACCES;
62544+
62545 f_modown(filp, pid, type, force);
62546 return 0;
62547 }
62548diff --git a/fs/fhandle.c b/fs/fhandle.c
62549index 999ff5c..ac037c9 100644
62550--- a/fs/fhandle.c
62551+++ b/fs/fhandle.c
62552@@ -8,6 +8,7 @@
62553 #include <linux/fs_struct.h>
62554 #include <linux/fsnotify.h>
62555 #include <linux/personality.h>
62556+#include <linux/grsecurity.h>
62557 #include <asm/uaccess.h>
62558 #include "internal.h"
62559 #include "mount.h"
62560@@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
62561 } else
62562 retval = 0;
62563 /* copy the mount id */
62564- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
62565- sizeof(*mnt_id)) ||
62566+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
62567 copy_to_user(ufh, handle,
62568 sizeof(struct file_handle) + handle_bytes))
62569 retval = -EFAULT;
62570@@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
62571 * the directory. Ideally we would like CAP_DAC_SEARCH.
62572 * But we don't have that
62573 */
62574- if (!capable(CAP_DAC_READ_SEARCH)) {
62575+ if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
62576 retval = -EPERM;
62577 goto out_err;
62578 }
62579diff --git a/fs/file.c b/fs/file.c
62580index 66923fe..2849783 100644
62581--- a/fs/file.c
62582+++ b/fs/file.c
62583@@ -16,6 +16,7 @@
62584 #include <linux/slab.h>
62585 #include <linux/vmalloc.h>
62586 #include <linux/file.h>
62587+#include <linux/security.h>
62588 #include <linux/fdtable.h>
62589 #include <linux/bitops.h>
62590 #include <linux/interrupt.h>
62591@@ -139,7 +140,7 @@ out:
62592 * Return <0 error code on error; 1 on successful completion.
62593 * The files->file_lock should be held on entry, and will be held on exit.
62594 */
62595-static int expand_fdtable(struct files_struct *files, int nr)
62596+static int expand_fdtable(struct files_struct *files, unsigned int nr)
62597 __releases(files->file_lock)
62598 __acquires(files->file_lock)
62599 {
62600@@ -184,7 +185,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
62601 * expanded and execution may have blocked.
62602 * The files->file_lock should be held on entry, and will be held on exit.
62603 */
62604-static int expand_files(struct files_struct *files, int nr)
62605+static int expand_files(struct files_struct *files, unsigned int nr)
62606 {
62607 struct fdtable *fdt;
62608
62609@@ -799,6 +800,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
62610 if (!file)
62611 return __close_fd(files, fd);
62612
62613+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
62614 if (fd >= rlimit(RLIMIT_NOFILE))
62615 return -EBADF;
62616
62617@@ -825,6 +827,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
62618 if (unlikely(oldfd == newfd))
62619 return -EINVAL;
62620
62621+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
62622 if (newfd >= rlimit(RLIMIT_NOFILE))
62623 return -EBADF;
62624
62625@@ -880,6 +883,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
62626 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
62627 {
62628 int err;
62629+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
62630 if (from >= rlimit(RLIMIT_NOFILE))
62631 return -EINVAL;
62632 err = alloc_fd(from, flags);
62633diff --git a/fs/filesystems.c b/fs/filesystems.c
62634index 5797d45..7d7d79a 100644
62635--- a/fs/filesystems.c
62636+++ b/fs/filesystems.c
62637@@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
62638 int len = dot ? dot - name : strlen(name);
62639
62640 fs = __get_fs_type(name, len);
62641+#ifdef CONFIG_GRKERNSEC_MODHARDEN
62642+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
62643+#else
62644 if (!fs && (request_module("fs-%.*s", len, name) == 0))
62645+#endif
62646 fs = __get_fs_type(name, len);
62647
62648 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
62649diff --git a/fs/fs_struct.c b/fs/fs_struct.c
62650index 7dca743..543d620 100644
62651--- a/fs/fs_struct.c
62652+++ b/fs/fs_struct.c
62653@@ -4,6 +4,7 @@
62654 #include <linux/path.h>
62655 #include <linux/slab.h>
62656 #include <linux/fs_struct.h>
62657+#include <linux/grsecurity.h>
62658 #include "internal.h"
62659
62660 /*
62661@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
62662 write_seqcount_begin(&fs->seq);
62663 old_root = fs->root;
62664 fs->root = *path;
62665+ gr_set_chroot_entries(current, path);
62666 write_seqcount_end(&fs->seq);
62667 spin_unlock(&fs->lock);
62668 if (old_root.dentry)
62669@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
62670 int hits = 0;
62671 spin_lock(&fs->lock);
62672 write_seqcount_begin(&fs->seq);
62673+ /* this root replacement is only done by pivot_root,
62674+ leave grsec's chroot tagging alone for this task
62675+ so that a pivoted root isn't treated as a chroot
62676+ */
62677 hits += replace_path(&fs->root, old_root, new_root);
62678 hits += replace_path(&fs->pwd, old_root, new_root);
62679 write_seqcount_end(&fs->seq);
62680@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
62681 task_lock(tsk);
62682 spin_lock(&fs->lock);
62683 tsk->fs = NULL;
62684- kill = !--fs->users;
62685+ gr_clear_chroot_entries(tsk);
62686+ kill = !atomic_dec_return(&fs->users);
62687 spin_unlock(&fs->lock);
62688 task_unlock(tsk);
62689 if (kill)
62690@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62691 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
62692 /* We don't need to lock fs - think why ;-) */
62693 if (fs) {
62694- fs->users = 1;
62695+ atomic_set(&fs->users, 1);
62696 fs->in_exec = 0;
62697 spin_lock_init(&fs->lock);
62698 seqcount_init(&fs->seq);
62699@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62700 spin_lock(&old->lock);
62701 fs->root = old->root;
62702 path_get(&fs->root);
62703+ /* instead of calling gr_set_chroot_entries here,
62704+ we call it from every caller of this function
62705+ */
62706 fs->pwd = old->pwd;
62707 path_get(&fs->pwd);
62708 spin_unlock(&old->lock);
62709@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
62710
62711 task_lock(current);
62712 spin_lock(&fs->lock);
62713- kill = !--fs->users;
62714+ kill = !atomic_dec_return(&fs->users);
62715 current->fs = new_fs;
62716+ gr_set_chroot_entries(current, &new_fs->root);
62717 spin_unlock(&fs->lock);
62718 task_unlock(current);
62719
62720@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
62721
62722 int current_umask(void)
62723 {
62724- return current->fs->umask;
62725+ return current->fs->umask | gr_acl_umask();
62726 }
62727 EXPORT_SYMBOL(current_umask);
62728
62729 /* to be mentioned only in INIT_TASK */
62730 struct fs_struct init_fs = {
62731- .users = 1,
62732+ .users = ATOMIC_INIT(1),
62733 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
62734 .seq = SEQCNT_ZERO(init_fs.seq),
62735 .umask = 0022,
62736diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
62737index 89acec7..a575262 100644
62738--- a/fs/fscache/cookie.c
62739+++ b/fs/fscache/cookie.c
62740@@ -19,7 +19,7 @@
62741
62742 struct kmem_cache *fscache_cookie_jar;
62743
62744-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
62745+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
62746
62747 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
62748 static int fscache_alloc_object(struct fscache_cache *cache,
62749@@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
62750 parent ? (char *) parent->def->name : "<no-parent>",
62751 def->name, netfs_data, enable);
62752
62753- fscache_stat(&fscache_n_acquires);
62754+ fscache_stat_unchecked(&fscache_n_acquires);
62755
62756 /* if there's no parent cookie, then we don't create one here either */
62757 if (!parent) {
62758- fscache_stat(&fscache_n_acquires_null);
62759+ fscache_stat_unchecked(&fscache_n_acquires_null);
62760 _leave(" [no parent]");
62761 return NULL;
62762 }
62763@@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62764 /* allocate and initialise a cookie */
62765 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
62766 if (!cookie) {
62767- fscache_stat(&fscache_n_acquires_oom);
62768+ fscache_stat_unchecked(&fscache_n_acquires_oom);
62769 _leave(" [ENOMEM]");
62770 return NULL;
62771 }
62772@@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
62773
62774 switch (cookie->def->type) {
62775 case FSCACHE_COOKIE_TYPE_INDEX:
62776- fscache_stat(&fscache_n_cookie_index);
62777+ fscache_stat_unchecked(&fscache_n_cookie_index);
62778 break;
62779 case FSCACHE_COOKIE_TYPE_DATAFILE:
62780- fscache_stat(&fscache_n_cookie_data);
62781+ fscache_stat_unchecked(&fscache_n_cookie_data);
62782 break;
62783 default:
62784- fscache_stat(&fscache_n_cookie_special);
62785+ fscache_stat_unchecked(&fscache_n_cookie_special);
62786 break;
62787 }
62788
62789@@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62790 } else {
62791 atomic_dec(&parent->n_children);
62792 __fscache_cookie_put(cookie);
62793- fscache_stat(&fscache_n_acquires_nobufs);
62794+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
62795 _leave(" = NULL");
62796 return NULL;
62797 }
62798@@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62799 }
62800 }
62801
62802- fscache_stat(&fscache_n_acquires_ok);
62803+ fscache_stat_unchecked(&fscache_n_acquires_ok);
62804 _leave(" = %p", cookie);
62805 return cookie;
62806 }
62807@@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
62808 cache = fscache_select_cache_for_object(cookie->parent);
62809 if (!cache) {
62810 up_read(&fscache_addremove_sem);
62811- fscache_stat(&fscache_n_acquires_no_cache);
62812+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
62813 _leave(" = -ENOMEDIUM [no cache]");
62814 return -ENOMEDIUM;
62815 }
62816@@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
62817 object = cache->ops->alloc_object(cache, cookie);
62818 fscache_stat_d(&fscache_n_cop_alloc_object);
62819 if (IS_ERR(object)) {
62820- fscache_stat(&fscache_n_object_no_alloc);
62821+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
62822 ret = PTR_ERR(object);
62823 goto error;
62824 }
62825
62826- fscache_stat(&fscache_n_object_alloc);
62827+ fscache_stat_unchecked(&fscache_n_object_alloc);
62828
62829- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
62830+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
62831
62832 _debug("ALLOC OBJ%x: %s {%lx}",
62833 object->debug_id, cookie->def->name, object->events);
62834@@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
62835
62836 _enter("{%s}", cookie->def->name);
62837
62838- fscache_stat(&fscache_n_invalidates);
62839+ fscache_stat_unchecked(&fscache_n_invalidates);
62840
62841 /* Only permit invalidation of data files. Invalidating an index will
62842 * require the caller to release all its attachments to the tree rooted
62843@@ -476,10 +476,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
62844 {
62845 struct fscache_object *object;
62846
62847- fscache_stat(&fscache_n_updates);
62848+ fscache_stat_unchecked(&fscache_n_updates);
62849
62850 if (!cookie) {
62851- fscache_stat(&fscache_n_updates_null);
62852+ fscache_stat_unchecked(&fscache_n_updates_null);
62853 _leave(" [no cookie]");
62854 return;
62855 }
62856@@ -580,12 +580,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
62857 */
62858 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
62859 {
62860- fscache_stat(&fscache_n_relinquishes);
62861+ fscache_stat_unchecked(&fscache_n_relinquishes);
62862 if (retire)
62863- fscache_stat(&fscache_n_relinquishes_retire);
62864+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
62865
62866 if (!cookie) {
62867- fscache_stat(&fscache_n_relinquishes_null);
62868+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
62869 _leave(" [no cookie]");
62870 return;
62871 }
62872@@ -686,7 +686,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
62873 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
62874 goto inconsistent;
62875
62876- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62877+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62878
62879 __fscache_use_cookie(cookie);
62880 if (fscache_submit_op(object, op) < 0)
62881diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
62882index 7872a62..d91b19f 100644
62883--- a/fs/fscache/internal.h
62884+++ b/fs/fscache/internal.h
62885@@ -137,8 +137,8 @@ extern void fscache_operation_gc(struct work_struct *);
62886 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
62887 extern int fscache_wait_for_operation_activation(struct fscache_object *,
62888 struct fscache_operation *,
62889- atomic_t *,
62890- atomic_t *,
62891+ atomic_unchecked_t *,
62892+ atomic_unchecked_t *,
62893 void (*)(struct fscache_operation *));
62894 extern void fscache_invalidate_writes(struct fscache_cookie *);
62895
62896@@ -157,101 +157,101 @@ extern void fscache_proc_cleanup(void);
62897 * stats.c
62898 */
62899 #ifdef CONFIG_FSCACHE_STATS
62900-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62901-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62902+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62903+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62904
62905-extern atomic_t fscache_n_op_pend;
62906-extern atomic_t fscache_n_op_run;
62907-extern atomic_t fscache_n_op_enqueue;
62908-extern atomic_t fscache_n_op_deferred_release;
62909-extern atomic_t fscache_n_op_release;
62910-extern atomic_t fscache_n_op_gc;
62911-extern atomic_t fscache_n_op_cancelled;
62912-extern atomic_t fscache_n_op_rejected;
62913+extern atomic_unchecked_t fscache_n_op_pend;
62914+extern atomic_unchecked_t fscache_n_op_run;
62915+extern atomic_unchecked_t fscache_n_op_enqueue;
62916+extern atomic_unchecked_t fscache_n_op_deferred_release;
62917+extern atomic_unchecked_t fscache_n_op_release;
62918+extern atomic_unchecked_t fscache_n_op_gc;
62919+extern atomic_unchecked_t fscache_n_op_cancelled;
62920+extern atomic_unchecked_t fscache_n_op_rejected;
62921
62922-extern atomic_t fscache_n_attr_changed;
62923-extern atomic_t fscache_n_attr_changed_ok;
62924-extern atomic_t fscache_n_attr_changed_nobufs;
62925-extern atomic_t fscache_n_attr_changed_nomem;
62926-extern atomic_t fscache_n_attr_changed_calls;
62927+extern atomic_unchecked_t fscache_n_attr_changed;
62928+extern atomic_unchecked_t fscache_n_attr_changed_ok;
62929+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
62930+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
62931+extern atomic_unchecked_t fscache_n_attr_changed_calls;
62932
62933-extern atomic_t fscache_n_allocs;
62934-extern atomic_t fscache_n_allocs_ok;
62935-extern atomic_t fscache_n_allocs_wait;
62936-extern atomic_t fscache_n_allocs_nobufs;
62937-extern atomic_t fscache_n_allocs_intr;
62938-extern atomic_t fscache_n_allocs_object_dead;
62939-extern atomic_t fscache_n_alloc_ops;
62940-extern atomic_t fscache_n_alloc_op_waits;
62941+extern atomic_unchecked_t fscache_n_allocs;
62942+extern atomic_unchecked_t fscache_n_allocs_ok;
62943+extern atomic_unchecked_t fscache_n_allocs_wait;
62944+extern atomic_unchecked_t fscache_n_allocs_nobufs;
62945+extern atomic_unchecked_t fscache_n_allocs_intr;
62946+extern atomic_unchecked_t fscache_n_allocs_object_dead;
62947+extern atomic_unchecked_t fscache_n_alloc_ops;
62948+extern atomic_unchecked_t fscache_n_alloc_op_waits;
62949
62950-extern atomic_t fscache_n_retrievals;
62951-extern atomic_t fscache_n_retrievals_ok;
62952-extern atomic_t fscache_n_retrievals_wait;
62953-extern atomic_t fscache_n_retrievals_nodata;
62954-extern atomic_t fscache_n_retrievals_nobufs;
62955-extern atomic_t fscache_n_retrievals_intr;
62956-extern atomic_t fscache_n_retrievals_nomem;
62957-extern atomic_t fscache_n_retrievals_object_dead;
62958-extern atomic_t fscache_n_retrieval_ops;
62959-extern atomic_t fscache_n_retrieval_op_waits;
62960+extern atomic_unchecked_t fscache_n_retrievals;
62961+extern atomic_unchecked_t fscache_n_retrievals_ok;
62962+extern atomic_unchecked_t fscache_n_retrievals_wait;
62963+extern atomic_unchecked_t fscache_n_retrievals_nodata;
62964+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
62965+extern atomic_unchecked_t fscache_n_retrievals_intr;
62966+extern atomic_unchecked_t fscache_n_retrievals_nomem;
62967+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
62968+extern atomic_unchecked_t fscache_n_retrieval_ops;
62969+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
62970
62971-extern atomic_t fscache_n_stores;
62972-extern atomic_t fscache_n_stores_ok;
62973-extern atomic_t fscache_n_stores_again;
62974-extern atomic_t fscache_n_stores_nobufs;
62975-extern atomic_t fscache_n_stores_oom;
62976-extern atomic_t fscache_n_store_ops;
62977-extern atomic_t fscache_n_store_calls;
62978-extern atomic_t fscache_n_store_pages;
62979-extern atomic_t fscache_n_store_radix_deletes;
62980-extern atomic_t fscache_n_store_pages_over_limit;
62981+extern atomic_unchecked_t fscache_n_stores;
62982+extern atomic_unchecked_t fscache_n_stores_ok;
62983+extern atomic_unchecked_t fscache_n_stores_again;
62984+extern atomic_unchecked_t fscache_n_stores_nobufs;
62985+extern atomic_unchecked_t fscache_n_stores_oom;
62986+extern atomic_unchecked_t fscache_n_store_ops;
62987+extern atomic_unchecked_t fscache_n_store_calls;
62988+extern atomic_unchecked_t fscache_n_store_pages;
62989+extern atomic_unchecked_t fscache_n_store_radix_deletes;
62990+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
62991
62992-extern atomic_t fscache_n_store_vmscan_not_storing;
62993-extern atomic_t fscache_n_store_vmscan_gone;
62994-extern atomic_t fscache_n_store_vmscan_busy;
62995-extern atomic_t fscache_n_store_vmscan_cancelled;
62996-extern atomic_t fscache_n_store_vmscan_wait;
62997+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
62998+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
62999+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
63000+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
63001+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
63002
63003-extern atomic_t fscache_n_marks;
63004-extern atomic_t fscache_n_uncaches;
63005+extern atomic_unchecked_t fscache_n_marks;
63006+extern atomic_unchecked_t fscache_n_uncaches;
63007
63008-extern atomic_t fscache_n_acquires;
63009-extern atomic_t fscache_n_acquires_null;
63010-extern atomic_t fscache_n_acquires_no_cache;
63011-extern atomic_t fscache_n_acquires_ok;
63012-extern atomic_t fscache_n_acquires_nobufs;
63013-extern atomic_t fscache_n_acquires_oom;
63014+extern atomic_unchecked_t fscache_n_acquires;
63015+extern atomic_unchecked_t fscache_n_acquires_null;
63016+extern atomic_unchecked_t fscache_n_acquires_no_cache;
63017+extern atomic_unchecked_t fscache_n_acquires_ok;
63018+extern atomic_unchecked_t fscache_n_acquires_nobufs;
63019+extern atomic_unchecked_t fscache_n_acquires_oom;
63020
63021-extern atomic_t fscache_n_invalidates;
63022-extern atomic_t fscache_n_invalidates_run;
63023+extern atomic_unchecked_t fscache_n_invalidates;
63024+extern atomic_unchecked_t fscache_n_invalidates_run;
63025
63026-extern atomic_t fscache_n_updates;
63027-extern atomic_t fscache_n_updates_null;
63028-extern atomic_t fscache_n_updates_run;
63029+extern atomic_unchecked_t fscache_n_updates;
63030+extern atomic_unchecked_t fscache_n_updates_null;
63031+extern atomic_unchecked_t fscache_n_updates_run;
63032
63033-extern atomic_t fscache_n_relinquishes;
63034-extern atomic_t fscache_n_relinquishes_null;
63035-extern atomic_t fscache_n_relinquishes_waitcrt;
63036-extern atomic_t fscache_n_relinquishes_retire;
63037+extern atomic_unchecked_t fscache_n_relinquishes;
63038+extern atomic_unchecked_t fscache_n_relinquishes_null;
63039+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
63040+extern atomic_unchecked_t fscache_n_relinquishes_retire;
63041
63042-extern atomic_t fscache_n_cookie_index;
63043-extern atomic_t fscache_n_cookie_data;
63044-extern atomic_t fscache_n_cookie_special;
63045+extern atomic_unchecked_t fscache_n_cookie_index;
63046+extern atomic_unchecked_t fscache_n_cookie_data;
63047+extern atomic_unchecked_t fscache_n_cookie_special;
63048
63049-extern atomic_t fscache_n_object_alloc;
63050-extern atomic_t fscache_n_object_no_alloc;
63051-extern atomic_t fscache_n_object_lookups;
63052-extern atomic_t fscache_n_object_lookups_negative;
63053-extern atomic_t fscache_n_object_lookups_positive;
63054-extern atomic_t fscache_n_object_lookups_timed_out;
63055-extern atomic_t fscache_n_object_created;
63056-extern atomic_t fscache_n_object_avail;
63057-extern atomic_t fscache_n_object_dead;
63058+extern atomic_unchecked_t fscache_n_object_alloc;
63059+extern atomic_unchecked_t fscache_n_object_no_alloc;
63060+extern atomic_unchecked_t fscache_n_object_lookups;
63061+extern atomic_unchecked_t fscache_n_object_lookups_negative;
63062+extern atomic_unchecked_t fscache_n_object_lookups_positive;
63063+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
63064+extern atomic_unchecked_t fscache_n_object_created;
63065+extern atomic_unchecked_t fscache_n_object_avail;
63066+extern atomic_unchecked_t fscache_n_object_dead;
63067
63068-extern atomic_t fscache_n_checkaux_none;
63069-extern atomic_t fscache_n_checkaux_okay;
63070-extern atomic_t fscache_n_checkaux_update;
63071-extern atomic_t fscache_n_checkaux_obsolete;
63072+extern atomic_unchecked_t fscache_n_checkaux_none;
63073+extern atomic_unchecked_t fscache_n_checkaux_okay;
63074+extern atomic_unchecked_t fscache_n_checkaux_update;
63075+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
63076
63077 extern atomic_t fscache_n_cop_alloc_object;
63078 extern atomic_t fscache_n_cop_lookup_object;
63079@@ -276,6 +276,11 @@ static inline void fscache_stat(atomic_t *stat)
63080 atomic_inc(stat);
63081 }
63082
63083+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
63084+{
63085+ atomic_inc_unchecked(stat);
63086+}
63087+
63088 static inline void fscache_stat_d(atomic_t *stat)
63089 {
63090 atomic_dec(stat);
63091@@ -288,6 +293,7 @@ extern const struct file_operations fscache_stats_fops;
63092
63093 #define __fscache_stat(stat) (NULL)
63094 #define fscache_stat(stat) do {} while (0)
63095+#define fscache_stat_unchecked(stat) do {} while (0)
63096 #define fscache_stat_d(stat) do {} while (0)
63097 #endif
63098
63099diff --git a/fs/fscache/object.c b/fs/fscache/object.c
63100index da032da..0076ce7 100644
63101--- a/fs/fscache/object.c
63102+++ b/fs/fscache/object.c
63103@@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
63104 _debug("LOOKUP \"%s\" in \"%s\"",
63105 cookie->def->name, object->cache->tag->name);
63106
63107- fscache_stat(&fscache_n_object_lookups);
63108+ fscache_stat_unchecked(&fscache_n_object_lookups);
63109 fscache_stat(&fscache_n_cop_lookup_object);
63110 ret = object->cache->ops->lookup_object(object);
63111 fscache_stat_d(&fscache_n_cop_lookup_object);
63112@@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
63113 if (ret == -ETIMEDOUT) {
63114 /* probably stuck behind another object, so move this one to
63115 * the back of the queue */
63116- fscache_stat(&fscache_n_object_lookups_timed_out);
63117+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
63118 _leave(" [timeout]");
63119 return NO_TRANSIT;
63120 }
63121@@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
63122 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
63123
63124 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
63125- fscache_stat(&fscache_n_object_lookups_negative);
63126+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
63127
63128 /* Allow write requests to begin stacking up and read requests to begin
63129 * returning ENODATA.
63130@@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
63131 /* if we were still looking up, then we must have a positive lookup
63132 * result, in which case there may be data available */
63133 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
63134- fscache_stat(&fscache_n_object_lookups_positive);
63135+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
63136
63137 /* We do (presumably) have data */
63138 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
63139@@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
63140 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
63141 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
63142 } else {
63143- fscache_stat(&fscache_n_object_created);
63144+ fscache_stat_unchecked(&fscache_n_object_created);
63145 }
63146
63147 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
63148@@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
63149 fscache_stat_d(&fscache_n_cop_lookup_complete);
63150
63151 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
63152- fscache_stat(&fscache_n_object_avail);
63153+ fscache_stat_unchecked(&fscache_n_object_avail);
63154
63155 _leave("");
63156 return transit_to(JUMPSTART_DEPS);
63157@@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
63158
63159 /* this just shifts the object release to the work processor */
63160 fscache_put_object(object);
63161- fscache_stat(&fscache_n_object_dead);
63162+ fscache_stat_unchecked(&fscache_n_object_dead);
63163
63164 _leave("");
63165 return transit_to(OBJECT_DEAD);
63166@@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
63167 enum fscache_checkaux result;
63168
63169 if (!object->cookie->def->check_aux) {
63170- fscache_stat(&fscache_n_checkaux_none);
63171+ fscache_stat_unchecked(&fscache_n_checkaux_none);
63172 return FSCACHE_CHECKAUX_OKAY;
63173 }
63174
63175@@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
63176 switch (result) {
63177 /* entry okay as is */
63178 case FSCACHE_CHECKAUX_OKAY:
63179- fscache_stat(&fscache_n_checkaux_okay);
63180+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
63181 break;
63182
63183 /* entry requires update */
63184 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
63185- fscache_stat(&fscache_n_checkaux_update);
63186+ fscache_stat_unchecked(&fscache_n_checkaux_update);
63187 break;
63188
63189 /* entry requires deletion */
63190 case FSCACHE_CHECKAUX_OBSOLETE:
63191- fscache_stat(&fscache_n_checkaux_obsolete);
63192+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
63193 break;
63194
63195 default:
63196@@ -993,7 +993,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
63197 {
63198 const struct fscache_state *s;
63199
63200- fscache_stat(&fscache_n_invalidates_run);
63201+ fscache_stat_unchecked(&fscache_n_invalidates_run);
63202 fscache_stat(&fscache_n_cop_invalidate_object);
63203 s = _fscache_invalidate_object(object, event);
63204 fscache_stat_d(&fscache_n_cop_invalidate_object);
63205@@ -1008,7 +1008,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
63206 {
63207 _enter("{OBJ%x},%d", object->debug_id, event);
63208
63209- fscache_stat(&fscache_n_updates_run);
63210+ fscache_stat_unchecked(&fscache_n_updates_run);
63211 fscache_stat(&fscache_n_cop_update_object);
63212 object->cache->ops->update_object(object);
63213 fscache_stat_d(&fscache_n_cop_update_object);
63214diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
63215index e7b87a0..a85d47a 100644
63216--- a/fs/fscache/operation.c
63217+++ b/fs/fscache/operation.c
63218@@ -17,7 +17,7 @@
63219 #include <linux/slab.h>
63220 #include "internal.h"
63221
63222-atomic_t fscache_op_debug_id;
63223+atomic_unchecked_t fscache_op_debug_id;
63224 EXPORT_SYMBOL(fscache_op_debug_id);
63225
63226 /**
63227@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
63228 ASSERTCMP(atomic_read(&op->usage), >, 0);
63229 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
63230
63231- fscache_stat(&fscache_n_op_enqueue);
63232+ fscache_stat_unchecked(&fscache_n_op_enqueue);
63233 switch (op->flags & FSCACHE_OP_TYPE) {
63234 case FSCACHE_OP_ASYNC:
63235 _debug("queue async");
63236@@ -72,7 +72,7 @@ static void fscache_run_op(struct fscache_object *object,
63237 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
63238 if (op->processor)
63239 fscache_enqueue_operation(op);
63240- fscache_stat(&fscache_n_op_run);
63241+ fscache_stat_unchecked(&fscache_n_op_run);
63242 }
63243
63244 /*
63245@@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
63246 if (object->n_in_progress > 0) {
63247 atomic_inc(&op->usage);
63248 list_add_tail(&op->pend_link, &object->pending_ops);
63249- fscache_stat(&fscache_n_op_pend);
63250+ fscache_stat_unchecked(&fscache_n_op_pend);
63251 } else if (!list_empty(&object->pending_ops)) {
63252 atomic_inc(&op->usage);
63253 list_add_tail(&op->pend_link, &object->pending_ops);
63254- fscache_stat(&fscache_n_op_pend);
63255+ fscache_stat_unchecked(&fscache_n_op_pend);
63256 fscache_start_operations(object);
63257 } else {
63258 ASSERTCMP(object->n_in_progress, ==, 0);
63259@@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
63260 object->n_exclusive++; /* reads and writes must wait */
63261 atomic_inc(&op->usage);
63262 list_add_tail(&op->pend_link, &object->pending_ops);
63263- fscache_stat(&fscache_n_op_pend);
63264+ fscache_stat_unchecked(&fscache_n_op_pend);
63265 ret = 0;
63266 } else {
63267 /* If we're in any other state, there must have been an I/O
63268@@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_object *object,
63269 if (object->n_exclusive > 0) {
63270 atomic_inc(&op->usage);
63271 list_add_tail(&op->pend_link, &object->pending_ops);
63272- fscache_stat(&fscache_n_op_pend);
63273+ fscache_stat_unchecked(&fscache_n_op_pend);
63274 } else if (!list_empty(&object->pending_ops)) {
63275 atomic_inc(&op->usage);
63276 list_add_tail(&op->pend_link, &object->pending_ops);
63277- fscache_stat(&fscache_n_op_pend);
63278+ fscache_stat_unchecked(&fscache_n_op_pend);
63279 fscache_start_operations(object);
63280 } else {
63281 ASSERTCMP(object->n_exclusive, ==, 0);
63282@@ -227,10 +227,10 @@ int fscache_submit_op(struct fscache_object *object,
63283 object->n_ops++;
63284 atomic_inc(&op->usage);
63285 list_add_tail(&op->pend_link, &object->pending_ops);
63286- fscache_stat(&fscache_n_op_pend);
63287+ fscache_stat_unchecked(&fscache_n_op_pend);
63288 ret = 0;
63289 } else if (fscache_object_is_dying(object)) {
63290- fscache_stat(&fscache_n_op_rejected);
63291+ fscache_stat_unchecked(&fscache_n_op_rejected);
63292 op->state = FSCACHE_OP_ST_CANCELLED;
63293 ret = -ENOBUFS;
63294 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
63295@@ -309,7 +309,7 @@ int fscache_cancel_op(struct fscache_operation *op,
63296 ret = -EBUSY;
63297 if (op->state == FSCACHE_OP_ST_PENDING) {
63298 ASSERT(!list_empty(&op->pend_link));
63299- fscache_stat(&fscache_n_op_cancelled);
63300+ fscache_stat_unchecked(&fscache_n_op_cancelled);
63301 list_del_init(&op->pend_link);
63302 if (do_cancel)
63303 do_cancel(op);
63304@@ -341,7 +341,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
63305 while (!list_empty(&object->pending_ops)) {
63306 op = list_entry(object->pending_ops.next,
63307 struct fscache_operation, pend_link);
63308- fscache_stat(&fscache_n_op_cancelled);
63309+ fscache_stat_unchecked(&fscache_n_op_cancelled);
63310 list_del_init(&op->pend_link);
63311
63312 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
63313@@ -413,7 +413,7 @@ void fscache_put_operation(struct fscache_operation *op)
63314 op->state, ==, FSCACHE_OP_ST_CANCELLED);
63315 op->state = FSCACHE_OP_ST_DEAD;
63316
63317- fscache_stat(&fscache_n_op_release);
63318+ fscache_stat_unchecked(&fscache_n_op_release);
63319
63320 if (op->release) {
63321 op->release(op);
63322@@ -432,7 +432,7 @@ void fscache_put_operation(struct fscache_operation *op)
63323 * lock, and defer it otherwise */
63324 if (!spin_trylock(&object->lock)) {
63325 _debug("defer put");
63326- fscache_stat(&fscache_n_op_deferred_release);
63327+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
63328
63329 cache = object->cache;
63330 spin_lock(&cache->op_gc_list_lock);
63331@@ -485,7 +485,7 @@ void fscache_operation_gc(struct work_struct *work)
63332
63333 _debug("GC DEFERRED REL OBJ%x OP%x",
63334 object->debug_id, op->debug_id);
63335- fscache_stat(&fscache_n_op_gc);
63336+ fscache_stat_unchecked(&fscache_n_op_gc);
63337
63338 ASSERTCMP(atomic_read(&op->usage), ==, 0);
63339 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
63340diff --git a/fs/fscache/page.c b/fs/fscache/page.c
63341index de33b3f..8be4d29 100644
63342--- a/fs/fscache/page.c
63343+++ b/fs/fscache/page.c
63344@@ -74,7 +74,7 @@ try_again:
63345 val = radix_tree_lookup(&cookie->stores, page->index);
63346 if (!val) {
63347 rcu_read_unlock();
63348- fscache_stat(&fscache_n_store_vmscan_not_storing);
63349+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
63350 __fscache_uncache_page(cookie, page);
63351 return true;
63352 }
63353@@ -104,11 +104,11 @@ try_again:
63354 spin_unlock(&cookie->stores_lock);
63355
63356 if (xpage) {
63357- fscache_stat(&fscache_n_store_vmscan_cancelled);
63358- fscache_stat(&fscache_n_store_radix_deletes);
63359+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
63360+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
63361 ASSERTCMP(xpage, ==, page);
63362 } else {
63363- fscache_stat(&fscache_n_store_vmscan_gone);
63364+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
63365 }
63366
63367 wake_up_bit(&cookie->flags, 0);
63368@@ -123,11 +123,11 @@ page_busy:
63369 * sleeping on memory allocation, so we may need to impose a timeout
63370 * too. */
63371 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
63372- fscache_stat(&fscache_n_store_vmscan_busy);
63373+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
63374 return false;
63375 }
63376
63377- fscache_stat(&fscache_n_store_vmscan_wait);
63378+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
63379 if (!release_page_wait_timeout(cookie, page))
63380 _debug("fscache writeout timeout page: %p{%lx}",
63381 page, page->index);
63382@@ -156,7 +156,7 @@ static void fscache_end_page_write(struct fscache_object *object,
63383 FSCACHE_COOKIE_STORING_TAG);
63384 if (!radix_tree_tag_get(&cookie->stores, page->index,
63385 FSCACHE_COOKIE_PENDING_TAG)) {
63386- fscache_stat(&fscache_n_store_radix_deletes);
63387+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
63388 xpage = radix_tree_delete(&cookie->stores, page->index);
63389 }
63390 spin_unlock(&cookie->stores_lock);
63391@@ -177,7 +177,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
63392
63393 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
63394
63395- fscache_stat(&fscache_n_attr_changed_calls);
63396+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
63397
63398 if (fscache_object_is_active(object)) {
63399 fscache_stat(&fscache_n_cop_attr_changed);
63400@@ -204,11 +204,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63401
63402 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63403
63404- fscache_stat(&fscache_n_attr_changed);
63405+ fscache_stat_unchecked(&fscache_n_attr_changed);
63406
63407 op = kzalloc(sizeof(*op), GFP_KERNEL);
63408 if (!op) {
63409- fscache_stat(&fscache_n_attr_changed_nomem);
63410+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
63411 _leave(" = -ENOMEM");
63412 return -ENOMEM;
63413 }
63414@@ -230,7 +230,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63415 if (fscache_submit_exclusive_op(object, op) < 0)
63416 goto nobufs_dec;
63417 spin_unlock(&cookie->lock);
63418- fscache_stat(&fscache_n_attr_changed_ok);
63419+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
63420 fscache_put_operation(op);
63421 _leave(" = 0");
63422 return 0;
63423@@ -242,7 +242,7 @@ nobufs:
63424 kfree(op);
63425 if (wake_cookie)
63426 __fscache_wake_unused_cookie(cookie);
63427- fscache_stat(&fscache_n_attr_changed_nobufs);
63428+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
63429 _leave(" = %d", -ENOBUFS);
63430 return -ENOBUFS;
63431 }
63432@@ -281,7 +281,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
63433 /* allocate a retrieval operation and attempt to submit it */
63434 op = kzalloc(sizeof(*op), GFP_NOIO);
63435 if (!op) {
63436- fscache_stat(&fscache_n_retrievals_nomem);
63437+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63438 return NULL;
63439 }
63440
63441@@ -311,12 +311,12 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
63442 return 0;
63443 }
63444
63445- fscache_stat(&fscache_n_retrievals_wait);
63446+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
63447
63448 jif = jiffies;
63449 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
63450 TASK_INTERRUPTIBLE) != 0) {
63451- fscache_stat(&fscache_n_retrievals_intr);
63452+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
63453 _leave(" = -ERESTARTSYS");
63454 return -ERESTARTSYS;
63455 }
63456@@ -345,8 +345,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
63457 */
63458 int fscache_wait_for_operation_activation(struct fscache_object *object,
63459 struct fscache_operation *op,
63460- atomic_t *stat_op_waits,
63461- atomic_t *stat_object_dead,
63462+ atomic_unchecked_t *stat_op_waits,
63463+ atomic_unchecked_t *stat_object_dead,
63464 void (*do_cancel)(struct fscache_operation *))
63465 {
63466 int ret;
63467@@ -356,7 +356,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63468
63469 _debug(">>> WT");
63470 if (stat_op_waits)
63471- fscache_stat(stat_op_waits);
63472+ fscache_stat_unchecked(stat_op_waits);
63473 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
63474 TASK_INTERRUPTIBLE) != 0) {
63475 ret = fscache_cancel_op(op, do_cancel);
63476@@ -373,7 +373,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63477 check_if_dead:
63478 if (op->state == FSCACHE_OP_ST_CANCELLED) {
63479 if (stat_object_dead)
63480- fscache_stat(stat_object_dead);
63481+ fscache_stat_unchecked(stat_object_dead);
63482 _leave(" = -ENOBUFS [cancelled]");
63483 return -ENOBUFS;
63484 }
63485@@ -381,7 +381,7 @@ check_if_dead:
63486 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
63487 fscache_cancel_op(op, do_cancel);
63488 if (stat_object_dead)
63489- fscache_stat(stat_object_dead);
63490+ fscache_stat_unchecked(stat_object_dead);
63491 return -ENOBUFS;
63492 }
63493 return 0;
63494@@ -409,7 +409,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63495
63496 _enter("%p,%p,,,", cookie, page);
63497
63498- fscache_stat(&fscache_n_retrievals);
63499+ fscache_stat_unchecked(&fscache_n_retrievals);
63500
63501 if (hlist_empty(&cookie->backing_objects))
63502 goto nobufs;
63503@@ -451,7 +451,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63504 goto nobufs_unlock_dec;
63505 spin_unlock(&cookie->lock);
63506
63507- fscache_stat(&fscache_n_retrieval_ops);
63508+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
63509
63510 /* pin the netfs read context in case we need to do the actual netfs
63511 * read because we've encountered a cache read failure */
63512@@ -482,15 +482,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63513
63514 error:
63515 if (ret == -ENOMEM)
63516- fscache_stat(&fscache_n_retrievals_nomem);
63517+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63518 else if (ret == -ERESTARTSYS)
63519- fscache_stat(&fscache_n_retrievals_intr);
63520+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
63521 else if (ret == -ENODATA)
63522- fscache_stat(&fscache_n_retrievals_nodata);
63523+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63524 else if (ret < 0)
63525- fscache_stat(&fscache_n_retrievals_nobufs);
63526+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63527 else
63528- fscache_stat(&fscache_n_retrievals_ok);
63529+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
63530
63531 fscache_put_retrieval(op);
63532 _leave(" = %d", ret);
63533@@ -505,7 +505,7 @@ nobufs_unlock:
63534 __fscache_wake_unused_cookie(cookie);
63535 kfree(op);
63536 nobufs:
63537- fscache_stat(&fscache_n_retrievals_nobufs);
63538+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63539 _leave(" = -ENOBUFS");
63540 return -ENOBUFS;
63541 }
63542@@ -544,7 +544,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63543
63544 _enter("%p,,%d,,,", cookie, *nr_pages);
63545
63546- fscache_stat(&fscache_n_retrievals);
63547+ fscache_stat_unchecked(&fscache_n_retrievals);
63548
63549 if (hlist_empty(&cookie->backing_objects))
63550 goto nobufs;
63551@@ -582,7 +582,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63552 goto nobufs_unlock_dec;
63553 spin_unlock(&cookie->lock);
63554
63555- fscache_stat(&fscache_n_retrieval_ops);
63556+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
63557
63558 /* pin the netfs read context in case we need to do the actual netfs
63559 * read because we've encountered a cache read failure */
63560@@ -613,15 +613,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63561
63562 error:
63563 if (ret == -ENOMEM)
63564- fscache_stat(&fscache_n_retrievals_nomem);
63565+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63566 else if (ret == -ERESTARTSYS)
63567- fscache_stat(&fscache_n_retrievals_intr);
63568+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
63569 else if (ret == -ENODATA)
63570- fscache_stat(&fscache_n_retrievals_nodata);
63571+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63572 else if (ret < 0)
63573- fscache_stat(&fscache_n_retrievals_nobufs);
63574+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63575 else
63576- fscache_stat(&fscache_n_retrievals_ok);
63577+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
63578
63579 fscache_put_retrieval(op);
63580 _leave(" = %d", ret);
63581@@ -636,7 +636,7 @@ nobufs_unlock:
63582 if (wake_cookie)
63583 __fscache_wake_unused_cookie(cookie);
63584 nobufs:
63585- fscache_stat(&fscache_n_retrievals_nobufs);
63586+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63587 _leave(" = -ENOBUFS");
63588 return -ENOBUFS;
63589 }
63590@@ -661,7 +661,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63591
63592 _enter("%p,%p,,,", cookie, page);
63593
63594- fscache_stat(&fscache_n_allocs);
63595+ fscache_stat_unchecked(&fscache_n_allocs);
63596
63597 if (hlist_empty(&cookie->backing_objects))
63598 goto nobufs;
63599@@ -695,7 +695,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63600 goto nobufs_unlock_dec;
63601 spin_unlock(&cookie->lock);
63602
63603- fscache_stat(&fscache_n_alloc_ops);
63604+ fscache_stat_unchecked(&fscache_n_alloc_ops);
63605
63606 ret = fscache_wait_for_operation_activation(
63607 object, &op->op,
63608@@ -712,11 +712,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63609
63610 error:
63611 if (ret == -ERESTARTSYS)
63612- fscache_stat(&fscache_n_allocs_intr);
63613+ fscache_stat_unchecked(&fscache_n_allocs_intr);
63614 else if (ret < 0)
63615- fscache_stat(&fscache_n_allocs_nobufs);
63616+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63617 else
63618- fscache_stat(&fscache_n_allocs_ok);
63619+ fscache_stat_unchecked(&fscache_n_allocs_ok);
63620
63621 fscache_put_retrieval(op);
63622 _leave(" = %d", ret);
63623@@ -730,7 +730,7 @@ nobufs_unlock:
63624 if (wake_cookie)
63625 __fscache_wake_unused_cookie(cookie);
63626 nobufs:
63627- fscache_stat(&fscache_n_allocs_nobufs);
63628+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63629 _leave(" = -ENOBUFS");
63630 return -ENOBUFS;
63631 }
63632@@ -806,7 +806,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63633
63634 spin_lock(&cookie->stores_lock);
63635
63636- fscache_stat(&fscache_n_store_calls);
63637+ fscache_stat_unchecked(&fscache_n_store_calls);
63638
63639 /* find a page to store */
63640 page = NULL;
63641@@ -817,7 +817,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63642 page = results[0];
63643 _debug("gang %d [%lx]", n, page->index);
63644 if (page->index > op->store_limit) {
63645- fscache_stat(&fscache_n_store_pages_over_limit);
63646+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
63647 goto superseded;
63648 }
63649
63650@@ -829,7 +829,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63651 spin_unlock(&cookie->stores_lock);
63652 spin_unlock(&object->lock);
63653
63654- fscache_stat(&fscache_n_store_pages);
63655+ fscache_stat_unchecked(&fscache_n_store_pages);
63656 fscache_stat(&fscache_n_cop_write_page);
63657 ret = object->cache->ops->write_page(op, page);
63658 fscache_stat_d(&fscache_n_cop_write_page);
63659@@ -933,7 +933,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63660 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63661 ASSERT(PageFsCache(page));
63662
63663- fscache_stat(&fscache_n_stores);
63664+ fscache_stat_unchecked(&fscache_n_stores);
63665
63666 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
63667 _leave(" = -ENOBUFS [invalidating]");
63668@@ -992,7 +992,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63669 spin_unlock(&cookie->stores_lock);
63670 spin_unlock(&object->lock);
63671
63672- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
63673+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63674 op->store_limit = object->store_limit;
63675
63676 __fscache_use_cookie(cookie);
63677@@ -1001,8 +1001,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63678
63679 spin_unlock(&cookie->lock);
63680 radix_tree_preload_end();
63681- fscache_stat(&fscache_n_store_ops);
63682- fscache_stat(&fscache_n_stores_ok);
63683+ fscache_stat_unchecked(&fscache_n_store_ops);
63684+ fscache_stat_unchecked(&fscache_n_stores_ok);
63685
63686 /* the work queue now carries its own ref on the object */
63687 fscache_put_operation(&op->op);
63688@@ -1010,14 +1010,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63689 return 0;
63690
63691 already_queued:
63692- fscache_stat(&fscache_n_stores_again);
63693+ fscache_stat_unchecked(&fscache_n_stores_again);
63694 already_pending:
63695 spin_unlock(&cookie->stores_lock);
63696 spin_unlock(&object->lock);
63697 spin_unlock(&cookie->lock);
63698 radix_tree_preload_end();
63699 kfree(op);
63700- fscache_stat(&fscache_n_stores_ok);
63701+ fscache_stat_unchecked(&fscache_n_stores_ok);
63702 _leave(" = 0");
63703 return 0;
63704
63705@@ -1039,14 +1039,14 @@ nobufs:
63706 kfree(op);
63707 if (wake_cookie)
63708 __fscache_wake_unused_cookie(cookie);
63709- fscache_stat(&fscache_n_stores_nobufs);
63710+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
63711 _leave(" = -ENOBUFS");
63712 return -ENOBUFS;
63713
63714 nomem_free:
63715 kfree(op);
63716 nomem:
63717- fscache_stat(&fscache_n_stores_oom);
63718+ fscache_stat_unchecked(&fscache_n_stores_oom);
63719 _leave(" = -ENOMEM");
63720 return -ENOMEM;
63721 }
63722@@ -1064,7 +1064,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
63723 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63724 ASSERTCMP(page, !=, NULL);
63725
63726- fscache_stat(&fscache_n_uncaches);
63727+ fscache_stat_unchecked(&fscache_n_uncaches);
63728
63729 /* cache withdrawal may beat us to it */
63730 if (!PageFsCache(page))
63731@@ -1115,7 +1115,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
63732 struct fscache_cookie *cookie = op->op.object->cookie;
63733
63734 #ifdef CONFIG_FSCACHE_STATS
63735- atomic_inc(&fscache_n_marks);
63736+ atomic_inc_unchecked(&fscache_n_marks);
63737 #endif
63738
63739 _debug("- mark %p{%lx}", page, page->index);
63740diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
63741index 40d13c7..ddf52b9 100644
63742--- a/fs/fscache/stats.c
63743+++ b/fs/fscache/stats.c
63744@@ -18,99 +18,99 @@
63745 /*
63746 * operation counters
63747 */
63748-atomic_t fscache_n_op_pend;
63749-atomic_t fscache_n_op_run;
63750-atomic_t fscache_n_op_enqueue;
63751-atomic_t fscache_n_op_requeue;
63752-atomic_t fscache_n_op_deferred_release;
63753-atomic_t fscache_n_op_release;
63754-atomic_t fscache_n_op_gc;
63755-atomic_t fscache_n_op_cancelled;
63756-atomic_t fscache_n_op_rejected;
63757+atomic_unchecked_t fscache_n_op_pend;
63758+atomic_unchecked_t fscache_n_op_run;
63759+atomic_unchecked_t fscache_n_op_enqueue;
63760+atomic_unchecked_t fscache_n_op_requeue;
63761+atomic_unchecked_t fscache_n_op_deferred_release;
63762+atomic_unchecked_t fscache_n_op_release;
63763+atomic_unchecked_t fscache_n_op_gc;
63764+atomic_unchecked_t fscache_n_op_cancelled;
63765+atomic_unchecked_t fscache_n_op_rejected;
63766
63767-atomic_t fscache_n_attr_changed;
63768-atomic_t fscache_n_attr_changed_ok;
63769-atomic_t fscache_n_attr_changed_nobufs;
63770-atomic_t fscache_n_attr_changed_nomem;
63771-atomic_t fscache_n_attr_changed_calls;
63772+atomic_unchecked_t fscache_n_attr_changed;
63773+atomic_unchecked_t fscache_n_attr_changed_ok;
63774+atomic_unchecked_t fscache_n_attr_changed_nobufs;
63775+atomic_unchecked_t fscache_n_attr_changed_nomem;
63776+atomic_unchecked_t fscache_n_attr_changed_calls;
63777
63778-atomic_t fscache_n_allocs;
63779-atomic_t fscache_n_allocs_ok;
63780-atomic_t fscache_n_allocs_wait;
63781-atomic_t fscache_n_allocs_nobufs;
63782-atomic_t fscache_n_allocs_intr;
63783-atomic_t fscache_n_allocs_object_dead;
63784-atomic_t fscache_n_alloc_ops;
63785-atomic_t fscache_n_alloc_op_waits;
63786+atomic_unchecked_t fscache_n_allocs;
63787+atomic_unchecked_t fscache_n_allocs_ok;
63788+atomic_unchecked_t fscache_n_allocs_wait;
63789+atomic_unchecked_t fscache_n_allocs_nobufs;
63790+atomic_unchecked_t fscache_n_allocs_intr;
63791+atomic_unchecked_t fscache_n_allocs_object_dead;
63792+atomic_unchecked_t fscache_n_alloc_ops;
63793+atomic_unchecked_t fscache_n_alloc_op_waits;
63794
63795-atomic_t fscache_n_retrievals;
63796-atomic_t fscache_n_retrievals_ok;
63797-atomic_t fscache_n_retrievals_wait;
63798-atomic_t fscache_n_retrievals_nodata;
63799-atomic_t fscache_n_retrievals_nobufs;
63800-atomic_t fscache_n_retrievals_intr;
63801-atomic_t fscache_n_retrievals_nomem;
63802-atomic_t fscache_n_retrievals_object_dead;
63803-atomic_t fscache_n_retrieval_ops;
63804-atomic_t fscache_n_retrieval_op_waits;
63805+atomic_unchecked_t fscache_n_retrievals;
63806+atomic_unchecked_t fscache_n_retrievals_ok;
63807+atomic_unchecked_t fscache_n_retrievals_wait;
63808+atomic_unchecked_t fscache_n_retrievals_nodata;
63809+atomic_unchecked_t fscache_n_retrievals_nobufs;
63810+atomic_unchecked_t fscache_n_retrievals_intr;
63811+atomic_unchecked_t fscache_n_retrievals_nomem;
63812+atomic_unchecked_t fscache_n_retrievals_object_dead;
63813+atomic_unchecked_t fscache_n_retrieval_ops;
63814+atomic_unchecked_t fscache_n_retrieval_op_waits;
63815
63816-atomic_t fscache_n_stores;
63817-atomic_t fscache_n_stores_ok;
63818-atomic_t fscache_n_stores_again;
63819-atomic_t fscache_n_stores_nobufs;
63820-atomic_t fscache_n_stores_oom;
63821-atomic_t fscache_n_store_ops;
63822-atomic_t fscache_n_store_calls;
63823-atomic_t fscache_n_store_pages;
63824-atomic_t fscache_n_store_radix_deletes;
63825-atomic_t fscache_n_store_pages_over_limit;
63826+atomic_unchecked_t fscache_n_stores;
63827+atomic_unchecked_t fscache_n_stores_ok;
63828+atomic_unchecked_t fscache_n_stores_again;
63829+atomic_unchecked_t fscache_n_stores_nobufs;
63830+atomic_unchecked_t fscache_n_stores_oom;
63831+atomic_unchecked_t fscache_n_store_ops;
63832+atomic_unchecked_t fscache_n_store_calls;
63833+atomic_unchecked_t fscache_n_store_pages;
63834+atomic_unchecked_t fscache_n_store_radix_deletes;
63835+atomic_unchecked_t fscache_n_store_pages_over_limit;
63836
63837-atomic_t fscache_n_store_vmscan_not_storing;
63838-atomic_t fscache_n_store_vmscan_gone;
63839-atomic_t fscache_n_store_vmscan_busy;
63840-atomic_t fscache_n_store_vmscan_cancelled;
63841-atomic_t fscache_n_store_vmscan_wait;
63842+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
63843+atomic_unchecked_t fscache_n_store_vmscan_gone;
63844+atomic_unchecked_t fscache_n_store_vmscan_busy;
63845+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
63846+atomic_unchecked_t fscache_n_store_vmscan_wait;
63847
63848-atomic_t fscache_n_marks;
63849-atomic_t fscache_n_uncaches;
63850+atomic_unchecked_t fscache_n_marks;
63851+atomic_unchecked_t fscache_n_uncaches;
63852
63853-atomic_t fscache_n_acquires;
63854-atomic_t fscache_n_acquires_null;
63855-atomic_t fscache_n_acquires_no_cache;
63856-atomic_t fscache_n_acquires_ok;
63857-atomic_t fscache_n_acquires_nobufs;
63858-atomic_t fscache_n_acquires_oom;
63859+atomic_unchecked_t fscache_n_acquires;
63860+atomic_unchecked_t fscache_n_acquires_null;
63861+atomic_unchecked_t fscache_n_acquires_no_cache;
63862+atomic_unchecked_t fscache_n_acquires_ok;
63863+atomic_unchecked_t fscache_n_acquires_nobufs;
63864+atomic_unchecked_t fscache_n_acquires_oom;
63865
63866-atomic_t fscache_n_invalidates;
63867-atomic_t fscache_n_invalidates_run;
63868+atomic_unchecked_t fscache_n_invalidates;
63869+atomic_unchecked_t fscache_n_invalidates_run;
63870
63871-atomic_t fscache_n_updates;
63872-atomic_t fscache_n_updates_null;
63873-atomic_t fscache_n_updates_run;
63874+atomic_unchecked_t fscache_n_updates;
63875+atomic_unchecked_t fscache_n_updates_null;
63876+atomic_unchecked_t fscache_n_updates_run;
63877
63878-atomic_t fscache_n_relinquishes;
63879-atomic_t fscache_n_relinquishes_null;
63880-atomic_t fscache_n_relinquishes_waitcrt;
63881-atomic_t fscache_n_relinquishes_retire;
63882+atomic_unchecked_t fscache_n_relinquishes;
63883+atomic_unchecked_t fscache_n_relinquishes_null;
63884+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
63885+atomic_unchecked_t fscache_n_relinquishes_retire;
63886
63887-atomic_t fscache_n_cookie_index;
63888-atomic_t fscache_n_cookie_data;
63889-atomic_t fscache_n_cookie_special;
63890+atomic_unchecked_t fscache_n_cookie_index;
63891+atomic_unchecked_t fscache_n_cookie_data;
63892+atomic_unchecked_t fscache_n_cookie_special;
63893
63894-atomic_t fscache_n_object_alloc;
63895-atomic_t fscache_n_object_no_alloc;
63896-atomic_t fscache_n_object_lookups;
63897-atomic_t fscache_n_object_lookups_negative;
63898-atomic_t fscache_n_object_lookups_positive;
63899-atomic_t fscache_n_object_lookups_timed_out;
63900-atomic_t fscache_n_object_created;
63901-atomic_t fscache_n_object_avail;
63902-atomic_t fscache_n_object_dead;
63903+atomic_unchecked_t fscache_n_object_alloc;
63904+atomic_unchecked_t fscache_n_object_no_alloc;
63905+atomic_unchecked_t fscache_n_object_lookups;
63906+atomic_unchecked_t fscache_n_object_lookups_negative;
63907+atomic_unchecked_t fscache_n_object_lookups_positive;
63908+atomic_unchecked_t fscache_n_object_lookups_timed_out;
63909+atomic_unchecked_t fscache_n_object_created;
63910+atomic_unchecked_t fscache_n_object_avail;
63911+atomic_unchecked_t fscache_n_object_dead;
63912
63913-atomic_t fscache_n_checkaux_none;
63914-atomic_t fscache_n_checkaux_okay;
63915-atomic_t fscache_n_checkaux_update;
63916-atomic_t fscache_n_checkaux_obsolete;
63917+atomic_unchecked_t fscache_n_checkaux_none;
63918+atomic_unchecked_t fscache_n_checkaux_okay;
63919+atomic_unchecked_t fscache_n_checkaux_update;
63920+atomic_unchecked_t fscache_n_checkaux_obsolete;
63921
63922 atomic_t fscache_n_cop_alloc_object;
63923 atomic_t fscache_n_cop_lookup_object;
63924@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
63925 seq_puts(m, "FS-Cache statistics\n");
63926
63927 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
63928- atomic_read(&fscache_n_cookie_index),
63929- atomic_read(&fscache_n_cookie_data),
63930- atomic_read(&fscache_n_cookie_special));
63931+ atomic_read_unchecked(&fscache_n_cookie_index),
63932+ atomic_read_unchecked(&fscache_n_cookie_data),
63933+ atomic_read_unchecked(&fscache_n_cookie_special));
63934
63935 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
63936- atomic_read(&fscache_n_object_alloc),
63937- atomic_read(&fscache_n_object_no_alloc),
63938- atomic_read(&fscache_n_object_avail),
63939- atomic_read(&fscache_n_object_dead));
63940+ atomic_read_unchecked(&fscache_n_object_alloc),
63941+ atomic_read_unchecked(&fscache_n_object_no_alloc),
63942+ atomic_read_unchecked(&fscache_n_object_avail),
63943+ atomic_read_unchecked(&fscache_n_object_dead));
63944 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
63945- atomic_read(&fscache_n_checkaux_none),
63946- atomic_read(&fscache_n_checkaux_okay),
63947- atomic_read(&fscache_n_checkaux_update),
63948- atomic_read(&fscache_n_checkaux_obsolete));
63949+ atomic_read_unchecked(&fscache_n_checkaux_none),
63950+ atomic_read_unchecked(&fscache_n_checkaux_okay),
63951+ atomic_read_unchecked(&fscache_n_checkaux_update),
63952+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
63953
63954 seq_printf(m, "Pages : mrk=%u unc=%u\n",
63955- atomic_read(&fscache_n_marks),
63956- atomic_read(&fscache_n_uncaches));
63957+ atomic_read_unchecked(&fscache_n_marks),
63958+ atomic_read_unchecked(&fscache_n_uncaches));
63959
63960 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
63961 " oom=%u\n",
63962- atomic_read(&fscache_n_acquires),
63963- atomic_read(&fscache_n_acquires_null),
63964- atomic_read(&fscache_n_acquires_no_cache),
63965- atomic_read(&fscache_n_acquires_ok),
63966- atomic_read(&fscache_n_acquires_nobufs),
63967- atomic_read(&fscache_n_acquires_oom));
63968+ atomic_read_unchecked(&fscache_n_acquires),
63969+ atomic_read_unchecked(&fscache_n_acquires_null),
63970+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
63971+ atomic_read_unchecked(&fscache_n_acquires_ok),
63972+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
63973+ atomic_read_unchecked(&fscache_n_acquires_oom));
63974
63975 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
63976- atomic_read(&fscache_n_object_lookups),
63977- atomic_read(&fscache_n_object_lookups_negative),
63978- atomic_read(&fscache_n_object_lookups_positive),
63979- atomic_read(&fscache_n_object_created),
63980- atomic_read(&fscache_n_object_lookups_timed_out));
63981+ atomic_read_unchecked(&fscache_n_object_lookups),
63982+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
63983+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
63984+ atomic_read_unchecked(&fscache_n_object_created),
63985+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
63986
63987 seq_printf(m, "Invals : n=%u run=%u\n",
63988- atomic_read(&fscache_n_invalidates),
63989- atomic_read(&fscache_n_invalidates_run));
63990+ atomic_read_unchecked(&fscache_n_invalidates),
63991+ atomic_read_unchecked(&fscache_n_invalidates_run));
63992
63993 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
63994- atomic_read(&fscache_n_updates),
63995- atomic_read(&fscache_n_updates_null),
63996- atomic_read(&fscache_n_updates_run));
63997+ atomic_read_unchecked(&fscache_n_updates),
63998+ atomic_read_unchecked(&fscache_n_updates_null),
63999+ atomic_read_unchecked(&fscache_n_updates_run));
64000
64001 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
64002- atomic_read(&fscache_n_relinquishes),
64003- atomic_read(&fscache_n_relinquishes_null),
64004- atomic_read(&fscache_n_relinquishes_waitcrt),
64005- atomic_read(&fscache_n_relinquishes_retire));
64006+ atomic_read_unchecked(&fscache_n_relinquishes),
64007+ atomic_read_unchecked(&fscache_n_relinquishes_null),
64008+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
64009+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
64010
64011 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
64012- atomic_read(&fscache_n_attr_changed),
64013- atomic_read(&fscache_n_attr_changed_ok),
64014- atomic_read(&fscache_n_attr_changed_nobufs),
64015- atomic_read(&fscache_n_attr_changed_nomem),
64016- atomic_read(&fscache_n_attr_changed_calls));
64017+ atomic_read_unchecked(&fscache_n_attr_changed),
64018+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
64019+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
64020+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
64021+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
64022
64023 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
64024- atomic_read(&fscache_n_allocs),
64025- atomic_read(&fscache_n_allocs_ok),
64026- atomic_read(&fscache_n_allocs_wait),
64027- atomic_read(&fscache_n_allocs_nobufs),
64028- atomic_read(&fscache_n_allocs_intr));
64029+ atomic_read_unchecked(&fscache_n_allocs),
64030+ atomic_read_unchecked(&fscache_n_allocs_ok),
64031+ atomic_read_unchecked(&fscache_n_allocs_wait),
64032+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
64033+ atomic_read_unchecked(&fscache_n_allocs_intr));
64034 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
64035- atomic_read(&fscache_n_alloc_ops),
64036- atomic_read(&fscache_n_alloc_op_waits),
64037- atomic_read(&fscache_n_allocs_object_dead));
64038+ atomic_read_unchecked(&fscache_n_alloc_ops),
64039+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
64040+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
64041
64042 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
64043 " int=%u oom=%u\n",
64044- atomic_read(&fscache_n_retrievals),
64045- atomic_read(&fscache_n_retrievals_ok),
64046- atomic_read(&fscache_n_retrievals_wait),
64047- atomic_read(&fscache_n_retrievals_nodata),
64048- atomic_read(&fscache_n_retrievals_nobufs),
64049- atomic_read(&fscache_n_retrievals_intr),
64050- atomic_read(&fscache_n_retrievals_nomem));
64051+ atomic_read_unchecked(&fscache_n_retrievals),
64052+ atomic_read_unchecked(&fscache_n_retrievals_ok),
64053+ atomic_read_unchecked(&fscache_n_retrievals_wait),
64054+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
64055+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
64056+ atomic_read_unchecked(&fscache_n_retrievals_intr),
64057+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
64058 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
64059- atomic_read(&fscache_n_retrieval_ops),
64060- atomic_read(&fscache_n_retrieval_op_waits),
64061- atomic_read(&fscache_n_retrievals_object_dead));
64062+ atomic_read_unchecked(&fscache_n_retrieval_ops),
64063+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
64064+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
64065
64066 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
64067- atomic_read(&fscache_n_stores),
64068- atomic_read(&fscache_n_stores_ok),
64069- atomic_read(&fscache_n_stores_again),
64070- atomic_read(&fscache_n_stores_nobufs),
64071- atomic_read(&fscache_n_stores_oom));
64072+ atomic_read_unchecked(&fscache_n_stores),
64073+ atomic_read_unchecked(&fscache_n_stores_ok),
64074+ atomic_read_unchecked(&fscache_n_stores_again),
64075+ atomic_read_unchecked(&fscache_n_stores_nobufs),
64076+ atomic_read_unchecked(&fscache_n_stores_oom));
64077 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
64078- atomic_read(&fscache_n_store_ops),
64079- atomic_read(&fscache_n_store_calls),
64080- atomic_read(&fscache_n_store_pages),
64081- atomic_read(&fscache_n_store_radix_deletes),
64082- atomic_read(&fscache_n_store_pages_over_limit));
64083+ atomic_read_unchecked(&fscache_n_store_ops),
64084+ atomic_read_unchecked(&fscache_n_store_calls),
64085+ atomic_read_unchecked(&fscache_n_store_pages),
64086+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
64087+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
64088
64089 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
64090- atomic_read(&fscache_n_store_vmscan_not_storing),
64091- atomic_read(&fscache_n_store_vmscan_gone),
64092- atomic_read(&fscache_n_store_vmscan_busy),
64093- atomic_read(&fscache_n_store_vmscan_cancelled),
64094- atomic_read(&fscache_n_store_vmscan_wait));
64095+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
64096+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
64097+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
64098+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
64099+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
64100
64101 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
64102- atomic_read(&fscache_n_op_pend),
64103- atomic_read(&fscache_n_op_run),
64104- atomic_read(&fscache_n_op_enqueue),
64105- atomic_read(&fscache_n_op_cancelled),
64106- atomic_read(&fscache_n_op_rejected));
64107+ atomic_read_unchecked(&fscache_n_op_pend),
64108+ atomic_read_unchecked(&fscache_n_op_run),
64109+ atomic_read_unchecked(&fscache_n_op_enqueue),
64110+ atomic_read_unchecked(&fscache_n_op_cancelled),
64111+ atomic_read_unchecked(&fscache_n_op_rejected));
64112 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
64113- atomic_read(&fscache_n_op_deferred_release),
64114- atomic_read(&fscache_n_op_release),
64115- atomic_read(&fscache_n_op_gc));
64116+ atomic_read_unchecked(&fscache_n_op_deferred_release),
64117+ atomic_read_unchecked(&fscache_n_op_release),
64118+ atomic_read_unchecked(&fscache_n_op_gc));
64119
64120 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
64121 atomic_read(&fscache_n_cop_alloc_object),
64122diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
64123index 966ace8..030a03a 100644
64124--- a/fs/fuse/cuse.c
64125+++ b/fs/fuse/cuse.c
64126@@ -611,10 +611,12 @@ static int __init cuse_init(void)
64127 INIT_LIST_HEAD(&cuse_conntbl[i]);
64128
64129 /* inherit and extend fuse_dev_operations */
64130- cuse_channel_fops = fuse_dev_operations;
64131- cuse_channel_fops.owner = THIS_MODULE;
64132- cuse_channel_fops.open = cuse_channel_open;
64133- cuse_channel_fops.release = cuse_channel_release;
64134+ pax_open_kernel();
64135+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
64136+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
64137+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
64138+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
64139+ pax_close_kernel();
64140
64141 cuse_class = class_create(THIS_MODULE, "cuse");
64142 if (IS_ERR(cuse_class))
64143diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
64144index ca88731..8e9c55d 100644
64145--- a/fs/fuse/dev.c
64146+++ b/fs/fuse/dev.c
64147@@ -1318,7 +1318,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
64148 ret = 0;
64149 pipe_lock(pipe);
64150
64151- if (!pipe->readers) {
64152+ if (!atomic_read(&pipe->readers)) {
64153 send_sig(SIGPIPE, current, 0);
64154 if (!ret)
64155 ret = -EPIPE;
64156@@ -1347,7 +1347,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
64157 page_nr++;
64158 ret += buf->len;
64159
64160- if (pipe->files)
64161+ if (atomic_read(&pipe->files))
64162 do_wakeup = 1;
64163 }
64164
64165diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
64166index de1d84a..fd69c0c 100644
64167--- a/fs/fuse/dir.c
64168+++ b/fs/fuse/dir.c
64169@@ -1479,7 +1479,7 @@ static char *read_link(struct dentry *dentry)
64170 return link;
64171 }
64172
64173-static void free_link(char *link)
64174+static void free_link(const char *link)
64175 {
64176 if (!IS_ERR(link))
64177 free_page((unsigned long) link);
64178diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
64179index fd62cae..3494dfa 100644
64180--- a/fs/hostfs/hostfs_kern.c
64181+++ b/fs/hostfs/hostfs_kern.c
64182@@ -908,7 +908,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
64183
64184 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
64185 {
64186- char *s = nd_get_link(nd);
64187+ const char *s = nd_get_link(nd);
64188 if (!IS_ERR(s))
64189 __putname(s);
64190 }
64191diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
64192index 1e2872b..7aea000 100644
64193--- a/fs/hugetlbfs/inode.c
64194+++ b/fs/hugetlbfs/inode.c
64195@@ -154,6 +154,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
64196 struct mm_struct *mm = current->mm;
64197 struct vm_area_struct *vma;
64198 struct hstate *h = hstate_file(file);
64199+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
64200 struct vm_unmapped_area_info info;
64201
64202 if (len & ~huge_page_mask(h))
64203@@ -167,17 +168,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
64204 return addr;
64205 }
64206
64207+#ifdef CONFIG_PAX_RANDMMAP
64208+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
64209+#endif
64210+
64211 if (addr) {
64212 addr = ALIGN(addr, huge_page_size(h));
64213 vma = find_vma(mm, addr);
64214- if (TASK_SIZE - len >= addr &&
64215- (!vma || addr + len <= vma->vm_start))
64216+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
64217 return addr;
64218 }
64219
64220 info.flags = 0;
64221 info.length = len;
64222 info.low_limit = TASK_UNMAPPED_BASE;
64223+
64224+#ifdef CONFIG_PAX_RANDMMAP
64225+ if (mm->pax_flags & MF_PAX_RANDMMAP)
64226+ info.low_limit += mm->delta_mmap;
64227+#endif
64228+
64229 info.high_limit = TASK_SIZE;
64230 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
64231 info.align_offset = 0;
64232@@ -919,7 +929,7 @@ static struct file_system_type hugetlbfs_fs_type = {
64233 };
64234 MODULE_ALIAS_FS("hugetlbfs");
64235
64236-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
64237+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
64238
64239 static int can_do_hugetlb_shm(void)
64240 {
64241diff --git a/fs/inode.c b/fs/inode.c
64242index 26753ba..d19eb34 100644
64243--- a/fs/inode.c
64244+++ b/fs/inode.c
64245@@ -840,16 +840,20 @@ unsigned int get_next_ino(void)
64246 unsigned int *p = &get_cpu_var(last_ino);
64247 unsigned int res = *p;
64248
64249+start:
64250+
64251 #ifdef CONFIG_SMP
64252 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
64253- static atomic_t shared_last_ino;
64254- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
64255+ static atomic_unchecked_t shared_last_ino;
64256+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
64257
64258 res = next - LAST_INO_BATCH;
64259 }
64260 #endif
64261
64262- *p = ++res;
64263+ if (unlikely(!++res))
64264+ goto start; /* never zero */
64265+ *p = res;
64266 put_cpu_var(last_ino);
64267 return res;
64268 }
64269diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
64270index 4a6cf28..d3a29d3 100644
64271--- a/fs/jffs2/erase.c
64272+++ b/fs/jffs2/erase.c
64273@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
64274 struct jffs2_unknown_node marker = {
64275 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
64276 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
64277- .totlen = cpu_to_je32(c->cleanmarker_size)
64278+ .totlen = cpu_to_je32(c->cleanmarker_size),
64279+ .hdr_crc = cpu_to_je32(0)
64280 };
64281
64282 jffs2_prealloc_raw_node_refs(c, jeb, 1);
64283diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
64284index 09ed551..45684f8 100644
64285--- a/fs/jffs2/wbuf.c
64286+++ b/fs/jffs2/wbuf.c
64287@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
64288 {
64289 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
64290 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
64291- .totlen = constant_cpu_to_je32(8)
64292+ .totlen = constant_cpu_to_je32(8),
64293+ .hdr_crc = constant_cpu_to_je32(0)
64294 };
64295
64296 /*
64297diff --git a/fs/jfs/super.c b/fs/jfs/super.c
64298index adf8cb0..bb935fa 100644
64299--- a/fs/jfs/super.c
64300+++ b/fs/jfs/super.c
64301@@ -893,7 +893,7 @@ static int __init init_jfs_fs(void)
64302
64303 jfs_inode_cachep =
64304 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
64305- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
64306+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
64307 init_once);
64308 if (jfs_inode_cachep == NULL)
64309 return -ENOMEM;
64310diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
64311index a693f5b..82276a1 100644
64312--- a/fs/kernfs/dir.c
64313+++ b/fs/kernfs/dir.c
64314@@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
64315 *
64316 * Returns 31 bit hash of ns + name (so it fits in an off_t )
64317 */
64318-static unsigned int kernfs_name_hash(const char *name, const void *ns)
64319+static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
64320 {
64321 unsigned long hash = init_name_hash();
64322 unsigned int len = strlen(name);
64323diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
64324index 4429d6d..9831f52 100644
64325--- a/fs/kernfs/file.c
64326+++ b/fs/kernfs/file.c
64327@@ -34,7 +34,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
64328
64329 struct kernfs_open_node {
64330 atomic_t refcnt;
64331- atomic_t event;
64332+ atomic_unchecked_t event;
64333 wait_queue_head_t poll;
64334 struct list_head files; /* goes through kernfs_open_file.list */
64335 };
64336@@ -163,7 +163,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
64337 {
64338 struct kernfs_open_file *of = sf->private;
64339
64340- of->event = atomic_read(&of->kn->attr.open->event);
64341+ of->event = atomic_read_unchecked(&of->kn->attr.open->event);
64342
64343 return of->kn->attr.ops->seq_show(sf, v);
64344 }
64345@@ -375,12 +375,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
64346 return ret;
64347 }
64348
64349-static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
64350- void *buf, int len, int write)
64351+static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
64352+ void *buf, size_t len, int write)
64353 {
64354 struct file *file = vma->vm_file;
64355 struct kernfs_open_file *of = kernfs_of(file);
64356- int ret;
64357+ ssize_t ret;
64358
64359 if (!of->vm_ops)
64360 return -EINVAL;
64361@@ -581,7 +581,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
64362 return -ENOMEM;
64363
64364 atomic_set(&new_on->refcnt, 0);
64365- atomic_set(&new_on->event, 1);
64366+ atomic_set_unchecked(&new_on->event, 1);
64367 init_waitqueue_head(&new_on->poll);
64368 INIT_LIST_HEAD(&new_on->files);
64369 goto retry;
64370@@ -787,7 +787,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
64371
64372 kernfs_put_active(kn);
64373
64374- if (of->event != atomic_read(&on->event))
64375+ if (of->event != atomic_read_unchecked(&on->event))
64376 goto trigger;
64377
64378 return DEFAULT_POLLMASK;
64379@@ -818,7 +818,7 @@ repeat:
64380
64381 on = kn->attr.open;
64382 if (on) {
64383- atomic_inc(&on->event);
64384+ atomic_inc_unchecked(&on->event);
64385 wake_up_interruptible(&on->poll);
64386 }
64387
64388diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
64389index 8a19889..4c3069a 100644
64390--- a/fs/kernfs/symlink.c
64391+++ b/fs/kernfs/symlink.c
64392@@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
64393 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
64394 void *cookie)
64395 {
64396- char *page = nd_get_link(nd);
64397+ const char *page = nd_get_link(nd);
64398 if (!IS_ERR(page))
64399 free_page((unsigned long)page);
64400 }
64401diff --git a/fs/libfs.c b/fs/libfs.c
64402index 88e3e00..979c262 100644
64403--- a/fs/libfs.c
64404+++ b/fs/libfs.c
64405@@ -160,6 +160,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64406
64407 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
64408 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
64409+ char d_name[sizeof(next->d_iname)];
64410+ const unsigned char *name;
64411+
64412 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
64413 if (!simple_positive(next)) {
64414 spin_unlock(&next->d_lock);
64415@@ -168,7 +171,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64416
64417 spin_unlock(&next->d_lock);
64418 spin_unlock(&dentry->d_lock);
64419- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
64420+ name = next->d_name.name;
64421+ if (name == next->d_iname) {
64422+ memcpy(d_name, name, next->d_name.len);
64423+ name = d_name;
64424+ }
64425+ if (!dir_emit(ctx, name, next->d_name.len,
64426 next->d_inode->i_ino, dt_type(next->d_inode)))
64427 return 0;
64428 spin_lock(&dentry->d_lock);
64429@@ -1027,7 +1035,7 @@ EXPORT_SYMBOL(noop_fsync);
64430 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
64431 void *cookie)
64432 {
64433- char *s = nd_get_link(nd);
64434+ const char *s = nd_get_link(nd);
64435 if (!IS_ERR(s))
64436 kfree(s);
64437 }
64438diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
64439index acd3947..1f896e2 100644
64440--- a/fs/lockd/clntproc.c
64441+++ b/fs/lockd/clntproc.c
64442@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
64443 /*
64444 * Cookie counter for NLM requests
64445 */
64446-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
64447+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
64448
64449 void nlmclnt_next_cookie(struct nlm_cookie *c)
64450 {
64451- u32 cookie = atomic_inc_return(&nlm_cookie);
64452+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
64453
64454 memcpy(c->data, &cookie, 4);
64455 c->len=4;
64456diff --git a/fs/locks.c b/fs/locks.c
64457index bb08857..f65e8bf 100644
64458--- a/fs/locks.c
64459+++ b/fs/locks.c
64460@@ -2350,7 +2350,7 @@ void locks_remove_file(struct file *filp)
64461 locks_remove_posix(filp, filp);
64462
64463 if (filp->f_op->flock) {
64464- struct file_lock fl = {
64465+ struct file_lock flock = {
64466 .fl_owner = filp,
64467 .fl_pid = current->tgid,
64468 .fl_file = filp,
64469@@ -2358,9 +2358,9 @@ void locks_remove_file(struct file *filp)
64470 .fl_type = F_UNLCK,
64471 .fl_end = OFFSET_MAX,
64472 };
64473- filp->f_op->flock(filp, F_SETLKW, &fl);
64474- if (fl.fl_ops && fl.fl_ops->fl_release_private)
64475- fl.fl_ops->fl_release_private(&fl);
64476+ filp->f_op->flock(filp, F_SETLKW, &flock);
64477+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
64478+ flock.fl_ops->fl_release_private(&flock);
64479 }
64480
64481 spin_lock(&inode->i_lock);
64482diff --git a/fs/mount.h b/fs/mount.h
64483index 6740a62..ccb472f 100644
64484--- a/fs/mount.h
64485+++ b/fs/mount.h
64486@@ -11,7 +11,7 @@ struct mnt_namespace {
64487 u64 seq; /* Sequence number to prevent loops */
64488 wait_queue_head_t poll;
64489 u64 event;
64490-};
64491+} __randomize_layout;
64492
64493 struct mnt_pcp {
64494 int mnt_count;
64495@@ -57,7 +57,7 @@ struct mount {
64496 int mnt_expiry_mark; /* true if marked for expiry */
64497 struct hlist_head mnt_pins;
64498 struct path mnt_ex_mountpoint;
64499-};
64500+} __randomize_layout;
64501
64502 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
64503
64504diff --git a/fs/namei.c b/fs/namei.c
64505index bb02687..79cba2c 100644
64506--- a/fs/namei.c
64507+++ b/fs/namei.c
64508@@ -331,17 +331,32 @@ int generic_permission(struct inode *inode, int mask)
64509 if (ret != -EACCES)
64510 return ret;
64511
64512+#ifdef CONFIG_GRKERNSEC
64513+ /* we'll block if we have to log due to a denied capability use */
64514+ if (mask & MAY_NOT_BLOCK)
64515+ return -ECHILD;
64516+#endif
64517+
64518 if (S_ISDIR(inode->i_mode)) {
64519 /* DACs are overridable for directories */
64520- if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64521- return 0;
64522 if (!(mask & MAY_WRITE))
64523- if (capable_wrt_inode_uidgid(inode,
64524- CAP_DAC_READ_SEARCH))
64525+ if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
64526+ capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64527 return 0;
64528+ if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64529+ return 0;
64530 return -EACCES;
64531 }
64532 /*
64533+ * Searching includes executable on directories, else just read.
64534+ */
64535+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
64536+ if (mask == MAY_READ)
64537+ if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
64538+ capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64539+ return 0;
64540+
64541+ /*
64542 * Read/write DACs are always overridable.
64543 * Executable DACs are overridable when there is
64544 * at least one exec bit set.
64545@@ -350,14 +365,6 @@ int generic_permission(struct inode *inode, int mask)
64546 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64547 return 0;
64548
64549- /*
64550- * Searching includes executable on directories, else just read.
64551- */
64552- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
64553- if (mask == MAY_READ)
64554- if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64555- return 0;
64556-
64557 return -EACCES;
64558 }
64559 EXPORT_SYMBOL(generic_permission);
64560@@ -823,7 +830,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
64561 {
64562 struct dentry *dentry = link->dentry;
64563 int error;
64564- char *s;
64565+ const char *s;
64566
64567 BUG_ON(nd->flags & LOOKUP_RCU);
64568
64569@@ -844,6 +851,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
64570 if (error)
64571 goto out_put_nd_path;
64572
64573+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
64574+ dentry->d_inode, dentry, nd->path.mnt)) {
64575+ error = -EACCES;
64576+ goto out_put_nd_path;
64577+ }
64578+
64579 nd->last_type = LAST_BIND;
64580 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
64581 error = PTR_ERR(*p);
64582@@ -1607,6 +1620,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
64583 if (res)
64584 break;
64585 res = walk_component(nd, path, LOOKUP_FOLLOW);
64586+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
64587+ res = -EACCES;
64588 put_link(nd, &link, cookie);
64589 } while (res > 0);
64590
64591@@ -1679,7 +1694,7 @@ EXPORT_SYMBOL(full_name_hash);
64592 static inline u64 hash_name(const char *name)
64593 {
64594 unsigned long a, b, adata, bdata, mask, hash, len;
64595- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
64596+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
64597
64598 hash = a = 0;
64599 len = -sizeof(unsigned long);
64600@@ -1968,6 +1983,8 @@ static int path_lookupat(int dfd, const char *name,
64601 if (err)
64602 break;
64603 err = lookup_last(nd, &path);
64604+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
64605+ err = -EACCES;
64606 put_link(nd, &link, cookie);
64607 }
64608 }
64609@@ -1975,6 +1992,13 @@ static int path_lookupat(int dfd, const char *name,
64610 if (!err)
64611 err = complete_walk(nd);
64612
64613+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
64614+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64615+ path_put(&nd->path);
64616+ err = -ENOENT;
64617+ }
64618+ }
64619+
64620 if (!err && nd->flags & LOOKUP_DIRECTORY) {
64621 if (!d_can_lookup(nd->path.dentry)) {
64622 path_put(&nd->path);
64623@@ -2002,8 +2026,15 @@ static int filename_lookup(int dfd, struct filename *name,
64624 retval = path_lookupat(dfd, name->name,
64625 flags | LOOKUP_REVAL, nd);
64626
64627- if (likely(!retval))
64628+ if (likely(!retval)) {
64629 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
64630+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
64631+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
64632+ path_put(&nd->path);
64633+ return -ENOENT;
64634+ }
64635+ }
64636+ }
64637 return retval;
64638 }
64639
64640@@ -2585,6 +2616,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
64641 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
64642 return -EPERM;
64643
64644+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
64645+ return -EPERM;
64646+ if (gr_handle_rawio(inode))
64647+ return -EPERM;
64648+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
64649+ return -EACCES;
64650+
64651 return 0;
64652 }
64653
64654@@ -2816,7 +2854,7 @@ looked_up:
64655 * cleared otherwise prior to returning.
64656 */
64657 static int lookup_open(struct nameidata *nd, struct path *path,
64658- struct file *file,
64659+ struct path *link, struct file *file,
64660 const struct open_flags *op,
64661 bool got_write, int *opened)
64662 {
64663@@ -2851,6 +2889,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64664 /* Negative dentry, just create the file */
64665 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
64666 umode_t mode = op->mode;
64667+
64668+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
64669+ error = -EACCES;
64670+ goto out_dput;
64671+ }
64672+
64673+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
64674+ error = -EACCES;
64675+ goto out_dput;
64676+ }
64677+
64678 if (!IS_POSIXACL(dir->d_inode))
64679 mode &= ~current_umask();
64680 /*
64681@@ -2872,6 +2921,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64682 nd->flags & LOOKUP_EXCL);
64683 if (error)
64684 goto out_dput;
64685+ else
64686+ gr_handle_create(dentry, nd->path.mnt);
64687 }
64688 out_no_open:
64689 path->dentry = dentry;
64690@@ -2886,7 +2937,7 @@ out_dput:
64691 /*
64692 * Handle the last step of open()
64693 */
64694-static int do_last(struct nameidata *nd, struct path *path,
64695+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
64696 struct file *file, const struct open_flags *op,
64697 int *opened, struct filename *name)
64698 {
64699@@ -2936,6 +2987,15 @@ static int do_last(struct nameidata *nd, struct path *path,
64700 if (error)
64701 return error;
64702
64703+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
64704+ error = -ENOENT;
64705+ goto out;
64706+ }
64707+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
64708+ error = -EACCES;
64709+ goto out;
64710+ }
64711+
64712 audit_inode(name, dir, LOOKUP_PARENT);
64713 error = -EISDIR;
64714 /* trailing slashes? */
64715@@ -2955,7 +3015,7 @@ retry_lookup:
64716 */
64717 }
64718 mutex_lock(&dir->d_inode->i_mutex);
64719- error = lookup_open(nd, path, file, op, got_write, opened);
64720+ error = lookup_open(nd, path, link, file, op, got_write, opened);
64721 mutex_unlock(&dir->d_inode->i_mutex);
64722
64723 if (error <= 0) {
64724@@ -2979,11 +3039,28 @@ retry_lookup:
64725 goto finish_open_created;
64726 }
64727
64728+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
64729+ error = -ENOENT;
64730+ goto exit_dput;
64731+ }
64732+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
64733+ error = -EACCES;
64734+ goto exit_dput;
64735+ }
64736+
64737 /*
64738 * create/update audit record if it already exists.
64739 */
64740- if (d_is_positive(path->dentry))
64741+ if (d_is_positive(path->dentry)) {
64742+ /* only check if O_CREAT is specified, all other checks need to go
64743+ into may_open */
64744+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
64745+ error = -EACCES;
64746+ goto exit_dput;
64747+ }
64748+
64749 audit_inode(name, path->dentry, 0);
64750+ }
64751
64752 /*
64753 * If atomic_open() acquired write access it is dropped now due to
64754@@ -3024,6 +3101,11 @@ finish_lookup:
64755 }
64756 }
64757 BUG_ON(inode != path->dentry->d_inode);
64758+ /* if we're resolving a symlink to another symlink */
64759+ if (link && gr_handle_symlink_owner(link, inode)) {
64760+ error = -EACCES;
64761+ goto out;
64762+ }
64763 return 1;
64764 }
64765
64766@@ -3033,7 +3115,6 @@ finish_lookup:
64767 save_parent.dentry = nd->path.dentry;
64768 save_parent.mnt = mntget(path->mnt);
64769 nd->path.dentry = path->dentry;
64770-
64771 }
64772 nd->inode = inode;
64773 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
64774@@ -3043,7 +3124,18 @@ finish_open:
64775 path_put(&save_parent);
64776 return error;
64777 }
64778+
64779+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64780+ error = -ENOENT;
64781+ goto out;
64782+ }
64783+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
64784+ error = -EACCES;
64785+ goto out;
64786+ }
64787+
64788 audit_inode(name, nd->path.dentry, 0);
64789+
64790 error = -EISDIR;
64791 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
64792 goto out;
64793@@ -3207,7 +3299,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64794 if (unlikely(error))
64795 goto out;
64796
64797- error = do_last(nd, &path, file, op, &opened, pathname);
64798+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
64799 while (unlikely(error > 0)) { /* trailing symlink */
64800 struct path link = path;
64801 void *cookie;
64802@@ -3225,7 +3317,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64803 error = follow_link(&link, nd, &cookie);
64804 if (unlikely(error))
64805 break;
64806- error = do_last(nd, &path, file, op, &opened, pathname);
64807+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
64808 put_link(nd, &link, cookie);
64809 }
64810 out:
64811@@ -3325,9 +3417,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
64812 goto unlock;
64813
64814 error = -EEXIST;
64815- if (d_is_positive(dentry))
64816+ if (d_is_positive(dentry)) {
64817+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
64818+ error = -ENOENT;
64819 goto fail;
64820-
64821+ }
64822 /*
64823 * Special case - lookup gave negative, but... we had foo/bar/
64824 * From the vfs_mknod() POV we just have a negative dentry -
64825@@ -3379,6 +3473,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
64826 }
64827 EXPORT_SYMBOL(user_path_create);
64828
64829+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
64830+{
64831+ struct filename *tmp = getname(pathname);
64832+ struct dentry *res;
64833+ if (IS_ERR(tmp))
64834+ return ERR_CAST(tmp);
64835+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
64836+ if (IS_ERR(res))
64837+ putname(tmp);
64838+ else
64839+ *to = tmp;
64840+ return res;
64841+}
64842+
64843 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
64844 {
64845 int error = may_create(dir, dentry);
64846@@ -3442,6 +3550,17 @@ retry:
64847
64848 if (!IS_POSIXACL(path.dentry->d_inode))
64849 mode &= ~current_umask();
64850+
64851+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
64852+ error = -EPERM;
64853+ goto out;
64854+ }
64855+
64856+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
64857+ error = -EACCES;
64858+ goto out;
64859+ }
64860+
64861 error = security_path_mknod(&path, dentry, mode, dev);
64862 if (error)
64863 goto out;
64864@@ -3457,6 +3576,8 @@ retry:
64865 error = vfs_mknod(path.dentry->d_inode,dentry,mode,0);
64866 break;
64867 }
64868+ if (!error)
64869+ gr_handle_create(dentry, path.mnt);
64870 out:
64871 done_path_create(&path, dentry);
64872 if (retry_estale(error, lookup_flags)) {
64873@@ -3511,9 +3632,16 @@ retry:
64874
64875 if (!IS_POSIXACL(path.dentry->d_inode))
64876 mode &= ~current_umask();
64877+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
64878+ error = -EACCES;
64879+ goto out;
64880+ }
64881 error = security_path_mkdir(&path, dentry, mode);
64882 if (!error)
64883 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
64884+ if (!error)
64885+ gr_handle_create(dentry, path.mnt);
64886+out:
64887 done_path_create(&path, dentry);
64888 if (retry_estale(error, lookup_flags)) {
64889 lookup_flags |= LOOKUP_REVAL;
64890@@ -3596,6 +3724,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
64891 struct filename *name;
64892 struct dentry *dentry;
64893 struct nameidata nd;
64894+ ino_t saved_ino = 0;
64895+ dev_t saved_dev = 0;
64896 unsigned int lookup_flags = 0;
64897 retry:
64898 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64899@@ -3628,10 +3758,21 @@ retry:
64900 error = -ENOENT;
64901 goto exit3;
64902 }
64903+
64904+ saved_ino = dentry->d_inode->i_ino;
64905+ saved_dev = gr_get_dev_from_dentry(dentry);
64906+
64907+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
64908+ error = -EACCES;
64909+ goto exit3;
64910+ }
64911+
64912 error = security_path_rmdir(&nd.path, dentry);
64913 if (error)
64914 goto exit3;
64915 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
64916+ if (!error && (saved_dev || saved_ino))
64917+ gr_handle_delete(saved_ino, saved_dev);
64918 exit3:
64919 dput(dentry);
64920 exit2:
64921@@ -3722,6 +3863,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
64922 struct nameidata nd;
64923 struct inode *inode = NULL;
64924 struct inode *delegated_inode = NULL;
64925+ ino_t saved_ino = 0;
64926+ dev_t saved_dev = 0;
64927 unsigned int lookup_flags = 0;
64928 retry:
64929 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64930@@ -3748,10 +3891,22 @@ retry_deleg:
64931 if (d_is_negative(dentry))
64932 goto slashes;
64933 ihold(inode);
64934+
64935+ if (inode->i_nlink <= 1) {
64936+ saved_ino = inode->i_ino;
64937+ saved_dev = gr_get_dev_from_dentry(dentry);
64938+ }
64939+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
64940+ error = -EACCES;
64941+ goto exit2;
64942+ }
64943+
64944 error = security_path_unlink(&nd.path, dentry);
64945 if (error)
64946 goto exit2;
64947 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
64948+ if (!error && (saved_ino || saved_dev))
64949+ gr_handle_delete(saved_ino, saved_dev);
64950 exit2:
64951 dput(dentry);
64952 }
64953@@ -3840,9 +3995,17 @@ retry:
64954 if (IS_ERR(dentry))
64955 goto out_putname;
64956
64957+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
64958+ error = -EACCES;
64959+ goto out;
64960+ }
64961+
64962 error = security_path_symlink(&path, dentry, from->name);
64963 if (!error)
64964 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
64965+ if (!error)
64966+ gr_handle_create(dentry, path.mnt);
64967+out:
64968 done_path_create(&path, dentry);
64969 if (retry_estale(error, lookup_flags)) {
64970 lookup_flags |= LOOKUP_REVAL;
64971@@ -3946,6 +4109,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
64972 struct dentry *new_dentry;
64973 struct path old_path, new_path;
64974 struct inode *delegated_inode = NULL;
64975+ struct filename *to = NULL;
64976 int how = 0;
64977 int error;
64978
64979@@ -3969,7 +4133,7 @@ retry:
64980 if (error)
64981 return error;
64982
64983- new_dentry = user_path_create(newdfd, newname, &new_path,
64984+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
64985 (how & LOOKUP_REVAL));
64986 error = PTR_ERR(new_dentry);
64987 if (IS_ERR(new_dentry))
64988@@ -3981,11 +4145,28 @@ retry:
64989 error = may_linkat(&old_path);
64990 if (unlikely(error))
64991 goto out_dput;
64992+
64993+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
64994+ old_path.dentry->d_inode,
64995+ old_path.dentry->d_inode->i_mode, to)) {
64996+ error = -EACCES;
64997+ goto out_dput;
64998+ }
64999+
65000+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
65001+ old_path.dentry, old_path.mnt, to)) {
65002+ error = -EACCES;
65003+ goto out_dput;
65004+ }
65005+
65006 error = security_path_link(old_path.dentry, &new_path, new_dentry);
65007 if (error)
65008 goto out_dput;
65009 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
65010+ if (!error)
65011+ gr_handle_create(new_dentry, new_path.mnt);
65012 out_dput:
65013+ putname(to);
65014 done_path_create(&new_path, new_dentry);
65015 if (delegated_inode) {
65016 error = break_deleg_wait(&delegated_inode);
65017@@ -4296,6 +4477,12 @@ retry_deleg:
65018 if (new_dentry == trap)
65019 goto exit5;
65020
65021+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
65022+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
65023+ to, flags);
65024+ if (error)
65025+ goto exit5;
65026+
65027 error = security_path_rename(&oldnd.path, old_dentry,
65028 &newnd.path, new_dentry, flags);
65029 if (error)
65030@@ -4303,6 +4490,9 @@ retry_deleg:
65031 error = vfs_rename(old_dir->d_inode, old_dentry,
65032 new_dir->d_inode, new_dentry,
65033 &delegated_inode, flags);
65034+ if (!error)
65035+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
65036+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
65037 exit5:
65038 dput(new_dentry);
65039 exit4:
65040@@ -4345,14 +4535,24 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
65041
65042 int readlink_copy(char __user *buffer, int buflen, const char *link)
65043 {
65044+ char tmpbuf[64];
65045+ const char *newlink;
65046 int len = PTR_ERR(link);
65047+
65048 if (IS_ERR(link))
65049 goto out;
65050
65051 len = strlen(link);
65052 if (len > (unsigned) buflen)
65053 len = buflen;
65054- if (copy_to_user(buffer, link, len))
65055+
65056+ if (len < sizeof(tmpbuf)) {
65057+ memcpy(tmpbuf, link, len);
65058+ newlink = tmpbuf;
65059+ } else
65060+ newlink = link;
65061+
65062+ if (copy_to_user(buffer, newlink, len))
65063 len = -EFAULT;
65064 out:
65065 return len;
65066diff --git a/fs/namespace.c b/fs/namespace.c
65067index 550dbff..c4ad324 100644
65068--- a/fs/namespace.c
65069+++ b/fs/namespace.c
65070@@ -1362,6 +1362,9 @@ static int do_umount(struct mount *mnt, int flags)
65071 if (!(sb->s_flags & MS_RDONLY))
65072 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
65073 up_write(&sb->s_umount);
65074+
65075+ gr_log_remount(mnt->mnt_devname, retval);
65076+
65077 return retval;
65078 }
65079
65080@@ -1384,6 +1387,9 @@ static int do_umount(struct mount *mnt, int flags)
65081 }
65082 unlock_mount_hash();
65083 namespace_unlock();
65084+
65085+ gr_log_unmount(mnt->mnt_devname, retval);
65086+
65087 return retval;
65088 }
65089
65090@@ -1403,7 +1409,7 @@ static inline bool may_mount(void)
65091 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
65092 */
65093
65094-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
65095+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
65096 {
65097 struct path path;
65098 struct mount *mnt;
65099@@ -1445,7 +1451,7 @@ out:
65100 /*
65101 * The 2.0 compatible umount. No flags.
65102 */
65103-SYSCALL_DEFINE1(oldumount, char __user *, name)
65104+SYSCALL_DEFINE1(oldumount, const char __user *, name)
65105 {
65106 return sys_umount(name, 0);
65107 }
65108@@ -2494,6 +2500,16 @@ long do_mount(const char *dev_name, const char *dir_name,
65109 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
65110 MS_STRICTATIME);
65111
65112+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
65113+ retval = -EPERM;
65114+ goto dput_out;
65115+ }
65116+
65117+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
65118+ retval = -EPERM;
65119+ goto dput_out;
65120+ }
65121+
65122 if (flags & MS_REMOUNT)
65123 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
65124 data_page);
65125@@ -2508,6 +2524,9 @@ long do_mount(const char *dev_name, const char *dir_name,
65126 dev_name, data_page);
65127 dput_out:
65128 path_put(&path);
65129+
65130+ gr_log_mount(dev_name, dir_name, retval);
65131+
65132 return retval;
65133 }
65134
65135@@ -2525,7 +2544,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
65136 * number incrementing at 10Ghz will take 12,427 years to wrap which
65137 * is effectively never, so we can ignore the possibility.
65138 */
65139-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
65140+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
65141
65142 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
65143 {
65144@@ -2540,7 +2559,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
65145 kfree(new_ns);
65146 return ERR_PTR(ret);
65147 }
65148- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
65149+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
65150 atomic_set(&new_ns->count, 1);
65151 new_ns->root = NULL;
65152 INIT_LIST_HEAD(&new_ns->list);
65153@@ -2550,7 +2569,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
65154 return new_ns;
65155 }
65156
65157-struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
65158+__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
65159 struct user_namespace *user_ns, struct fs_struct *new_fs)
65160 {
65161 struct mnt_namespace *new_ns;
65162@@ -2671,8 +2690,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
65163 }
65164 EXPORT_SYMBOL(mount_subtree);
65165
65166-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
65167- char __user *, type, unsigned long, flags, void __user *, data)
65168+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
65169+ const char __user *, type, unsigned long, flags, void __user *, data)
65170 {
65171 int ret;
65172 char *kernel_type;
65173@@ -2785,6 +2804,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
65174 if (error)
65175 goto out2;
65176
65177+ if (gr_handle_chroot_pivot()) {
65178+ error = -EPERM;
65179+ goto out2;
65180+ }
65181+
65182 get_fs_root(current->fs, &root);
65183 old_mp = lock_mount(&old);
65184 error = PTR_ERR(old_mp);
65185@@ -3056,7 +3080,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
65186 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
65187 return -EPERM;
65188
65189- if (fs->users != 1)
65190+ if (atomic_read(&fs->users) != 1)
65191 return -EINVAL;
65192
65193 get_mnt_ns(mnt_ns);
65194diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
65195index f4ccfe6..a5cf064 100644
65196--- a/fs/nfs/callback_xdr.c
65197+++ b/fs/nfs/callback_xdr.c
65198@@ -51,7 +51,7 @@ struct callback_op {
65199 callback_decode_arg_t decode_args;
65200 callback_encode_res_t encode_res;
65201 long res_maxsize;
65202-};
65203+} __do_const;
65204
65205 static struct callback_op callback_ops[];
65206
65207diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
65208index 0689aa5..299386e 100644
65209--- a/fs/nfs/inode.c
65210+++ b/fs/nfs/inode.c
65211@@ -1228,16 +1228,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
65212 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
65213 }
65214
65215-static atomic_long_t nfs_attr_generation_counter;
65216+static atomic_long_unchecked_t nfs_attr_generation_counter;
65217
65218 static unsigned long nfs_read_attr_generation_counter(void)
65219 {
65220- return atomic_long_read(&nfs_attr_generation_counter);
65221+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
65222 }
65223
65224 unsigned long nfs_inc_attr_generation_counter(void)
65225 {
65226- return atomic_long_inc_return(&nfs_attr_generation_counter);
65227+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
65228 }
65229
65230 void nfs_fattr_init(struct nfs_fattr *fattr)
65231diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
65232index 1d3cb47..2b8ed89 100644
65233--- a/fs/nfsd/nfs4proc.c
65234+++ b/fs/nfsd/nfs4proc.c
65235@@ -1155,7 +1155,7 @@ struct nfsd4_operation {
65236 nfsd4op_rsize op_rsize_bop;
65237 stateid_getter op_get_currentstateid;
65238 stateid_setter op_set_currentstateid;
65239-};
65240+} __do_const;
65241
65242 static struct nfsd4_operation nfsd4_ops[];
65243
65244diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
65245index 353aac8..32035ee 100644
65246--- a/fs/nfsd/nfs4xdr.c
65247+++ b/fs/nfsd/nfs4xdr.c
65248@@ -1534,7 +1534,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
65249
65250 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
65251
65252-static nfsd4_dec nfsd4_dec_ops[] = {
65253+static const nfsd4_dec nfsd4_dec_ops[] = {
65254 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
65255 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
65256 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
65257diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
65258index ff95676..96cf3f62 100644
65259--- a/fs/nfsd/nfscache.c
65260+++ b/fs/nfsd/nfscache.c
65261@@ -527,17 +527,20 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
65262 {
65263 struct svc_cacherep *rp = rqstp->rq_cacherep;
65264 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
65265- int len;
65266+ long len;
65267 size_t bufsize = 0;
65268
65269 if (!rp)
65270 return;
65271
65272- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
65273- len >>= 2;
65274+ if (statp) {
65275+ len = (char*)statp - (char*)resv->iov_base;
65276+ len = resv->iov_len - len;
65277+ len >>= 2;
65278+ }
65279
65280 /* Don't cache excessive amounts of data and XDR failures */
65281- if (!statp || len > (256 >> 2)) {
65282+ if (!statp || len > (256 >> 2) || len < 0) {
65283 nfsd_reply_cache_free(rp);
65284 return;
65285 }
65286@@ -545,7 +548,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
65287 switch (cachetype) {
65288 case RC_REPLSTAT:
65289 if (len != 1)
65290- printk("nfsd: RC_REPLSTAT/reply len %d!\n",len);
65291+ printk("nfsd: RC_REPLSTAT/reply len %ld!\n",len);
65292 rp->c_replstat = *statp;
65293 break;
65294 case RC_REPLBUFF:
65295diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
65296index 6ab077b..5ac7f0b 100644
65297--- a/fs/nfsd/vfs.c
65298+++ b/fs/nfsd/vfs.c
65299@@ -855,7 +855,7 @@ __be32 nfsd_readv(struct file *file, loff_t offset, struct kvec *vec, int vlen,
65300
65301 oldfs = get_fs();
65302 set_fs(KERNEL_DS);
65303- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
65304+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
65305 set_fs(oldfs);
65306 return nfsd_finish_read(file, count, host_err);
65307 }
65308@@ -943,7 +943,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
65309
65310 /* Write the data. */
65311 oldfs = get_fs(); set_fs(KERNEL_DS);
65312- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
65313+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
65314 set_fs(oldfs);
65315 if (host_err < 0)
65316 goto out_nfserr;
65317@@ -1485,7 +1485,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
65318 */
65319
65320 oldfs = get_fs(); set_fs(KERNEL_DS);
65321- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
65322+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
65323 set_fs(oldfs);
65324
65325 if (host_err < 0)
65326diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
65327index 52ccd34..7a6b202 100644
65328--- a/fs/nls/nls_base.c
65329+++ b/fs/nls/nls_base.c
65330@@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
65331
65332 int __register_nls(struct nls_table *nls, struct module *owner)
65333 {
65334- struct nls_table ** tmp = &tables;
65335+ struct nls_table *tmp = tables;
65336
65337 if (nls->next)
65338 return -EBUSY;
65339
65340- nls->owner = owner;
65341+ pax_open_kernel();
65342+ *(void **)&nls->owner = owner;
65343+ pax_close_kernel();
65344 spin_lock(&nls_lock);
65345- while (*tmp) {
65346- if (nls == *tmp) {
65347+ while (tmp) {
65348+ if (nls == tmp) {
65349 spin_unlock(&nls_lock);
65350 return -EBUSY;
65351 }
65352- tmp = &(*tmp)->next;
65353+ tmp = tmp->next;
65354 }
65355- nls->next = tables;
65356+ pax_open_kernel();
65357+ *(struct nls_table **)&nls->next = tables;
65358+ pax_close_kernel();
65359 tables = nls;
65360 spin_unlock(&nls_lock);
65361 return 0;
65362@@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
65363
65364 int unregister_nls(struct nls_table * nls)
65365 {
65366- struct nls_table ** tmp = &tables;
65367+ struct nls_table * const * tmp = &tables;
65368
65369 spin_lock(&nls_lock);
65370 while (*tmp) {
65371 if (nls == *tmp) {
65372- *tmp = nls->next;
65373+ pax_open_kernel();
65374+ *(struct nls_table **)tmp = nls->next;
65375+ pax_close_kernel();
65376 spin_unlock(&nls_lock);
65377 return 0;
65378 }
65379@@ -272,7 +278,7 @@ int unregister_nls(struct nls_table * nls)
65380 return -EINVAL;
65381 }
65382
65383-static struct nls_table *find_nls(char *charset)
65384+static struct nls_table *find_nls(const char *charset)
65385 {
65386 struct nls_table *nls;
65387 spin_lock(&nls_lock);
65388@@ -288,7 +294,7 @@ static struct nls_table *find_nls(char *charset)
65389 return nls;
65390 }
65391
65392-struct nls_table *load_nls(char *charset)
65393+struct nls_table *load_nls(const char *charset)
65394 {
65395 return try_then_request_module(find_nls(charset), "nls_%s", charset);
65396 }
65397diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
65398index 162b3f1..6076a7c 100644
65399--- a/fs/nls/nls_euc-jp.c
65400+++ b/fs/nls/nls_euc-jp.c
65401@@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
65402 p_nls = load_nls("cp932");
65403
65404 if (p_nls) {
65405- table.charset2upper = p_nls->charset2upper;
65406- table.charset2lower = p_nls->charset2lower;
65407+ pax_open_kernel();
65408+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65409+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65410+ pax_close_kernel();
65411 return register_nls(&table);
65412 }
65413
65414diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
65415index a80a741..7b96e1b 100644
65416--- a/fs/nls/nls_koi8-ru.c
65417+++ b/fs/nls/nls_koi8-ru.c
65418@@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
65419 p_nls = load_nls("koi8-u");
65420
65421 if (p_nls) {
65422- table.charset2upper = p_nls->charset2upper;
65423- table.charset2lower = p_nls->charset2lower;
65424+ pax_open_kernel();
65425+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65426+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65427+ pax_close_kernel();
65428 return register_nls(&table);
65429 }
65430
65431diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
65432index c991616..5ae51af 100644
65433--- a/fs/notify/fanotify/fanotify_user.c
65434+++ b/fs/notify/fanotify/fanotify_user.c
65435@@ -216,8 +216,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
65436
65437 fd = fanotify_event_metadata.fd;
65438 ret = -EFAULT;
65439- if (copy_to_user(buf, &fanotify_event_metadata,
65440- fanotify_event_metadata.event_len))
65441+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
65442+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
65443 goto out_close_fd;
65444
65445 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
65446diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c
65447index 0f88bc0..7d888d7 100644
65448--- a/fs/notify/inotify/inotify_fsnotify.c
65449+++ b/fs/notify/inotify/inotify_fsnotify.c
65450@@ -165,8 +165,10 @@ static void inotify_free_group_priv(struct fsnotify_group *group)
65451 /* ideally the idr is empty and we won't hit the BUG in the callback */
65452 idr_for_each(&group->inotify_data.idr, idr_callback, group);
65453 idr_destroy(&group->inotify_data.idr);
65454- atomic_dec(&group->inotify_data.user->inotify_devs);
65455- free_uid(group->inotify_data.user);
65456+ if (group->inotify_data.user) {
65457+ atomic_dec(&group->inotify_data.user->inotify_devs);
65458+ free_uid(group->inotify_data.user);
65459+ }
65460 }
65461
65462 static void inotify_free_event(struct fsnotify_event *fsn_event)
65463diff --git a/fs/notify/notification.c b/fs/notify/notification.c
65464index a95d8e0..a91a5fd 100644
65465--- a/fs/notify/notification.c
65466+++ b/fs/notify/notification.c
65467@@ -48,7 +48,7 @@
65468 #include <linux/fsnotify_backend.h>
65469 #include "fsnotify.h"
65470
65471-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65472+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65473
65474 /**
65475 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
65476@@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65477 */
65478 u32 fsnotify_get_cookie(void)
65479 {
65480- return atomic_inc_return(&fsnotify_sync_cookie);
65481+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
65482 }
65483 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
65484
65485diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
65486index 9e38daf..5727cae 100644
65487--- a/fs/ntfs/dir.c
65488+++ b/fs/ntfs/dir.c
65489@@ -1310,7 +1310,7 @@ find_next_index_buffer:
65490 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
65491 ~(s64)(ndir->itype.index.block_size - 1)));
65492 /* Bounds checks. */
65493- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65494+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65495 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
65496 "inode 0x%lx or driver bug.", vdir->i_ino);
65497 goto err_out;
65498diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
65499index f5ec1ce..807fd78 100644
65500--- a/fs/ntfs/file.c
65501+++ b/fs/ntfs/file.c
65502@@ -1279,7 +1279,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
65503 char *addr;
65504 size_t total = 0;
65505 unsigned len;
65506- int left;
65507+ unsigned left;
65508
65509 do {
65510 len = PAGE_CACHE_SIZE - ofs;
65511diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
65512index 6c3296e..c0b99f0 100644
65513--- a/fs/ntfs/super.c
65514+++ b/fs/ntfs/super.c
65515@@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65516 if (!silent)
65517 ntfs_error(sb, "Primary boot sector is invalid.");
65518 } else if (!silent)
65519- ntfs_error(sb, read_err_str, "primary");
65520+ ntfs_error(sb, read_err_str, "%s", "primary");
65521 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
65522 if (bh_primary)
65523 brelse(bh_primary);
65524@@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65525 goto hotfix_primary_boot_sector;
65526 brelse(bh_backup);
65527 } else if (!silent)
65528- ntfs_error(sb, read_err_str, "backup");
65529+ ntfs_error(sb, read_err_str, "%s", "backup");
65530 /* Try to read NT3.51- backup boot sector. */
65531 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
65532 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
65533@@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65534 "sector.");
65535 brelse(bh_backup);
65536 } else if (!silent)
65537- ntfs_error(sb, read_err_str, "backup");
65538+ ntfs_error(sb, read_err_str, "%s", "backup");
65539 /* We failed. Cleanup and return. */
65540 if (bh_primary)
65541 brelse(bh_primary);
65542diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
65543index 0440134..d52c93a 100644
65544--- a/fs/ocfs2/localalloc.c
65545+++ b/fs/ocfs2/localalloc.c
65546@@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
65547 goto bail;
65548 }
65549
65550- atomic_inc(&osb->alloc_stats.moves);
65551+ atomic_inc_unchecked(&osb->alloc_stats.moves);
65552
65553 bail:
65554 if (handle)
65555diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
65556index 8add6f1..b931e04 100644
65557--- a/fs/ocfs2/namei.c
65558+++ b/fs/ocfs2/namei.c
65559@@ -158,7 +158,7 @@ bail_add:
65560 * NOTE: This dentry already has ->d_op set from
65561 * ocfs2_get_parent() and ocfs2_get_dentry()
65562 */
65563- if (ret)
65564+ if (!IS_ERR_OR_NULL(ret))
65565 dentry = ret;
65566
65567 status = ocfs2_dentry_attach_lock(dentry, inode,
65568diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
65569index bbec539..7b266d5 100644
65570--- a/fs/ocfs2/ocfs2.h
65571+++ b/fs/ocfs2/ocfs2.h
65572@@ -236,11 +236,11 @@ enum ocfs2_vol_state
65573
65574 struct ocfs2_alloc_stats
65575 {
65576- atomic_t moves;
65577- atomic_t local_data;
65578- atomic_t bitmap_data;
65579- atomic_t bg_allocs;
65580- atomic_t bg_extends;
65581+ atomic_unchecked_t moves;
65582+ atomic_unchecked_t local_data;
65583+ atomic_unchecked_t bitmap_data;
65584+ atomic_unchecked_t bg_allocs;
65585+ atomic_unchecked_t bg_extends;
65586 };
65587
65588 enum ocfs2_local_alloc_state
65589diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
65590index 0cb889a..6a26b24 100644
65591--- a/fs/ocfs2/suballoc.c
65592+++ b/fs/ocfs2/suballoc.c
65593@@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
65594 mlog_errno(status);
65595 goto bail;
65596 }
65597- atomic_inc(&osb->alloc_stats.bg_extends);
65598+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
65599
65600 /* You should never ask for this much metadata */
65601 BUG_ON(bits_wanted >
65602@@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
65603 mlog_errno(status);
65604 goto bail;
65605 }
65606- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65607+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65608
65609 *suballoc_loc = res.sr_bg_blkno;
65610 *suballoc_bit_start = res.sr_bit_offset;
65611@@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
65612 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
65613 res->sr_bits);
65614
65615- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65616+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65617
65618 BUG_ON(res->sr_bits != 1);
65619
65620@@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
65621 mlog_errno(status);
65622 goto bail;
65623 }
65624- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65625+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65626
65627 BUG_ON(res.sr_bits != 1);
65628
65629@@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
65630 cluster_start,
65631 num_clusters);
65632 if (!status)
65633- atomic_inc(&osb->alloc_stats.local_data);
65634+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
65635 } else {
65636 if (min_clusters > (osb->bitmap_cpg - 1)) {
65637 /* The only paths asking for contiguousness
65638@@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
65639 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
65640 res.sr_bg_blkno,
65641 res.sr_bit_offset);
65642- atomic_inc(&osb->alloc_stats.bitmap_data);
65643+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
65644 *num_clusters = res.sr_bits;
65645 }
65646 }
65647diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
65648index 4142546..69375a9 100644
65649--- a/fs/ocfs2/super.c
65650+++ b/fs/ocfs2/super.c
65651@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
65652 "%10s => GlobalAllocs: %d LocalAllocs: %d "
65653 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
65654 "Stats",
65655- atomic_read(&osb->alloc_stats.bitmap_data),
65656- atomic_read(&osb->alloc_stats.local_data),
65657- atomic_read(&osb->alloc_stats.bg_allocs),
65658- atomic_read(&osb->alloc_stats.moves),
65659- atomic_read(&osb->alloc_stats.bg_extends));
65660+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
65661+ atomic_read_unchecked(&osb->alloc_stats.local_data),
65662+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
65663+ atomic_read_unchecked(&osb->alloc_stats.moves),
65664+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
65665
65666 out += snprintf(buf + out, len - out,
65667 "%10s => State: %u Descriptor: %llu Size: %u bits "
65668@@ -2100,11 +2100,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
65669
65670 mutex_init(&osb->system_file_mutex);
65671
65672- atomic_set(&osb->alloc_stats.moves, 0);
65673- atomic_set(&osb->alloc_stats.local_data, 0);
65674- atomic_set(&osb->alloc_stats.bitmap_data, 0);
65675- atomic_set(&osb->alloc_stats.bg_allocs, 0);
65676- atomic_set(&osb->alloc_stats.bg_extends, 0);
65677+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
65678+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
65679+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
65680+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
65681+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
65682
65683 /* Copy the blockcheck stats from the superblock probe */
65684 osb->osb_ecc_stats = *stats;
65685diff --git a/fs/open.c b/fs/open.c
65686index d6fd3ac..6ccf474 100644
65687--- a/fs/open.c
65688+++ b/fs/open.c
65689@@ -32,6 +32,8 @@
65690 #include <linux/dnotify.h>
65691 #include <linux/compat.h>
65692
65693+#define CREATE_TRACE_POINTS
65694+#include <trace/events/fs.h>
65695 #include "internal.h"
65696
65697 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
65698@@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
65699 error = locks_verify_truncate(inode, NULL, length);
65700 if (!error)
65701 error = security_path_truncate(path);
65702+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
65703+ error = -EACCES;
65704 if (!error)
65705 error = do_truncate(path->dentry, length, 0, NULL);
65706
65707@@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
65708 error = locks_verify_truncate(inode, f.file, length);
65709 if (!error)
65710 error = security_path_truncate(&f.file->f_path);
65711+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
65712+ error = -EACCES;
65713 if (!error)
65714 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
65715 sb_end_write(inode->i_sb);
65716@@ -380,6 +386,9 @@ retry:
65717 if (__mnt_is_readonly(path.mnt))
65718 res = -EROFS;
65719
65720+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
65721+ res = -EACCES;
65722+
65723 out_path_release:
65724 path_put(&path);
65725 if (retry_estale(res, lookup_flags)) {
65726@@ -411,6 +420,8 @@ retry:
65727 if (error)
65728 goto dput_and_out;
65729
65730+ gr_log_chdir(path.dentry, path.mnt);
65731+
65732 set_fs_pwd(current->fs, &path);
65733
65734 dput_and_out:
65735@@ -440,6 +451,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
65736 goto out_putf;
65737
65738 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
65739+
65740+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
65741+ error = -EPERM;
65742+
65743+ if (!error)
65744+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
65745+
65746 if (!error)
65747 set_fs_pwd(current->fs, &f.file->f_path);
65748 out_putf:
65749@@ -469,7 +487,13 @@ retry:
65750 if (error)
65751 goto dput_and_out;
65752
65753+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
65754+ goto dput_and_out;
65755+
65756 set_fs_root(current->fs, &path);
65757+
65758+ gr_handle_chroot_chdir(&path);
65759+
65760 error = 0;
65761 dput_and_out:
65762 path_put(&path);
65763@@ -493,6 +517,16 @@ static int chmod_common(struct path *path, umode_t mode)
65764 return error;
65765 retry_deleg:
65766 mutex_lock(&inode->i_mutex);
65767+
65768+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
65769+ error = -EACCES;
65770+ goto out_unlock;
65771+ }
65772+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
65773+ error = -EACCES;
65774+ goto out_unlock;
65775+ }
65776+
65777 error = security_path_chmod(path, mode);
65778 if (error)
65779 goto out_unlock;
65780@@ -558,6 +592,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
65781 uid = make_kuid(current_user_ns(), user);
65782 gid = make_kgid(current_user_ns(), group);
65783
65784+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
65785+ return -EACCES;
65786+
65787 newattrs.ia_valid = ATTR_CTIME;
65788 if (user != (uid_t) -1) {
65789 if (!uid_valid(uid))
65790@@ -983,6 +1020,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
65791 } else {
65792 fsnotify_open(f);
65793 fd_install(fd, f);
65794+ trace_do_sys_open(tmp->name, flags, mode);
65795 }
65796 }
65797 putname(tmp);
65798diff --git a/fs/pipe.c b/fs/pipe.c
65799index 21981e5..3d5f55c 100644
65800--- a/fs/pipe.c
65801+++ b/fs/pipe.c
65802@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
65803
65804 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
65805 {
65806- if (pipe->files)
65807+ if (atomic_read(&pipe->files))
65808 mutex_lock_nested(&pipe->mutex, subclass);
65809 }
65810
65811@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
65812
65813 void pipe_unlock(struct pipe_inode_info *pipe)
65814 {
65815- if (pipe->files)
65816+ if (atomic_read(&pipe->files))
65817 mutex_unlock(&pipe->mutex);
65818 }
65819 EXPORT_SYMBOL(pipe_unlock);
65820@@ -292,9 +292,9 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
65821 }
65822 if (bufs) /* More to do? */
65823 continue;
65824- if (!pipe->writers)
65825+ if (!atomic_read(&pipe->writers))
65826 break;
65827- if (!pipe->waiting_writers) {
65828+ if (!atomic_read(&pipe->waiting_writers)) {
65829 /* syscall merging: Usually we must not sleep
65830 * if O_NONBLOCK is set, or if we got some data.
65831 * But if a writer sleeps in kernel space, then
65832@@ -351,7 +351,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65833
65834 __pipe_lock(pipe);
65835
65836- if (!pipe->readers) {
65837+ if (!atomic_read(&pipe->readers)) {
65838 send_sig(SIGPIPE, current, 0);
65839 ret = -EPIPE;
65840 goto out;
65841@@ -387,7 +387,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65842 for (;;) {
65843 int bufs;
65844
65845- if (!pipe->readers) {
65846+ if (!atomic_read(&pipe->readers)) {
65847 send_sig(SIGPIPE, current, 0);
65848 if (!ret)
65849 ret = -EPIPE;
65850@@ -455,9 +455,9 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65851 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65852 do_wakeup = 0;
65853 }
65854- pipe->waiting_writers++;
65855+ atomic_inc(&pipe->waiting_writers);
65856 pipe_wait(pipe);
65857- pipe->waiting_writers--;
65858+ atomic_dec(&pipe->waiting_writers);
65859 }
65860 out:
65861 __pipe_unlock(pipe);
65862@@ -512,7 +512,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65863 mask = 0;
65864 if (filp->f_mode & FMODE_READ) {
65865 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
65866- if (!pipe->writers && filp->f_version != pipe->w_counter)
65867+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
65868 mask |= POLLHUP;
65869 }
65870
65871@@ -522,7 +522,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65872 * Most Unices do not set POLLERR for FIFOs but on Linux they
65873 * behave exactly like pipes for poll().
65874 */
65875- if (!pipe->readers)
65876+ if (!atomic_read(&pipe->readers))
65877 mask |= POLLERR;
65878 }
65879
65880@@ -534,7 +534,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
65881 int kill = 0;
65882
65883 spin_lock(&inode->i_lock);
65884- if (!--pipe->files) {
65885+ if (atomic_dec_and_test(&pipe->files)) {
65886 inode->i_pipe = NULL;
65887 kill = 1;
65888 }
65889@@ -551,11 +551,11 @@ pipe_release(struct inode *inode, struct file *file)
65890
65891 __pipe_lock(pipe);
65892 if (file->f_mode & FMODE_READ)
65893- pipe->readers--;
65894+ atomic_dec(&pipe->readers);
65895 if (file->f_mode & FMODE_WRITE)
65896- pipe->writers--;
65897+ atomic_dec(&pipe->writers);
65898
65899- if (pipe->readers || pipe->writers) {
65900+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
65901 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
65902 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65903 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
65904@@ -620,7 +620,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
65905 kfree(pipe);
65906 }
65907
65908-static struct vfsmount *pipe_mnt __read_mostly;
65909+struct vfsmount *pipe_mnt __read_mostly;
65910
65911 /*
65912 * pipefs_dname() is called from d_path().
65913@@ -650,8 +650,9 @@ static struct inode * get_pipe_inode(void)
65914 goto fail_iput;
65915
65916 inode->i_pipe = pipe;
65917- pipe->files = 2;
65918- pipe->readers = pipe->writers = 1;
65919+ atomic_set(&pipe->files, 2);
65920+ atomic_set(&pipe->readers, 1);
65921+ atomic_set(&pipe->writers, 1);
65922 inode->i_fop = &pipefifo_fops;
65923
65924 /*
65925@@ -830,17 +831,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
65926 spin_lock(&inode->i_lock);
65927 if (inode->i_pipe) {
65928 pipe = inode->i_pipe;
65929- pipe->files++;
65930+ atomic_inc(&pipe->files);
65931 spin_unlock(&inode->i_lock);
65932 } else {
65933 spin_unlock(&inode->i_lock);
65934 pipe = alloc_pipe_info();
65935 if (!pipe)
65936 return -ENOMEM;
65937- pipe->files = 1;
65938+ atomic_set(&pipe->files, 1);
65939 spin_lock(&inode->i_lock);
65940 if (unlikely(inode->i_pipe)) {
65941- inode->i_pipe->files++;
65942+ atomic_inc(&inode->i_pipe->files);
65943 spin_unlock(&inode->i_lock);
65944 free_pipe_info(pipe);
65945 pipe = inode->i_pipe;
65946@@ -865,10 +866,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
65947 * opened, even when there is no process writing the FIFO.
65948 */
65949 pipe->r_counter++;
65950- if (pipe->readers++ == 0)
65951+ if (atomic_inc_return(&pipe->readers) == 1)
65952 wake_up_partner(pipe);
65953
65954- if (!is_pipe && !pipe->writers) {
65955+ if (!is_pipe && !atomic_read(&pipe->writers)) {
65956 if ((filp->f_flags & O_NONBLOCK)) {
65957 /* suppress POLLHUP until we have
65958 * seen a writer */
65959@@ -887,14 +888,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
65960 * errno=ENXIO when there is no process reading the FIFO.
65961 */
65962 ret = -ENXIO;
65963- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
65964+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
65965 goto err;
65966
65967 pipe->w_counter++;
65968- if (!pipe->writers++)
65969+ if (atomic_inc_return(&pipe->writers) == 1)
65970 wake_up_partner(pipe);
65971
65972- if (!is_pipe && !pipe->readers) {
65973+ if (!is_pipe && !atomic_read(&pipe->readers)) {
65974 if (wait_for_partner(pipe, &pipe->r_counter))
65975 goto err_wr;
65976 }
65977@@ -908,11 +909,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
65978 * the process can at least talk to itself.
65979 */
65980
65981- pipe->readers++;
65982- pipe->writers++;
65983+ atomic_inc(&pipe->readers);
65984+ atomic_inc(&pipe->writers);
65985 pipe->r_counter++;
65986 pipe->w_counter++;
65987- if (pipe->readers == 1 || pipe->writers == 1)
65988+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
65989 wake_up_partner(pipe);
65990 break;
65991
65992@@ -926,13 +927,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
65993 return 0;
65994
65995 err_rd:
65996- if (!--pipe->readers)
65997+ if (atomic_dec_and_test(&pipe->readers))
65998 wake_up_interruptible(&pipe->wait);
65999 ret = -ERESTARTSYS;
66000 goto err;
66001
66002 err_wr:
66003- if (!--pipe->writers)
66004+ if (atomic_dec_and_test(&pipe->writers))
66005 wake_up_interruptible(&pipe->wait);
66006 ret = -ERESTARTSYS;
66007 goto err;
66008diff --git a/fs/posix_acl.c b/fs/posix_acl.c
66009index 0855f77..6787d50 100644
66010--- a/fs/posix_acl.c
66011+++ b/fs/posix_acl.c
66012@@ -20,6 +20,7 @@
66013 #include <linux/xattr.h>
66014 #include <linux/export.h>
66015 #include <linux/user_namespace.h>
66016+#include <linux/grsecurity.h>
66017
66018 struct posix_acl **acl_by_type(struct inode *inode, int type)
66019 {
66020@@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
66021 }
66022 }
66023 if (mode_p)
66024- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
66025+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
66026 return not_equiv;
66027 }
66028 EXPORT_SYMBOL(posix_acl_equiv_mode);
66029@@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
66030 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
66031 }
66032
66033- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
66034+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
66035 return not_equiv;
66036 }
66037
66038@@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
66039 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
66040 int err = -ENOMEM;
66041 if (clone) {
66042+ *mode_p &= ~gr_acl_umask();
66043+
66044 err = posix_acl_create_masq(clone, mode_p);
66045 if (err < 0) {
66046 posix_acl_release(clone);
66047@@ -659,11 +662,12 @@ struct posix_acl *
66048 posix_acl_from_xattr(struct user_namespace *user_ns,
66049 const void *value, size_t size)
66050 {
66051- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
66052- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
66053+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
66054+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
66055 int count;
66056 struct posix_acl *acl;
66057 struct posix_acl_entry *acl_e;
66058+ umode_t umask = gr_acl_umask();
66059
66060 if (!value)
66061 return NULL;
66062@@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
66063
66064 switch(acl_e->e_tag) {
66065 case ACL_USER_OBJ:
66066+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
66067+ break;
66068 case ACL_GROUP_OBJ:
66069 case ACL_MASK:
66070+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
66071+ break;
66072 case ACL_OTHER:
66073+ acl_e->e_perm &= ~(umask & S_IRWXO);
66074 break;
66075
66076 case ACL_USER:
66077+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
66078 acl_e->e_uid =
66079 make_kuid(user_ns,
66080 le32_to_cpu(entry->e_id));
66081@@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
66082 goto fail;
66083 break;
66084 case ACL_GROUP:
66085+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
66086 acl_e->e_gid =
66087 make_kgid(user_ns,
66088 le32_to_cpu(entry->e_id));
66089diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
66090index 2183fcf..3c32a98 100644
66091--- a/fs/proc/Kconfig
66092+++ b/fs/proc/Kconfig
66093@@ -30,7 +30,7 @@ config PROC_FS
66094
66095 config PROC_KCORE
66096 bool "/proc/kcore support" if !ARM
66097- depends on PROC_FS && MMU
66098+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
66099 help
66100 Provides a virtual ELF core file of the live kernel. This can
66101 be read with gdb and other ELF tools. No modifications can be
66102@@ -38,8 +38,8 @@ config PROC_KCORE
66103
66104 config PROC_VMCORE
66105 bool "/proc/vmcore support"
66106- depends on PROC_FS && CRASH_DUMP
66107- default y
66108+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
66109+ default n
66110 help
66111 Exports the dump image of crashed kernel in ELF format.
66112
66113@@ -63,8 +63,8 @@ config PROC_SYSCTL
66114 limited in memory.
66115
66116 config PROC_PAGE_MONITOR
66117- default y
66118- depends on PROC_FS && MMU
66119+ default n
66120+ depends on PROC_FS && MMU && !GRKERNSEC
66121 bool "Enable /proc page monitoring" if EXPERT
66122 help
66123 Various /proc files exist to monitor process memory utilization:
66124diff --git a/fs/proc/array.c b/fs/proc/array.c
66125index cd3653e..9b9b79a 100644
66126--- a/fs/proc/array.c
66127+++ b/fs/proc/array.c
66128@@ -60,6 +60,7 @@
66129 #include <linux/tty.h>
66130 #include <linux/string.h>
66131 #include <linux/mman.h>
66132+#include <linux/grsecurity.h>
66133 #include <linux/proc_fs.h>
66134 #include <linux/ioport.h>
66135 #include <linux/uaccess.h>
66136@@ -347,6 +348,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
66137 seq_putc(m, '\n');
66138 }
66139
66140+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66141+static inline void task_pax(struct seq_file *m, struct task_struct *p)
66142+{
66143+ if (p->mm)
66144+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
66145+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
66146+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
66147+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
66148+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
66149+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
66150+ else
66151+ seq_printf(m, "PaX:\t-----\n");
66152+}
66153+#endif
66154+
66155 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
66156 struct pid *pid, struct task_struct *task)
66157 {
66158@@ -365,9 +381,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
66159 task_cpus_allowed(m, task);
66160 cpuset_task_status_allowed(m, task);
66161 task_context_switch_counts(m, task);
66162+
66163+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66164+ task_pax(m, task);
66165+#endif
66166+
66167+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
66168+ task_grsec_rbac(m, task);
66169+#endif
66170+
66171 return 0;
66172 }
66173
66174+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66175+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
66176+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
66177+ _mm->pax_flags & MF_PAX_SEGMEXEC))
66178+#endif
66179+
66180 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66181 struct pid *pid, struct task_struct *task, int whole)
66182 {
66183@@ -389,6 +420,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66184 char tcomm[sizeof(task->comm)];
66185 unsigned long flags;
66186
66187+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66188+ if (current->exec_id != m->exec_id) {
66189+ gr_log_badprocpid("stat");
66190+ return 0;
66191+ }
66192+#endif
66193+
66194 state = *get_task_state(task);
66195 vsize = eip = esp = 0;
66196 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
66197@@ -459,6 +497,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66198 gtime = task_gtime(task);
66199 }
66200
66201+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66202+ if (PAX_RAND_FLAGS(mm)) {
66203+ eip = 0;
66204+ esp = 0;
66205+ wchan = 0;
66206+ }
66207+#endif
66208+#ifdef CONFIG_GRKERNSEC_HIDESYM
66209+ wchan = 0;
66210+ eip =0;
66211+ esp =0;
66212+#endif
66213+
66214 /* scale priority and nice values from timeslices to -20..20 */
66215 /* to make it look like a "normal" Unix priority/nice value */
66216 priority = task_prio(task);
66217@@ -490,9 +541,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66218 seq_put_decimal_ull(m, ' ', vsize);
66219 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
66220 seq_put_decimal_ull(m, ' ', rsslim);
66221+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66222+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
66223+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
66224+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
66225+#else
66226 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
66227 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
66228 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
66229+#endif
66230 seq_put_decimal_ull(m, ' ', esp);
66231 seq_put_decimal_ull(m, ' ', eip);
66232 /* The signal information here is obsolete.
66233@@ -514,7 +571,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
66234 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
66235 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
66236
66237- if (mm && permitted) {
66238+ if (mm && permitted
66239+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66240+ && !PAX_RAND_FLAGS(mm)
66241+#endif
66242+ ) {
66243 seq_put_decimal_ull(m, ' ', mm->start_data);
66244 seq_put_decimal_ull(m, ' ', mm->end_data);
66245 seq_put_decimal_ull(m, ' ', mm->start_brk);
66246@@ -552,8 +613,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
66247 struct pid *pid, struct task_struct *task)
66248 {
66249 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
66250- struct mm_struct *mm = get_task_mm(task);
66251+ struct mm_struct *mm;
66252
66253+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66254+ if (current->exec_id != m->exec_id) {
66255+ gr_log_badprocpid("statm");
66256+ return 0;
66257+ }
66258+#endif
66259+ mm = get_task_mm(task);
66260 if (mm) {
66261 size = task_statm(mm, &shared, &text, &data, &resident);
66262 mmput(mm);
66263@@ -576,6 +644,20 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
66264 return 0;
66265 }
66266
66267+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66268+int proc_pid_ipaddr(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task)
66269+{
66270+ unsigned long flags;
66271+ u32 curr_ip = 0;
66272+
66273+ if (lock_task_sighand(task, &flags)) {
66274+ curr_ip = task->signal->curr_ip;
66275+ unlock_task_sighand(task, &flags);
66276+ }
66277+ return seq_printf(m, "%pI4\n", &curr_ip);
66278+}
66279+#endif
66280+
66281 #ifdef CONFIG_CHECKPOINT_RESTORE
66282 static struct pid *
66283 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
66284diff --git a/fs/proc/base.c b/fs/proc/base.c
66285index baf852b..03fe930 100644
66286--- a/fs/proc/base.c
66287+++ b/fs/proc/base.c
66288@@ -113,6 +113,14 @@ struct pid_entry {
66289 union proc_op op;
66290 };
66291
66292+struct getdents_callback {
66293+ struct linux_dirent __user * current_dir;
66294+ struct linux_dirent __user * previous;
66295+ struct file * file;
66296+ int count;
66297+ int error;
66298+};
66299+
66300 #define NOD(NAME, MODE, IOP, FOP, OP) { \
66301 .name = (NAME), \
66302 .len = sizeof(NAME) - 1, \
66303@@ -208,12 +216,28 @@ static int proc_pid_cmdline(struct seq_file *m, struct pid_namespace *ns,
66304 return 0;
66305 }
66306
66307+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66308+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
66309+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
66310+ _mm->pax_flags & MF_PAX_SEGMEXEC))
66311+#endif
66312+
66313 static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
66314 struct pid *pid, struct task_struct *task)
66315 {
66316 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
66317 if (mm && !IS_ERR(mm)) {
66318 unsigned int nwords = 0;
66319+
66320+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66321+ /* allow if we're currently ptracing this task */
66322+ if (PAX_RAND_FLAGS(mm) &&
66323+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
66324+ mmput(mm);
66325+ return 0;
66326+ }
66327+#endif
66328+
66329 do {
66330 nwords += 2;
66331 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
66332@@ -225,7 +249,7 @@ static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
66333 }
66334
66335
66336-#ifdef CONFIG_KALLSYMS
66337+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66338 /*
66339 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
66340 * Returns the resolved symbol. If that fails, simply return the address.
66341@@ -265,7 +289,7 @@ static void unlock_trace(struct task_struct *task)
66342 mutex_unlock(&task->signal->cred_guard_mutex);
66343 }
66344
66345-#ifdef CONFIG_STACKTRACE
66346+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66347
66348 #define MAX_STACK_TRACE_DEPTH 64
66349
66350@@ -487,7 +511,7 @@ static int proc_pid_limits(struct seq_file *m, struct pid_namespace *ns,
66351 return 0;
66352 }
66353
66354-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66355+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66356 static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
66357 struct pid *pid, struct task_struct *task)
66358 {
66359@@ -517,7 +541,7 @@ static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
66360 /************************************************************************/
66361
66362 /* permission checks */
66363-static int proc_fd_access_allowed(struct inode *inode)
66364+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
66365 {
66366 struct task_struct *task;
66367 int allowed = 0;
66368@@ -527,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
66369 */
66370 task = get_proc_task(inode);
66371 if (task) {
66372- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
66373+ if (log)
66374+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
66375+ else
66376+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
66377 put_task_struct(task);
66378 }
66379 return allowed;
66380@@ -558,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
66381 struct task_struct *task,
66382 int hide_pid_min)
66383 {
66384+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66385+ return false;
66386+
66387+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66388+ rcu_read_lock();
66389+ {
66390+ const struct cred *tmpcred = current_cred();
66391+ const struct cred *cred = __task_cred(task);
66392+
66393+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
66394+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66395+ || in_group_p(grsec_proc_gid)
66396+#endif
66397+ ) {
66398+ rcu_read_unlock();
66399+ return true;
66400+ }
66401+ }
66402+ rcu_read_unlock();
66403+
66404+ if (!pid->hide_pid)
66405+ return false;
66406+#endif
66407+
66408 if (pid->hide_pid < hide_pid_min)
66409 return true;
66410 if (in_group_p(pid->pid_gid))
66411 return true;
66412+
66413 return ptrace_may_access(task, PTRACE_MODE_READ);
66414 }
66415
66416@@ -579,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
66417 put_task_struct(task);
66418
66419 if (!has_perms) {
66420+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66421+ {
66422+#else
66423 if (pid->hide_pid == 2) {
66424+#endif
66425 /*
66426 * Let's make getdents(), stat(), and open()
66427 * consistent with each other. If a process
66428@@ -640,6 +696,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
66429 if (!task)
66430 return -ESRCH;
66431
66432+ if (gr_acl_handle_procpidmem(task)) {
66433+ put_task_struct(task);
66434+ return -EPERM;
66435+ }
66436+
66437 mm = mm_access(task, mode);
66438 put_task_struct(task);
66439
66440@@ -655,6 +716,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
66441
66442 file->private_data = mm;
66443
66444+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66445+ file->f_version = current->exec_id;
66446+#endif
66447+
66448 return 0;
66449 }
66450
66451@@ -676,6 +741,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66452 ssize_t copied;
66453 char *page;
66454
66455+#ifdef CONFIG_GRKERNSEC
66456+ if (write)
66457+ return -EPERM;
66458+#endif
66459+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66460+ if (file->f_version != current->exec_id) {
66461+ gr_log_badprocpid("mem");
66462+ return 0;
66463+ }
66464+#endif
66465+
66466 if (!mm)
66467 return 0;
66468
66469@@ -688,7 +764,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66470 goto free;
66471
66472 while (count > 0) {
66473- int this_len = min_t(int, count, PAGE_SIZE);
66474+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
66475
66476 if (write && copy_from_user(page, buf, this_len)) {
66477 copied = -EFAULT;
66478@@ -780,6 +856,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66479 if (!mm)
66480 return 0;
66481
66482+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66483+ if (file->f_version != current->exec_id) {
66484+ gr_log_badprocpid("environ");
66485+ return 0;
66486+ }
66487+#endif
66488+
66489 page = (char *)__get_free_page(GFP_TEMPORARY);
66490 if (!page)
66491 return -ENOMEM;
66492@@ -789,7 +872,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66493 goto free;
66494 while (count > 0) {
66495 size_t this_len, max_len;
66496- int retval;
66497+ ssize_t retval;
66498
66499 if (src >= (mm->env_end - mm->env_start))
66500 break;
66501@@ -1403,7 +1486,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
66502 int error = -EACCES;
66503
66504 /* Are we allowed to snoop on the tasks file descriptors? */
66505- if (!proc_fd_access_allowed(inode))
66506+ if (!proc_fd_access_allowed(inode, 0))
66507 goto out;
66508
66509 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
66510@@ -1447,8 +1530,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
66511 struct path path;
66512
66513 /* Are we allowed to snoop on the tasks file descriptors? */
66514- if (!proc_fd_access_allowed(inode))
66515- goto out;
66516+ /* logging this is needed for learning on chromium to work properly,
66517+ but we don't want to flood the logs from 'ps' which does a readlink
66518+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
66519+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
66520+ */
66521+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
66522+ if (!proc_fd_access_allowed(inode,0))
66523+ goto out;
66524+ } else {
66525+ if (!proc_fd_access_allowed(inode,1))
66526+ goto out;
66527+ }
66528
66529 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
66530 if (error)
66531@@ -1498,7 +1591,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
66532 rcu_read_lock();
66533 cred = __task_cred(task);
66534 inode->i_uid = cred->euid;
66535+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66536+ inode->i_gid = grsec_proc_gid;
66537+#else
66538 inode->i_gid = cred->egid;
66539+#endif
66540 rcu_read_unlock();
66541 }
66542 security_task_to_inode(task, inode);
66543@@ -1534,10 +1631,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
66544 return -ENOENT;
66545 }
66546 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
66547+#ifdef CONFIG_GRKERNSEC_PROC_USER
66548+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
66549+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66550+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
66551+#endif
66552 task_dumpable(task)) {
66553 cred = __task_cred(task);
66554 stat->uid = cred->euid;
66555+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66556+ stat->gid = grsec_proc_gid;
66557+#else
66558 stat->gid = cred->egid;
66559+#endif
66560 }
66561 }
66562 rcu_read_unlock();
66563@@ -1575,11 +1681,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
66564
66565 if (task) {
66566 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
66567+#ifdef CONFIG_GRKERNSEC_PROC_USER
66568+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
66569+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66570+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
66571+#endif
66572 task_dumpable(task)) {
66573 rcu_read_lock();
66574 cred = __task_cred(task);
66575 inode->i_uid = cred->euid;
66576+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66577+ inode->i_gid = grsec_proc_gid;
66578+#else
66579 inode->i_gid = cred->egid;
66580+#endif
66581 rcu_read_unlock();
66582 } else {
66583 inode->i_uid = GLOBAL_ROOT_UID;
66584@@ -2114,6 +2229,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
66585 if (!task)
66586 goto out_no_task;
66587
66588+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66589+ goto out;
66590+
66591 /*
66592 * Yes, it does not scale. And it should not. Don't add
66593 * new entries into /proc/<tgid>/ without very good reasons.
66594@@ -2144,6 +2262,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
66595 if (!task)
66596 return -ENOENT;
66597
66598+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66599+ goto out;
66600+
66601 if (!dir_emit_dots(file, ctx))
66602 goto out;
66603
66604@@ -2535,7 +2656,7 @@ static const struct pid_entry tgid_base_stuff[] = {
66605 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
66606 #endif
66607 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
66608-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66609+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66610 ONE("syscall", S_IRUSR, proc_pid_syscall),
66611 #endif
66612 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
66613@@ -2560,10 +2681,10 @@ static const struct pid_entry tgid_base_stuff[] = {
66614 #ifdef CONFIG_SECURITY
66615 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
66616 #endif
66617-#ifdef CONFIG_KALLSYMS
66618+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66619 ONE("wchan", S_IRUGO, proc_pid_wchan),
66620 #endif
66621-#ifdef CONFIG_STACKTRACE
66622+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66623 ONE("stack", S_IRUSR, proc_pid_stack),
66624 #endif
66625 #ifdef CONFIG_SCHEDSTATS
66626@@ -2597,6 +2718,9 @@ static const struct pid_entry tgid_base_stuff[] = {
66627 #ifdef CONFIG_HARDWALL
66628 ONE("hardwall", S_IRUGO, proc_pid_hardwall),
66629 #endif
66630+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66631+ ONE("ipaddr", S_IRUSR, proc_pid_ipaddr),
66632+#endif
66633 #ifdef CONFIG_USER_NS
66634 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
66635 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
66636@@ -2727,7 +2851,14 @@ static int proc_pid_instantiate(struct inode *dir,
66637 if (!inode)
66638 goto out;
66639
66640+#ifdef CONFIG_GRKERNSEC_PROC_USER
66641+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
66642+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66643+ inode->i_gid = grsec_proc_gid;
66644+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
66645+#else
66646 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
66647+#endif
66648 inode->i_op = &proc_tgid_base_inode_operations;
66649 inode->i_fop = &proc_tgid_base_operations;
66650 inode->i_flags|=S_IMMUTABLE;
66651@@ -2765,7 +2896,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
66652 if (!task)
66653 goto out;
66654
66655+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66656+ goto out_put_task;
66657+
66658 result = proc_pid_instantiate(dir, dentry, task, NULL);
66659+out_put_task:
66660 put_task_struct(task);
66661 out:
66662 return ERR_PTR(result);
66663@@ -2879,7 +3014,7 @@ static const struct pid_entry tid_base_stuff[] = {
66664 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
66665 #endif
66666 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
66667-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66668+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66669 ONE("syscall", S_IRUSR, proc_pid_syscall),
66670 #endif
66671 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
66672@@ -2906,10 +3041,10 @@ static const struct pid_entry tid_base_stuff[] = {
66673 #ifdef CONFIG_SECURITY
66674 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
66675 #endif
66676-#ifdef CONFIG_KALLSYMS
66677+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66678 ONE("wchan", S_IRUGO, proc_pid_wchan),
66679 #endif
66680-#ifdef CONFIG_STACKTRACE
66681+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66682 ONE("stack", S_IRUSR, proc_pid_stack),
66683 #endif
66684 #ifdef CONFIG_SCHEDSTATS
66685diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
66686index cbd82df..c0407d2 100644
66687--- a/fs/proc/cmdline.c
66688+++ b/fs/proc/cmdline.c
66689@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
66690
66691 static int __init proc_cmdline_init(void)
66692 {
66693+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66694+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
66695+#else
66696 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
66697+#endif
66698 return 0;
66699 }
66700 fs_initcall(proc_cmdline_init);
66701diff --git a/fs/proc/devices.c b/fs/proc/devices.c
66702index 50493ed..248166b 100644
66703--- a/fs/proc/devices.c
66704+++ b/fs/proc/devices.c
66705@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
66706
66707 static int __init proc_devices_init(void)
66708 {
66709+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66710+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
66711+#else
66712 proc_create("devices", 0, NULL, &proc_devinfo_operations);
66713+#endif
66714 return 0;
66715 }
66716 fs_initcall(proc_devices_init);
66717diff --git a/fs/proc/fd.c b/fs/proc/fd.c
66718index 955bb55..71948bd 100644
66719--- a/fs/proc/fd.c
66720+++ b/fs/proc/fd.c
66721@@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
66722 if (!task)
66723 return -ENOENT;
66724
66725- files = get_files_struct(task);
66726+ if (!gr_acl_handle_procpidmem(task))
66727+ files = get_files_struct(task);
66728 put_task_struct(task);
66729
66730 if (files) {
66731@@ -285,11 +286,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
66732 */
66733 int proc_fd_permission(struct inode *inode, int mask)
66734 {
66735+ struct task_struct *task;
66736 int rv = generic_permission(inode, mask);
66737- if (rv == 0)
66738- return 0;
66739+
66740 if (task_tgid(current) == proc_pid(inode))
66741 rv = 0;
66742+
66743+ task = get_proc_task(inode);
66744+ if (task == NULL)
66745+ return rv;
66746+
66747+ if (gr_acl_handle_procpidmem(task))
66748+ rv = -EACCES;
66749+
66750+ put_task_struct(task);
66751+
66752 return rv;
66753 }
66754
66755diff --git a/fs/proc/generic.c b/fs/proc/generic.c
66756index 317b726..e329aed 100644
66757--- a/fs/proc/generic.c
66758+++ b/fs/proc/generic.c
66759@@ -23,6 +23,7 @@
66760 #include <linux/bitops.h>
66761 #include <linux/spinlock.h>
66762 #include <linux/completion.h>
66763+#include <linux/grsecurity.h>
66764 #include <asm/uaccess.h>
66765
66766 #include "internal.h"
66767@@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
66768 return proc_lookup_de(PDE(dir), dir, dentry);
66769 }
66770
66771+struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
66772+ unsigned int flags)
66773+{
66774+ if (gr_proc_is_restricted())
66775+ return ERR_PTR(-EACCES);
66776+
66777+ return proc_lookup_de(PDE(dir), dir, dentry);
66778+}
66779+
66780 /*
66781 * This returns non-zero if at EOF, so that the /proc
66782 * root directory can use this and check if it should
66783@@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
66784 return proc_readdir_de(PDE(inode), file, ctx);
66785 }
66786
66787+int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
66788+{
66789+ struct inode *inode = file_inode(file);
66790+
66791+ if (gr_proc_is_restricted())
66792+ return -EACCES;
66793+
66794+ return proc_readdir_de(PDE(inode), file, ctx);
66795+}
66796+
66797 /*
66798 * These are the generic /proc directory operations. They
66799 * use the in-memory "struct proc_dir_entry" tree to parse
66800@@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
66801 .iterate = proc_readdir,
66802 };
66803
66804+static const struct file_operations proc_dir_restricted_operations = {
66805+ .llseek = generic_file_llseek,
66806+ .read = generic_read_dir,
66807+ .iterate = proc_readdir_restrict,
66808+};
66809+
66810 /*
66811 * proc directories can do almost nothing..
66812 */
66813@@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
66814 .setattr = proc_notify_change,
66815 };
66816
66817+static const struct inode_operations proc_dir_restricted_inode_operations = {
66818+ .lookup = proc_lookup_restrict,
66819+ .getattr = proc_getattr,
66820+ .setattr = proc_notify_change,
66821+};
66822+
66823 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
66824 {
66825 struct proc_dir_entry *tmp;
66826@@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
66827 return ret;
66828
66829 if (S_ISDIR(dp->mode)) {
66830- dp->proc_fops = &proc_dir_operations;
66831- dp->proc_iops = &proc_dir_inode_operations;
66832+ if (dp->restricted) {
66833+ dp->proc_fops = &proc_dir_restricted_operations;
66834+ dp->proc_iops = &proc_dir_restricted_inode_operations;
66835+ } else {
66836+ dp->proc_fops = &proc_dir_operations;
66837+ dp->proc_iops = &proc_dir_inode_operations;
66838+ }
66839 dir->nlink++;
66840 } else if (S_ISLNK(dp->mode)) {
66841 dp->proc_iops = &proc_link_inode_operations;
66842@@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
66843 }
66844 EXPORT_SYMBOL_GPL(proc_mkdir_data);
66845
66846+struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
66847+ struct proc_dir_entry *parent, void *data)
66848+{
66849+ struct proc_dir_entry *ent;
66850+
66851+ if (mode == 0)
66852+ mode = S_IRUGO | S_IXUGO;
66853+
66854+ ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
66855+ if (ent) {
66856+ ent->data = data;
66857+ ent->restricted = 1;
66858+ if (proc_register(parent, ent) < 0) {
66859+ kfree(ent);
66860+ ent = NULL;
66861+ }
66862+ }
66863+ return ent;
66864+}
66865+EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
66866+
66867 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
66868 struct proc_dir_entry *parent)
66869 {
66870@@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
66871 }
66872 EXPORT_SYMBOL(proc_mkdir);
66873
66874+struct proc_dir_entry *proc_mkdir_restrict(const char *name,
66875+ struct proc_dir_entry *parent)
66876+{
66877+ return proc_mkdir_data_restrict(name, 0, parent, NULL);
66878+}
66879+EXPORT_SYMBOL(proc_mkdir_restrict);
66880+
66881 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
66882 struct proc_dir_entry *parent,
66883 const struct file_operations *proc_fops,
66884diff --git a/fs/proc/inode.c b/fs/proc/inode.c
66885index 333080d..0a35ec4 100644
66886--- a/fs/proc/inode.c
66887+++ b/fs/proc/inode.c
66888@@ -23,11 +23,17 @@
66889 #include <linux/slab.h>
66890 #include <linux/mount.h>
66891 #include <linux/magic.h>
66892+#include <linux/grsecurity.h>
66893
66894 #include <asm/uaccess.h>
66895
66896 #include "internal.h"
66897
66898+#ifdef CONFIG_PROC_SYSCTL
66899+extern const struct inode_operations proc_sys_inode_operations;
66900+extern const struct inode_operations proc_sys_dir_operations;
66901+#endif
66902+
66903 static void proc_evict_inode(struct inode *inode)
66904 {
66905 struct proc_dir_entry *de;
66906@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
66907 ns = PROC_I(inode)->ns.ns;
66908 if (ns_ops && ns)
66909 ns_ops->put(ns);
66910+
66911+#ifdef CONFIG_PROC_SYSCTL
66912+ if (inode->i_op == &proc_sys_inode_operations ||
66913+ inode->i_op == &proc_sys_dir_operations)
66914+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
66915+#endif
66916+
66917 }
66918
66919 static struct kmem_cache * proc_inode_cachep;
66920@@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
66921 if (de->mode) {
66922 inode->i_mode = de->mode;
66923 inode->i_uid = de->uid;
66924+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66925+ inode->i_gid = grsec_proc_gid;
66926+#else
66927 inode->i_gid = de->gid;
66928+#endif
66929 }
66930 if (de->size)
66931 inode->i_size = de->size;
66932diff --git a/fs/proc/internal.h b/fs/proc/internal.h
66933index 7da13e4..68d0981 100644
66934--- a/fs/proc/internal.h
66935+++ b/fs/proc/internal.h
66936@@ -46,9 +46,10 @@ struct proc_dir_entry {
66937 struct completion *pde_unload_completion;
66938 struct list_head pde_openers; /* who did ->open, but not ->release */
66939 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
66940+ u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
66941 u8 namelen;
66942 char name[];
66943-};
66944+} __randomize_layout;
66945
66946 union proc_op {
66947 int (*proc_get_link)(struct dentry *, struct path *);
66948@@ -66,7 +67,7 @@ struct proc_inode {
66949 struct ctl_table *sysctl_entry;
66950 struct proc_ns ns;
66951 struct inode vfs_inode;
66952-};
66953+} __randomize_layout;
66954
66955 /*
66956 * General functions
66957@@ -154,6 +155,10 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
66958 struct pid *, struct task_struct *);
66959 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
66960 struct pid *, struct task_struct *);
66961+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66962+extern int proc_pid_ipaddr(struct seq_file *, struct pid_namespace *,
66963+ struct pid *, struct task_struct *);
66964+#endif
66965
66966 /*
66967 * base.c
66968@@ -178,9 +183,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
66969 * generic.c
66970 */
66971 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
66972+extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
66973 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
66974 struct dentry *);
66975 extern int proc_readdir(struct file *, struct dir_context *);
66976+extern int proc_readdir_restrict(struct file *, struct dir_context *);
66977 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
66978
66979 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
66980diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
66981index a352d57..cb94a5c 100644
66982--- a/fs/proc/interrupts.c
66983+++ b/fs/proc/interrupts.c
66984@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
66985
66986 static int __init proc_interrupts_init(void)
66987 {
66988+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66989+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
66990+#else
66991 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
66992+#endif
66993 return 0;
66994 }
66995 fs_initcall(proc_interrupts_init);
66996diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
66997index 6df8d07..3321060 100644
66998--- a/fs/proc/kcore.c
66999+++ b/fs/proc/kcore.c
67000@@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
67001 * the addresses in the elf_phdr on our list.
67002 */
67003 start = kc_offset_to_vaddr(*fpos - elf_buflen);
67004- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
67005+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
67006+ if (tsz > buflen)
67007 tsz = buflen;
67008-
67009+
67010 while (buflen) {
67011 struct kcore_list *m;
67012
67013@@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
67014 kfree(elf_buf);
67015 } else {
67016 if (kern_addr_valid(start)) {
67017- unsigned long n;
67018+ char *elf_buf;
67019+ mm_segment_t oldfs;
67020
67021- n = copy_to_user(buffer, (char *)start, tsz);
67022- /*
67023- * We cannot distinguish between fault on source
67024- * and fault on destination. When this happens
67025- * we clear too and hope it will trigger the
67026- * EFAULT again.
67027- */
67028- if (n) {
67029- if (clear_user(buffer + tsz - n,
67030- n))
67031+ elf_buf = kmalloc(tsz, GFP_KERNEL);
67032+ if (!elf_buf)
67033+ return -ENOMEM;
67034+ oldfs = get_fs();
67035+ set_fs(KERNEL_DS);
67036+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
67037+ set_fs(oldfs);
67038+ if (copy_to_user(buffer, elf_buf, tsz)) {
67039+ kfree(elf_buf);
67040 return -EFAULT;
67041+ }
67042 }
67043+ set_fs(oldfs);
67044+ kfree(elf_buf);
67045 } else {
67046 if (clear_user(buffer, tsz))
67047 return -EFAULT;
67048@@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
67049
67050 static int open_kcore(struct inode *inode, struct file *filp)
67051 {
67052+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
67053+ return -EPERM;
67054+#endif
67055 if (!capable(CAP_SYS_RAWIO))
67056 return -EPERM;
67057 if (kcore_need_update)
67058diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
67059index aa1eee0..03dda72 100644
67060--- a/fs/proc/meminfo.c
67061+++ b/fs/proc/meminfo.c
67062@@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
67063 vmi.used >> 10,
67064 vmi.largest_chunk >> 10
67065 #ifdef CONFIG_MEMORY_FAILURE
67066- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
67067+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
67068 #endif
67069 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
67070 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
67071diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
67072index d4a3574..b421ce9 100644
67073--- a/fs/proc/nommu.c
67074+++ b/fs/proc/nommu.c
67075@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
67076
67077 if (file) {
67078 seq_pad(m, ' ');
67079- seq_path(m, &file->f_path, "");
67080+ seq_path(m, &file->f_path, "\n\\");
67081 }
67082
67083 seq_putc(m, '\n');
67084diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
67085index a63af3e..b4f262a 100644
67086--- a/fs/proc/proc_net.c
67087+++ b/fs/proc/proc_net.c
67088@@ -23,9 +23,27 @@
67089 #include <linux/nsproxy.h>
67090 #include <net/net_namespace.h>
67091 #include <linux/seq_file.h>
67092+#include <linux/grsecurity.h>
67093
67094 #include "internal.h"
67095
67096+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
67097+static struct seq_operations *ipv6_seq_ops_addr;
67098+
67099+void register_ipv6_seq_ops_addr(struct seq_operations *addr)
67100+{
67101+ ipv6_seq_ops_addr = addr;
67102+}
67103+
67104+void unregister_ipv6_seq_ops_addr(void)
67105+{
67106+ ipv6_seq_ops_addr = NULL;
67107+}
67108+
67109+EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
67110+EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
67111+#endif
67112+
67113 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
67114 {
67115 return pde->parent->data;
67116@@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
67117 return maybe_get_net(PDE_NET(PDE(inode)));
67118 }
67119
67120+extern const struct seq_operations dev_seq_ops;
67121+
67122 int seq_open_net(struct inode *ino, struct file *f,
67123 const struct seq_operations *ops, int size)
67124 {
67125@@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
67126
67127 BUG_ON(size < sizeof(*p));
67128
67129+ /* only permit access to /proc/net/dev */
67130+ if (
67131+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
67132+ ops != ipv6_seq_ops_addr &&
67133+#endif
67134+ ops != &dev_seq_ops && gr_proc_is_restricted())
67135+ return -EACCES;
67136+
67137 net = get_proc_net(ino);
67138 if (net == NULL)
67139 return -ENXIO;
67140@@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
67141 int err;
67142 struct net *net;
67143
67144+ if (gr_proc_is_restricted())
67145+ return -EACCES;
67146+
67147 err = -ENXIO;
67148 net = get_proc_net(inode);
67149 if (net == NULL)
67150diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
67151index f92d5dd..26398ac 100644
67152--- a/fs/proc/proc_sysctl.c
67153+++ b/fs/proc/proc_sysctl.c
67154@@ -11,13 +11,21 @@
67155 #include <linux/namei.h>
67156 #include <linux/mm.h>
67157 #include <linux/module.h>
67158+#include <linux/nsproxy.h>
67159+#ifdef CONFIG_GRKERNSEC
67160+#include <net/net_namespace.h>
67161+#endif
67162 #include "internal.h"
67163
67164+extern int gr_handle_chroot_sysctl(const int op);
67165+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
67166+ const int op);
67167+
67168 static const struct dentry_operations proc_sys_dentry_operations;
67169 static const struct file_operations proc_sys_file_operations;
67170-static const struct inode_operations proc_sys_inode_operations;
67171+const struct inode_operations proc_sys_inode_operations;
67172 static const struct file_operations proc_sys_dir_file_operations;
67173-static const struct inode_operations proc_sys_dir_operations;
67174+const struct inode_operations proc_sys_dir_operations;
67175
67176 void proc_sys_poll_notify(struct ctl_table_poll *poll)
67177 {
67178@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
67179
67180 err = NULL;
67181 d_set_d_op(dentry, &proc_sys_dentry_operations);
67182+
67183+ gr_handle_proc_create(dentry, inode);
67184+
67185 d_add(dentry, inode);
67186
67187 out:
67188@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
67189 struct inode *inode = file_inode(filp);
67190 struct ctl_table_header *head = grab_header(inode);
67191 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
67192+ int op = write ? MAY_WRITE : MAY_READ;
67193 ssize_t error;
67194 size_t res;
67195
67196@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
67197 * and won't be until we finish.
67198 */
67199 error = -EPERM;
67200- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
67201+ if (sysctl_perm(head, table, op))
67202 goto out;
67203
67204 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
67205@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
67206 if (!table->proc_handler)
67207 goto out;
67208
67209+#ifdef CONFIG_GRKERNSEC
67210+ error = -EPERM;
67211+ if (gr_handle_chroot_sysctl(op))
67212+ goto out;
67213+ dget(filp->f_path.dentry);
67214+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
67215+ dput(filp->f_path.dentry);
67216+ goto out;
67217+ }
67218+ dput(filp->f_path.dentry);
67219+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
67220+ goto out;
67221+ if (write) {
67222+ if (current->nsproxy->net_ns != table->extra2) {
67223+ if (!capable(CAP_SYS_ADMIN))
67224+ goto out;
67225+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
67226+ goto out;
67227+ }
67228+#endif
67229+
67230 /* careful: calling conventions are nasty here */
67231 res = count;
67232 error = table->proc_handler(table, write, buf, &res, ppos);
67233@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
67234 return false;
67235 } else {
67236 d_set_d_op(child, &proc_sys_dentry_operations);
67237+
67238+ gr_handle_proc_create(child, inode);
67239+
67240 d_add(child, inode);
67241 }
67242 } else {
67243@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, struct ctl_table *table,
67244 if ((*pos)++ < ctx->pos)
67245 return true;
67246
67247+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
67248+ return 0;
67249+
67250 if (unlikely(S_ISLNK(table->mode)))
67251 res = proc_sys_link_fill_cache(file, ctx, head, table);
67252 else
67253@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
67254 if (IS_ERR(head))
67255 return PTR_ERR(head);
67256
67257+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
67258+ return -ENOENT;
67259+
67260 generic_fillattr(inode, stat);
67261 if (table)
67262 stat->mode = (stat->mode & S_IFMT) | table->mode;
67263@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
67264 .llseek = generic_file_llseek,
67265 };
67266
67267-static const struct inode_operations proc_sys_inode_operations = {
67268+const struct inode_operations proc_sys_inode_operations = {
67269 .permission = proc_sys_permission,
67270 .setattr = proc_sys_setattr,
67271 .getattr = proc_sys_getattr,
67272 };
67273
67274-static const struct inode_operations proc_sys_dir_operations = {
67275+const struct inode_operations proc_sys_dir_operations = {
67276 .lookup = proc_sys_lookup,
67277 .permission = proc_sys_permission,
67278 .setattr = proc_sys_setattr,
67279@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
67280 static struct ctl_dir *new_dir(struct ctl_table_set *set,
67281 const char *name, int namelen)
67282 {
67283- struct ctl_table *table;
67284+ ctl_table_no_const *table;
67285 struct ctl_dir *new;
67286 struct ctl_node *node;
67287 char *new_name;
67288@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
67289 return NULL;
67290
67291 node = (struct ctl_node *)(new + 1);
67292- table = (struct ctl_table *)(node + 1);
67293+ table = (ctl_table_no_const *)(node + 1);
67294 new_name = (char *)(table + 2);
67295 memcpy(new_name, name, namelen);
67296 new_name[namelen] = '\0';
67297@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
67298 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
67299 struct ctl_table_root *link_root)
67300 {
67301- struct ctl_table *link_table, *entry, *link;
67302+ ctl_table_no_const *link_table, *link;
67303+ struct ctl_table *entry;
67304 struct ctl_table_header *links;
67305 struct ctl_node *node;
67306 char *link_name;
67307@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
67308 return NULL;
67309
67310 node = (struct ctl_node *)(links + 1);
67311- link_table = (struct ctl_table *)(node + nr_entries);
67312+ link_table = (ctl_table_no_const *)(node + nr_entries);
67313 link_name = (char *)&link_table[nr_entries + 1];
67314
67315 for (link = link_table, entry = table; entry->procname; link++, entry++) {
67316@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67317 struct ctl_table_header ***subheader, struct ctl_table_set *set,
67318 struct ctl_table *table)
67319 {
67320- struct ctl_table *ctl_table_arg = NULL;
67321- struct ctl_table *entry, *files;
67322+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
67323+ struct ctl_table *entry;
67324 int nr_files = 0;
67325 int nr_dirs = 0;
67326 int err = -ENOMEM;
67327@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67328 nr_files++;
67329 }
67330
67331- files = table;
67332 /* If there are mixed files and directories we need a new table */
67333 if (nr_dirs && nr_files) {
67334- struct ctl_table *new;
67335+ ctl_table_no_const *new;
67336 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
67337 GFP_KERNEL);
67338 if (!files)
67339@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
67340 /* Register everything except a directory full of subdirectories */
67341 if (nr_files || !nr_dirs) {
67342 struct ctl_table_header *header;
67343- header = __register_sysctl_table(set, path, files);
67344+ header = __register_sysctl_table(set, path, files ? files : table);
67345 if (!header) {
67346 kfree(ctl_table_arg);
67347 goto out;
67348diff --git a/fs/proc/root.c b/fs/proc/root.c
67349index 094e44d..085a877 100644
67350--- a/fs/proc/root.c
67351+++ b/fs/proc/root.c
67352@@ -188,7 +188,15 @@ void __init proc_root_init(void)
67353 proc_mkdir("openprom", NULL);
67354 #endif
67355 proc_tty_init();
67356+#ifdef CONFIG_GRKERNSEC_PROC_ADD
67357+#ifdef CONFIG_GRKERNSEC_PROC_USER
67358+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
67359+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67360+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
67361+#endif
67362+#else
67363 proc_mkdir("bus", NULL);
67364+#endif
67365 proc_sys_init();
67366 }
67367
67368diff --git a/fs/proc/stat.c b/fs/proc/stat.c
67369index bf2d03f..f058f9c 100644
67370--- a/fs/proc/stat.c
67371+++ b/fs/proc/stat.c
67372@@ -11,6 +11,7 @@
67373 #include <linux/irqnr.h>
67374 #include <linux/cputime.h>
67375 #include <linux/tick.h>
67376+#include <linux/grsecurity.h>
67377
67378 #ifndef arch_irq_stat_cpu
67379 #define arch_irq_stat_cpu(cpu) 0
67380@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
67381 u64 sum_softirq = 0;
67382 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
67383 struct timespec boottime;
67384+ int unrestricted = 1;
67385+
67386+#ifdef CONFIG_GRKERNSEC_PROC_ADD
67387+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67388+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
67389+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67390+ && !in_group_p(grsec_proc_gid)
67391+#endif
67392+ )
67393+ unrestricted = 0;
67394+#endif
67395+#endif
67396
67397 user = nice = system = idle = iowait =
67398 irq = softirq = steal = 0;
67399@@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
67400 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67401 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67402 idle += get_idle_time(i);
67403- iowait += get_iowait_time(i);
67404- irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67405- softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67406- steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67407- guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67408- guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67409- sum += kstat_cpu_irqs_sum(i);
67410- sum += arch_irq_stat_cpu(i);
67411+ if (unrestricted) {
67412+ iowait += get_iowait_time(i);
67413+ irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67414+ softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67415+ steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67416+ guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67417+ guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67418+ sum += kstat_cpu_irqs_sum(i);
67419+ sum += arch_irq_stat_cpu(i);
67420+ for (j = 0; j < NR_SOFTIRQS; j++) {
67421+ unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67422
67423- for (j = 0; j < NR_SOFTIRQS; j++) {
67424- unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67425-
67426- per_softirq_sums[j] += softirq_stat;
67427- sum_softirq += softirq_stat;
67428+ per_softirq_sums[j] += softirq_stat;
67429+ sum_softirq += softirq_stat;
67430+ }
67431 }
67432 }
67433- sum += arch_irq_stat();
67434+ if (unrestricted)
67435+ sum += arch_irq_stat();
67436
67437 seq_puts(p, "cpu ");
67438 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67439@@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
67440 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67441 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67442 idle = get_idle_time(i);
67443- iowait = get_iowait_time(i);
67444- irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67445- softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67446- steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67447- guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67448- guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67449+ if (unrestricted) {
67450+ iowait = get_iowait_time(i);
67451+ irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67452+ softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67453+ steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67454+ guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67455+ guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67456+ }
67457 seq_printf(p, "cpu%d", i);
67458 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67459 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
67460@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
67461
67462 /* sum again ? it could be updated? */
67463 for_each_irq_nr(j)
67464- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
67465+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
67466
67467 seq_printf(p,
67468 "\nctxt %llu\n"
67469@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
67470 "processes %lu\n"
67471 "procs_running %lu\n"
67472 "procs_blocked %lu\n",
67473- nr_context_switches(),
67474+ unrestricted ? nr_context_switches() : 0ULL,
67475 (unsigned long)jif,
67476- total_forks,
67477- nr_running(),
67478- nr_iowait());
67479+ unrestricted ? total_forks : 0UL,
67480+ unrestricted ? nr_running() : 0UL,
67481+ unrestricted ? nr_iowait() : 0UL);
67482
67483 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
67484
67485diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
67486index c341568..75852a2 100644
67487--- a/fs/proc/task_mmu.c
67488+++ b/fs/proc/task_mmu.c
67489@@ -13,12 +13,19 @@
67490 #include <linux/swap.h>
67491 #include <linux/swapops.h>
67492 #include <linux/mmu_notifier.h>
67493+#include <linux/grsecurity.h>
67494
67495 #include <asm/elf.h>
67496 #include <asm/uaccess.h>
67497 #include <asm/tlbflush.h>
67498 #include "internal.h"
67499
67500+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67501+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
67502+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
67503+ _mm->pax_flags & MF_PAX_SEGMEXEC))
67504+#endif
67505+
67506 void task_mem(struct seq_file *m, struct mm_struct *mm)
67507 {
67508 unsigned long data, text, lib, swap;
67509@@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67510 "VmExe:\t%8lu kB\n"
67511 "VmLib:\t%8lu kB\n"
67512 "VmPTE:\t%8lu kB\n"
67513- "VmSwap:\t%8lu kB\n",
67514- hiwater_vm << (PAGE_SHIFT-10),
67515+ "VmSwap:\t%8lu kB\n"
67516+
67517+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67518+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
67519+#endif
67520+
67521+ ,hiwater_vm << (PAGE_SHIFT-10),
67522 total_vm << (PAGE_SHIFT-10),
67523 mm->locked_vm << (PAGE_SHIFT-10),
67524 mm->pinned_vm << (PAGE_SHIFT-10),
67525@@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67526 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
67527 (PTRS_PER_PTE * sizeof(pte_t) *
67528 atomic_long_read(&mm->nr_ptes)) >> 10,
67529- swap << (PAGE_SHIFT-10));
67530+ swap << (PAGE_SHIFT-10)
67531+
67532+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67533+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67534+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
67535+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
67536+#else
67537+ , mm->context.user_cs_base
67538+ , mm->context.user_cs_limit
67539+#endif
67540+#endif
67541+
67542+ );
67543 }
67544
67545 unsigned long task_vsize(struct mm_struct *mm)
67546@@ -271,13 +295,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67547 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
67548 }
67549
67550- /* We don't show the stack guard page in /proc/maps */
67551+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67552+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
67553+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
67554+#else
67555 start = vma->vm_start;
67556- if (stack_guard_page_start(vma, start))
67557- start += PAGE_SIZE;
67558 end = vma->vm_end;
67559- if (stack_guard_page_end(vma, end))
67560- end -= PAGE_SIZE;
67561+#endif
67562
67563 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
67564 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
67565@@ -287,7 +311,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67566 flags & VM_WRITE ? 'w' : '-',
67567 flags & VM_EXEC ? 'x' : '-',
67568 flags & VM_MAYSHARE ? 's' : 'p',
67569+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67570+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
67571+#else
67572 pgoff,
67573+#endif
67574 MAJOR(dev), MINOR(dev), ino);
67575
67576 /*
67577@@ -296,7 +324,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67578 */
67579 if (file) {
67580 seq_pad(m, ' ');
67581- seq_path(m, &file->f_path, "\n");
67582+ seq_path(m, &file->f_path, "\n\\");
67583 goto done;
67584 }
67585
67586@@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67587 * Thread stack in /proc/PID/task/TID/maps or
67588 * the main process stack.
67589 */
67590- if (!is_pid || (vma->vm_start <= mm->start_stack &&
67591- vma->vm_end >= mm->start_stack)) {
67592+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
67593+ (vma->vm_start <= mm->start_stack &&
67594+ vma->vm_end >= mm->start_stack)) {
67595 name = "[stack]";
67596 } else {
67597 /* Thread stack in /proc/PID/maps */
67598@@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
67599 struct proc_maps_private *priv = m->private;
67600 struct task_struct *task = priv->task;
67601
67602+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67603+ if (current->exec_id != m->exec_id) {
67604+ gr_log_badprocpid("maps");
67605+ return 0;
67606+ }
67607+#endif
67608+
67609 show_map_vma(m, vma, is_pid);
67610
67611 if (m->count < m->size) /* vma is copied successfully */
67612@@ -593,12 +629,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
67613 .private = &mss,
67614 };
67615
67616+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67617+ if (current->exec_id != m->exec_id) {
67618+ gr_log_badprocpid("smaps");
67619+ return 0;
67620+ }
67621+#endif
67622 memset(&mss, 0, sizeof mss);
67623- mss.vma = vma;
67624- /* mmap_sem is held in m_start */
67625- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
67626- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
67627-
67628+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67629+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
67630+#endif
67631+ mss.vma = vma;
67632+ /* mmap_sem is held in m_start */
67633+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
67634+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
67635+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67636+ }
67637+#endif
67638 show_map_vma(m, vma, is_pid);
67639
67640 seq_printf(m,
67641@@ -616,7 +663,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
67642 "KernelPageSize: %8lu kB\n"
67643 "MMUPageSize: %8lu kB\n"
67644 "Locked: %8lu kB\n",
67645+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67646+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
67647+#else
67648 (vma->vm_end - vma->vm_start) >> 10,
67649+#endif
67650 mss.resident >> 10,
67651 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
67652 mss.shared_clean >> 10,
67653@@ -1422,6 +1473,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
67654 char buffer[64];
67655 int nid;
67656
67657+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67658+ if (current->exec_id != m->exec_id) {
67659+ gr_log_badprocpid("numa_maps");
67660+ return 0;
67661+ }
67662+#endif
67663+
67664 if (!mm)
67665 return 0;
67666
67667@@ -1439,11 +1497,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
67668 mpol_to_str(buffer, sizeof(buffer), pol);
67669 mpol_cond_put(pol);
67670
67671+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67672+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
67673+#else
67674 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
67675+#endif
67676
67677 if (file) {
67678 seq_puts(m, " file=");
67679- seq_path(m, &file->f_path, "\n\t= ");
67680+ seq_path(m, &file->f_path, "\n\t\\= ");
67681 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
67682 seq_puts(m, " heap");
67683 } else {
67684diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
67685index 678455d..ebd3245 100644
67686--- a/fs/proc/task_nommu.c
67687+++ b/fs/proc/task_nommu.c
67688@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67689 else
67690 bytes += kobjsize(mm);
67691
67692- if (current->fs && current->fs->users > 1)
67693+ if (current->fs && atomic_read(&current->fs->users) > 1)
67694 sbytes += kobjsize(current->fs);
67695 else
67696 bytes += kobjsize(current->fs);
67697@@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
67698
67699 if (file) {
67700 seq_pad(m, ' ');
67701- seq_path(m, &file->f_path, "");
67702+ seq_path(m, &file->f_path, "\n\\");
67703 } else if (mm) {
67704 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
67705
67706diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
67707index a90d6d35..d08047c 100644
67708--- a/fs/proc/vmcore.c
67709+++ b/fs/proc/vmcore.c
67710@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
67711 nr_bytes = count;
67712
67713 /* If pfn is not ram, return zeros for sparse dump files */
67714- if (pfn_is_ram(pfn) == 0)
67715- memset(buf, 0, nr_bytes);
67716- else {
67717+ if (pfn_is_ram(pfn) == 0) {
67718+ if (userbuf) {
67719+ if (clear_user((char __force_user *)buf, nr_bytes))
67720+ return -EFAULT;
67721+ } else
67722+ memset(buf, 0, nr_bytes);
67723+ } else {
67724 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
67725 offset, userbuf);
67726 if (tmp < 0)
67727@@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
67728 static int copy_to(void *target, void *src, size_t size, int userbuf)
67729 {
67730 if (userbuf) {
67731- if (copy_to_user((char __user *) target, src, size))
67732+ if (copy_to_user((char __force_user *) target, src, size))
67733 return -EFAULT;
67734 } else {
67735 memcpy(target, src, size);
67736@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67737 if (*fpos < m->offset + m->size) {
67738 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
67739 start = m->paddr + *fpos - m->offset;
67740- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
67741+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
67742 if (tmp < 0)
67743 return tmp;
67744 buflen -= tsz;
67745@@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67746 static ssize_t read_vmcore(struct file *file, char __user *buffer,
67747 size_t buflen, loff_t *fpos)
67748 {
67749- return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
67750+ return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
67751 }
67752
67753 /*
67754diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
67755index d3fb2b6..43a8140 100644
67756--- a/fs/qnx6/qnx6.h
67757+++ b/fs/qnx6/qnx6.h
67758@@ -74,7 +74,7 @@ enum {
67759 BYTESEX_BE,
67760 };
67761
67762-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67763+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67764 {
67765 if (sbi->s_bytesex == BYTESEX_LE)
67766 return le64_to_cpu((__force __le64)n);
67767@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
67768 return (__force __fs64)cpu_to_be64(n);
67769 }
67770
67771-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67772+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67773 {
67774 if (sbi->s_bytesex == BYTESEX_LE)
67775 return le32_to_cpu((__force __le32)n);
67776diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
67777index bb2869f..d34ada8 100644
67778--- a/fs/quota/netlink.c
67779+++ b/fs/quota/netlink.c
67780@@ -44,7 +44,7 @@ static struct genl_family quota_genl_family = {
67781 void quota_send_warning(struct kqid qid, dev_t dev,
67782 const char warntype)
67783 {
67784- static atomic_t seq;
67785+ static atomic_unchecked_t seq;
67786 struct sk_buff *skb;
67787 void *msg_head;
67788 int ret;
67789@@ -60,7 +60,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
67790 "VFS: Not enough memory to send quota warning.\n");
67791 return;
67792 }
67793- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
67794+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
67795 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
67796 if (!msg_head) {
67797 printk(KERN_ERR
67798diff --git a/fs/read_write.c b/fs/read_write.c
67799index 009d854..16ce214 100644
67800--- a/fs/read_write.c
67801+++ b/fs/read_write.c
67802@@ -495,7 +495,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
67803
67804 old_fs = get_fs();
67805 set_fs(get_ds());
67806- p = (__force const char __user *)buf;
67807+ p = (const char __force_user *)buf;
67808 if (count > MAX_RW_COUNT)
67809 count = MAX_RW_COUNT;
67810 if (file->f_op->write)
67811diff --git a/fs/readdir.c b/fs/readdir.c
67812index 33fd922..e0d6094 100644
67813--- a/fs/readdir.c
67814+++ b/fs/readdir.c
67815@@ -18,6 +18,7 @@
67816 #include <linux/security.h>
67817 #include <linux/syscalls.h>
67818 #include <linux/unistd.h>
67819+#include <linux/namei.h>
67820
67821 #include <asm/uaccess.h>
67822
67823@@ -71,6 +72,7 @@ struct old_linux_dirent {
67824 struct readdir_callback {
67825 struct dir_context ctx;
67826 struct old_linux_dirent __user * dirent;
67827+ struct file * file;
67828 int result;
67829 };
67830
67831@@ -88,6 +90,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
67832 buf->result = -EOVERFLOW;
67833 return -EOVERFLOW;
67834 }
67835+
67836+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67837+ return 0;
67838+
67839 buf->result++;
67840 dirent = buf->dirent;
67841 if (!access_ok(VERIFY_WRITE, dirent,
67842@@ -119,6 +125,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
67843 if (!f.file)
67844 return -EBADF;
67845
67846+ buf.file = f.file;
67847 error = iterate_dir(f.file, &buf.ctx);
67848 if (buf.result)
67849 error = buf.result;
67850@@ -144,6 +151,7 @@ struct getdents_callback {
67851 struct dir_context ctx;
67852 struct linux_dirent __user * current_dir;
67853 struct linux_dirent __user * previous;
67854+ struct file * file;
67855 int count;
67856 int error;
67857 };
67858@@ -165,6 +173,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
67859 buf->error = -EOVERFLOW;
67860 return -EOVERFLOW;
67861 }
67862+
67863+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67864+ return 0;
67865+
67866 dirent = buf->previous;
67867 if (dirent) {
67868 if (__put_user(offset, &dirent->d_off))
67869@@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
67870 if (!f.file)
67871 return -EBADF;
67872
67873+ buf.file = f.file;
67874 error = iterate_dir(f.file, &buf.ctx);
67875 if (error >= 0)
67876 error = buf.error;
67877@@ -228,6 +241,7 @@ struct getdents_callback64 {
67878 struct dir_context ctx;
67879 struct linux_dirent64 __user * current_dir;
67880 struct linux_dirent64 __user * previous;
67881+ struct file *file;
67882 int count;
67883 int error;
67884 };
67885@@ -243,6 +257,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
67886 buf->error = -EINVAL; /* only used if we fail.. */
67887 if (reclen > buf->count)
67888 return -EINVAL;
67889+
67890+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67891+ return 0;
67892+
67893 dirent = buf->previous;
67894 if (dirent) {
67895 if (__put_user(offset, &dirent->d_off))
67896@@ -290,6 +308,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
67897 if (!f.file)
67898 return -EBADF;
67899
67900+ buf.file = f.file;
67901 error = iterate_dir(f.file, &buf.ctx);
67902 if (error >= 0)
67903 error = buf.error;
67904diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
67905index 9c02d96..6562c10 100644
67906--- a/fs/reiserfs/do_balan.c
67907+++ b/fs/reiserfs/do_balan.c
67908@@ -1887,7 +1887,7 @@ void do_balance(struct tree_balance *tb, struct item_head *ih,
67909 return;
67910 }
67911
67912- atomic_inc(&fs_generation(tb->tb_sb));
67913+ atomic_inc_unchecked(&fs_generation(tb->tb_sb));
67914 do_balance_starts(tb);
67915
67916 /*
67917diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
67918index aca73dd..e3c558d 100644
67919--- a/fs/reiserfs/item_ops.c
67920+++ b/fs/reiserfs/item_ops.c
67921@@ -724,18 +724,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
67922 }
67923
67924 static struct item_operations errcatch_ops = {
67925- errcatch_bytes_number,
67926- errcatch_decrement_key,
67927- errcatch_is_left_mergeable,
67928- errcatch_print_item,
67929- errcatch_check_item,
67930+ .bytes_number = errcatch_bytes_number,
67931+ .decrement_key = errcatch_decrement_key,
67932+ .is_left_mergeable = errcatch_is_left_mergeable,
67933+ .print_item = errcatch_print_item,
67934+ .check_item = errcatch_check_item,
67935
67936- errcatch_create_vi,
67937- errcatch_check_left,
67938- errcatch_check_right,
67939- errcatch_part_size,
67940- errcatch_unit_num,
67941- errcatch_print_vi
67942+ .create_vi = errcatch_create_vi,
67943+ .check_left = errcatch_check_left,
67944+ .check_right = errcatch_check_right,
67945+ .part_size = errcatch_part_size,
67946+ .unit_num = errcatch_unit_num,
67947+ .print_vi = errcatch_print_vi
67948 };
67949
67950 #if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
67951diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
67952index 621b9f3..af527fd 100644
67953--- a/fs/reiserfs/procfs.c
67954+++ b/fs/reiserfs/procfs.c
67955@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
67956 "SMALL_TAILS " : "NO_TAILS ",
67957 replay_only(sb) ? "REPLAY_ONLY " : "",
67958 convert_reiserfs(sb) ? "CONV " : "",
67959- atomic_read(&r->s_generation_counter),
67960+ atomic_read_unchecked(&r->s_generation_counter),
67961 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
67962 SF(s_do_balance), SF(s_unneeded_left_neighbor),
67963 SF(s_good_search_by_key_reada), SF(s_bmaps),
67964diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
67965index 735c2c2..81b91af 100644
67966--- a/fs/reiserfs/reiserfs.h
67967+++ b/fs/reiserfs/reiserfs.h
67968@@ -573,7 +573,7 @@ struct reiserfs_sb_info {
67969 /* Comment? -Hans */
67970 wait_queue_head_t s_wait;
67971 /* increased by one every time the tree gets re-balanced */
67972- atomic_t s_generation_counter;
67973+ atomic_unchecked_t s_generation_counter;
67974
67975 /* File system properties. Currently holds on-disk FS format */
67976 unsigned long s_properties;
67977@@ -2294,7 +2294,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
67978 #define REISERFS_USER_MEM 1 /* user memory mode */
67979
67980 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
67981-#define get_generation(s) atomic_read (&fs_generation(s))
67982+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
67983 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
67984 #define __fs_changed(gen,s) (gen != get_generation (s))
67985 #define fs_changed(gen,s) \
67986diff --git a/fs/select.c b/fs/select.c
67987index 467bb1c..cf9d65a 100644
67988--- a/fs/select.c
67989+++ b/fs/select.c
67990@@ -20,6 +20,7 @@
67991 #include <linux/export.h>
67992 #include <linux/slab.h>
67993 #include <linux/poll.h>
67994+#include <linux/security.h>
67995 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
67996 #include <linux/file.h>
67997 #include <linux/fdtable.h>
67998@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
67999 struct poll_list *walk = head;
68000 unsigned long todo = nfds;
68001
68002+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
68003 if (nfds > rlimit(RLIMIT_NOFILE))
68004 return -EINVAL;
68005
68006diff --git a/fs/seq_file.c b/fs/seq_file.c
68007index 3857b72..0b7281e 100644
68008--- a/fs/seq_file.c
68009+++ b/fs/seq_file.c
68010@@ -12,6 +12,8 @@
68011 #include <linux/slab.h>
68012 #include <linux/cred.h>
68013 #include <linux/mm.h>
68014+#include <linux/sched.h>
68015+#include <linux/grsecurity.h>
68016
68017 #include <asm/uaccess.h>
68018 #include <asm/page.h>
68019@@ -34,12 +36,7 @@ static void seq_set_overflow(struct seq_file *m)
68020
68021 static void *seq_buf_alloc(unsigned long size)
68022 {
68023- void *buf;
68024-
68025- buf = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
68026- if (!buf && size > PAGE_SIZE)
68027- buf = vmalloc(size);
68028- return buf;
68029+ return kmalloc(size, GFP_KERNEL | GFP_USERCOPY);
68030 }
68031
68032 /**
68033@@ -72,6 +69,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
68034 #ifdef CONFIG_USER_NS
68035 p->user_ns = file->f_cred->user_ns;
68036 #endif
68037+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68038+ p->exec_id = current->exec_id;
68039+#endif
68040
68041 /*
68042 * Wrappers around seq_open(e.g. swaps_open) need to be
68043@@ -94,6 +94,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
68044 }
68045 EXPORT_SYMBOL(seq_open);
68046
68047+
68048+int seq_open_restrict(struct file *file, const struct seq_operations *op)
68049+{
68050+ if (gr_proc_is_restricted())
68051+ return -EACCES;
68052+
68053+ return seq_open(file, op);
68054+}
68055+EXPORT_SYMBOL(seq_open_restrict);
68056+
68057 static int traverse(struct seq_file *m, loff_t offset)
68058 {
68059 loff_t pos = 0, index;
68060@@ -165,7 +175,7 @@ Eoverflow:
68061 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
68062 {
68063 struct seq_file *m = file->private_data;
68064- size_t copied = 0;
68065+ ssize_t copied = 0;
68066 loff_t pos;
68067 size_t n;
68068 void *p;
68069@@ -596,7 +606,7 @@ static void single_stop(struct seq_file *p, void *v)
68070 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
68071 void *data)
68072 {
68073- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
68074+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
68075 int res = -ENOMEM;
68076
68077 if (op) {
68078@@ -632,6 +642,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
68079 }
68080 EXPORT_SYMBOL(single_open_size);
68081
68082+int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
68083+ void *data)
68084+{
68085+ if (gr_proc_is_restricted())
68086+ return -EACCES;
68087+
68088+ return single_open(file, show, data);
68089+}
68090+EXPORT_SYMBOL(single_open_restrict);
68091+
68092+
68093 int single_release(struct inode *inode, struct file *file)
68094 {
68095 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
68096diff --git a/fs/splice.c b/fs/splice.c
68097index f5cb9ba..8ddb1e9 100644
68098--- a/fs/splice.c
68099+++ b/fs/splice.c
68100@@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
68101 pipe_lock(pipe);
68102
68103 for (;;) {
68104- if (!pipe->readers) {
68105+ if (!atomic_read(&pipe->readers)) {
68106 send_sig(SIGPIPE, current, 0);
68107 if (!ret)
68108 ret = -EPIPE;
68109@@ -216,7 +216,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
68110 page_nr++;
68111 ret += buf->len;
68112
68113- if (pipe->files)
68114+ if (atomic_read(&pipe->files))
68115 do_wakeup = 1;
68116
68117 if (!--spd->nr_pages)
68118@@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
68119 do_wakeup = 0;
68120 }
68121
68122- pipe->waiting_writers++;
68123+ atomic_inc(&pipe->waiting_writers);
68124 pipe_wait(pipe);
68125- pipe->waiting_writers--;
68126+ atomic_dec(&pipe->waiting_writers);
68127 }
68128
68129 pipe_unlock(pipe);
68130@@ -576,7 +576,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
68131 old_fs = get_fs();
68132 set_fs(get_ds());
68133 /* The cast to a user pointer is valid due to the set_fs() */
68134- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
68135+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
68136 set_fs(old_fs);
68137
68138 return res;
68139@@ -591,7 +591,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
68140 old_fs = get_fs();
68141 set_fs(get_ds());
68142 /* The cast to a user pointer is valid due to the set_fs() */
68143- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
68144+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
68145 set_fs(old_fs);
68146
68147 return res;
68148@@ -644,7 +644,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
68149 goto err;
68150
68151 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
68152- vec[i].iov_base = (void __user *) page_address(page);
68153+ vec[i].iov_base = (void __force_user *) page_address(page);
68154 vec[i].iov_len = this_len;
68155 spd.pages[i] = page;
68156 spd.nr_pages++;
68157@@ -783,7 +783,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
68158 ops->release(pipe, buf);
68159 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
68160 pipe->nrbufs--;
68161- if (pipe->files)
68162+ if (atomic_read(&pipe->files))
68163 sd->need_wakeup = true;
68164 }
68165
68166@@ -807,10 +807,10 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
68167 static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
68168 {
68169 while (!pipe->nrbufs) {
68170- if (!pipe->writers)
68171+ if (!atomic_read(&pipe->writers))
68172 return 0;
68173
68174- if (!pipe->waiting_writers && sd->num_spliced)
68175+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
68176 return 0;
68177
68178 if (sd->flags & SPLICE_F_NONBLOCK)
68179@@ -1040,7 +1040,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
68180 ops->release(pipe, buf);
68181 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
68182 pipe->nrbufs--;
68183- if (pipe->files)
68184+ if (atomic_read(&pipe->files))
68185 sd.need_wakeup = true;
68186 } else {
68187 buf->offset += ret;
68188@@ -1200,7 +1200,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
68189 * out of the pipe right after the splice_to_pipe(). So set
68190 * PIPE_READERS appropriately.
68191 */
68192- pipe->readers = 1;
68193+ atomic_set(&pipe->readers, 1);
68194
68195 current->splice_pipe = pipe;
68196 }
68197@@ -1496,6 +1496,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
68198
68199 partial[buffers].offset = off;
68200 partial[buffers].len = plen;
68201+ partial[buffers].private = 0;
68202
68203 off = 0;
68204 len -= plen;
68205@@ -1732,9 +1733,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
68206 ret = -ERESTARTSYS;
68207 break;
68208 }
68209- if (!pipe->writers)
68210+ if (!atomic_read(&pipe->writers))
68211 break;
68212- if (!pipe->waiting_writers) {
68213+ if (!atomic_read(&pipe->waiting_writers)) {
68214 if (flags & SPLICE_F_NONBLOCK) {
68215 ret = -EAGAIN;
68216 break;
68217@@ -1766,7 +1767,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
68218 pipe_lock(pipe);
68219
68220 while (pipe->nrbufs >= pipe->buffers) {
68221- if (!pipe->readers) {
68222+ if (!atomic_read(&pipe->readers)) {
68223 send_sig(SIGPIPE, current, 0);
68224 ret = -EPIPE;
68225 break;
68226@@ -1779,9 +1780,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
68227 ret = -ERESTARTSYS;
68228 break;
68229 }
68230- pipe->waiting_writers++;
68231+ atomic_inc(&pipe->waiting_writers);
68232 pipe_wait(pipe);
68233- pipe->waiting_writers--;
68234+ atomic_dec(&pipe->waiting_writers);
68235 }
68236
68237 pipe_unlock(pipe);
68238@@ -1817,14 +1818,14 @@ retry:
68239 pipe_double_lock(ipipe, opipe);
68240
68241 do {
68242- if (!opipe->readers) {
68243+ if (!atomic_read(&opipe->readers)) {
68244 send_sig(SIGPIPE, current, 0);
68245 if (!ret)
68246 ret = -EPIPE;
68247 break;
68248 }
68249
68250- if (!ipipe->nrbufs && !ipipe->writers)
68251+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
68252 break;
68253
68254 /*
68255@@ -1921,7 +1922,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
68256 pipe_double_lock(ipipe, opipe);
68257
68258 do {
68259- if (!opipe->readers) {
68260+ if (!atomic_read(&opipe->readers)) {
68261 send_sig(SIGPIPE, current, 0);
68262 if (!ret)
68263 ret = -EPIPE;
68264@@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
68265 * return EAGAIN if we have the potential of some data in the
68266 * future, otherwise just return 0
68267 */
68268- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
68269+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
68270 ret = -EAGAIN;
68271
68272 pipe_unlock(ipipe);
68273diff --git a/fs/stat.c b/fs/stat.c
68274index ae0c3ce..9ee641c 100644
68275--- a/fs/stat.c
68276+++ b/fs/stat.c
68277@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
68278 stat->gid = inode->i_gid;
68279 stat->rdev = inode->i_rdev;
68280 stat->size = i_size_read(inode);
68281- stat->atime = inode->i_atime;
68282- stat->mtime = inode->i_mtime;
68283+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
68284+ stat->atime = inode->i_ctime;
68285+ stat->mtime = inode->i_ctime;
68286+ } else {
68287+ stat->atime = inode->i_atime;
68288+ stat->mtime = inode->i_mtime;
68289+ }
68290 stat->ctime = inode->i_ctime;
68291 stat->blksize = (1 << inode->i_blkbits);
68292 stat->blocks = inode->i_blocks;
68293@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
68294 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
68295 {
68296 struct inode *inode = path->dentry->d_inode;
68297+ int retval;
68298
68299- if (inode->i_op->getattr)
68300- return inode->i_op->getattr(path->mnt, path->dentry, stat);
68301+ if (inode->i_op->getattr) {
68302+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
68303+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
68304+ stat->atime = stat->ctime;
68305+ stat->mtime = stat->ctime;
68306+ }
68307+ return retval;
68308+ }
68309
68310 generic_fillattr(inode, stat);
68311 return 0;
68312diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
68313index 0b45ff4..847de5b 100644
68314--- a/fs/sysfs/dir.c
68315+++ b/fs/sysfs/dir.c
68316@@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
68317 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
68318 {
68319 struct kernfs_node *parent, *kn;
68320+ const char *name;
68321+ umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
68322+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
68323+ const char *parent_name;
68324+#endif
68325
68326 BUG_ON(!kobj);
68327
68328+ name = kobject_name(kobj);
68329+
68330 if (kobj->parent)
68331 parent = kobj->parent->sd;
68332 else
68333@@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
68334 if (!parent)
68335 return -ENOENT;
68336
68337- kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
68338- S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
68339+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
68340+ parent_name = parent->name;
68341+ mode = S_IRWXU;
68342+
68343+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
68344+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
68345+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
68346+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
68347+ mode = S_IRWXU | S_IRUGO | S_IXUGO;
68348+#endif
68349+
68350+ kn = kernfs_create_dir_ns(parent, name,
68351+ mode, kobj, ns);
68352 if (IS_ERR(kn)) {
68353 if (PTR_ERR(kn) == -EEXIST)
68354- sysfs_warn_dup(parent, kobject_name(kobj));
68355+ sysfs_warn_dup(parent, name);
68356 return PTR_ERR(kn);
68357 }
68358
68359diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
68360index 69d4889..a810bd4 100644
68361--- a/fs/sysv/sysv.h
68362+++ b/fs/sysv/sysv.h
68363@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
68364 #endif
68365 }
68366
68367-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
68368+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
68369 {
68370 if (sbi->s_bytesex == BYTESEX_PDP)
68371 return PDP_swab((__force __u32)n);
68372diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
68373index fb08b0c..65fcc7e 100644
68374--- a/fs/ubifs/io.c
68375+++ b/fs/ubifs/io.c
68376@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
68377 return err;
68378 }
68379
68380-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68381+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68382 {
68383 int err;
68384
68385diff --git a/fs/udf/misc.c b/fs/udf/misc.c
68386index c175b4d..8f36a16 100644
68387--- a/fs/udf/misc.c
68388+++ b/fs/udf/misc.c
68389@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
68390
68391 u8 udf_tag_checksum(const struct tag *t)
68392 {
68393- u8 *data = (u8 *)t;
68394+ const u8 *data = (const u8 *)t;
68395 u8 checksum = 0;
68396 int i;
68397 for (i = 0; i < sizeof(struct tag); ++i)
68398diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
68399index 8d974c4..b82f6ec 100644
68400--- a/fs/ufs/swab.h
68401+++ b/fs/ufs/swab.h
68402@@ -22,7 +22,7 @@ enum {
68403 BYTESEX_BE
68404 };
68405
68406-static inline u64
68407+static inline u64 __intentional_overflow(-1)
68408 fs64_to_cpu(struct super_block *sbp, __fs64 n)
68409 {
68410 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68411@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
68412 return (__force __fs64)cpu_to_be64(n);
68413 }
68414
68415-static inline u32
68416+static inline u32 __intentional_overflow(-1)
68417 fs32_to_cpu(struct super_block *sbp, __fs32 n)
68418 {
68419 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68420diff --git a/fs/utimes.c b/fs/utimes.c
68421index aa138d6..5f3a811 100644
68422--- a/fs/utimes.c
68423+++ b/fs/utimes.c
68424@@ -1,6 +1,7 @@
68425 #include <linux/compiler.h>
68426 #include <linux/file.h>
68427 #include <linux/fs.h>
68428+#include <linux/security.h>
68429 #include <linux/linkage.h>
68430 #include <linux/mount.h>
68431 #include <linux/namei.h>
68432@@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
68433 }
68434 }
68435 retry_deleg:
68436+
68437+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
68438+ error = -EACCES;
68439+ goto mnt_drop_write_and_out;
68440+ }
68441+
68442 mutex_lock(&inode->i_mutex);
68443 error = notify_change(path->dentry, &newattrs, &delegated_inode);
68444 mutex_unlock(&inode->i_mutex);
68445diff --git a/fs/xattr.c b/fs/xattr.c
68446index c69e6d4..cc56af5 100644
68447--- a/fs/xattr.c
68448+++ b/fs/xattr.c
68449@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
68450 return rc;
68451 }
68452
68453+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
68454+ssize_t
68455+pax_getxattr(struct dentry *dentry, void *value, size_t size)
68456+{
68457+ struct inode *inode = dentry->d_inode;
68458+ ssize_t error;
68459+
68460+ error = inode_permission(inode, MAY_EXEC);
68461+ if (error)
68462+ return error;
68463+
68464+ if (inode->i_op->getxattr)
68465+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
68466+ else
68467+ error = -EOPNOTSUPP;
68468+
68469+ return error;
68470+}
68471+EXPORT_SYMBOL(pax_getxattr);
68472+#endif
68473+
68474 ssize_t
68475 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
68476 {
68477@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
68478 * Extended attribute SET operations
68479 */
68480 static long
68481-setxattr(struct dentry *d, const char __user *name, const void __user *value,
68482+setxattr(struct path *path, const char __user *name, const void __user *value,
68483 size_t size, int flags)
68484 {
68485 int error;
68486@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
68487 posix_acl_fix_xattr_from_user(kvalue, size);
68488 }
68489
68490- error = vfs_setxattr(d, kname, kvalue, size, flags);
68491+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
68492+ error = -EACCES;
68493+ goto out;
68494+ }
68495+
68496+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
68497 out:
68498 if (vvalue)
68499 vfree(vvalue);
68500@@ -377,7 +403,7 @@ retry:
68501 return error;
68502 error = mnt_want_write(path.mnt);
68503 if (!error) {
68504- error = setxattr(path.dentry, name, value, size, flags);
68505+ error = setxattr(&path, name, value, size, flags);
68506 mnt_drop_write(path.mnt);
68507 }
68508 path_put(&path);
68509@@ -401,7 +427,7 @@ retry:
68510 return error;
68511 error = mnt_want_write(path.mnt);
68512 if (!error) {
68513- error = setxattr(path.dentry, name, value, size, flags);
68514+ error = setxattr(&path, name, value, size, flags);
68515 mnt_drop_write(path.mnt);
68516 }
68517 path_put(&path);
68518@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
68519 const void __user *,value, size_t, size, int, flags)
68520 {
68521 struct fd f = fdget(fd);
68522- struct dentry *dentry;
68523 int error = -EBADF;
68524
68525 if (!f.file)
68526 return error;
68527- dentry = f.file->f_path.dentry;
68528- audit_inode(NULL, dentry, 0);
68529+ audit_inode(NULL, f.file->f_path.dentry, 0);
68530 error = mnt_want_write_file(f.file);
68531 if (!error) {
68532- error = setxattr(dentry, name, value, size, flags);
68533+ error = setxattr(&f.file->f_path, name, value, size, flags);
68534 mnt_drop_write_file(f.file);
68535 }
68536 fdput(f);
68537@@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
68538 * Extended attribute REMOVE operations
68539 */
68540 static long
68541-removexattr(struct dentry *d, const char __user *name)
68542+removexattr(struct path *path, const char __user *name)
68543 {
68544 int error;
68545 char kname[XATTR_NAME_MAX + 1];
68546@@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
68547 if (error < 0)
68548 return error;
68549
68550- return vfs_removexattr(d, kname);
68551+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
68552+ return -EACCES;
68553+
68554+ return vfs_removexattr(path->dentry, kname);
68555 }
68556
68557 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
68558@@ -652,7 +679,7 @@ retry:
68559 return error;
68560 error = mnt_want_write(path.mnt);
68561 if (!error) {
68562- error = removexattr(path.dentry, name);
68563+ error = removexattr(&path, name);
68564 mnt_drop_write(path.mnt);
68565 }
68566 path_put(&path);
68567@@ -675,7 +702,7 @@ retry:
68568 return error;
68569 error = mnt_want_write(path.mnt);
68570 if (!error) {
68571- error = removexattr(path.dentry, name);
68572+ error = removexattr(&path, name);
68573 mnt_drop_write(path.mnt);
68574 }
68575 path_put(&path);
68576@@ -689,16 +716,16 @@ retry:
68577 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
68578 {
68579 struct fd f = fdget(fd);
68580- struct dentry *dentry;
68581+ struct path *path;
68582 int error = -EBADF;
68583
68584 if (!f.file)
68585 return error;
68586- dentry = f.file->f_path.dentry;
68587- audit_inode(NULL, dentry, 0);
68588+ path = &f.file->f_path;
68589+ audit_inode(NULL, path->dentry, 0);
68590 error = mnt_want_write_file(f.file);
68591 if (!error) {
68592- error = removexattr(dentry, name);
68593+ error = removexattr(path, name);
68594 mnt_drop_write_file(f.file);
68595 }
68596 fdput(f);
68597diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
68598index 86df952..ac430d6 100644
68599--- a/fs/xfs/libxfs/xfs_bmap.c
68600+++ b/fs/xfs/libxfs/xfs_bmap.c
68601@@ -583,7 +583,7 @@ xfs_bmap_validate_ret(
68602
68603 #else
68604 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
68605-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
68606+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
68607 #endif /* DEBUG */
68608
68609 /*
68610diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
68611index f1b69ed..3d0222f 100644
68612--- a/fs/xfs/xfs_dir2_readdir.c
68613+++ b/fs/xfs/xfs_dir2_readdir.c
68614@@ -159,7 +159,12 @@ xfs_dir2_sf_getdents(
68615 ino = dp->d_ops->sf_get_ino(sfp, sfep);
68616 filetype = dp->d_ops->sf_get_ftype(sfep);
68617 ctx->pos = off & 0x7fffffff;
68618- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68619+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
68620+ char name[sfep->namelen];
68621+ memcpy(name, sfep->name, sfep->namelen);
68622+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(dp->i_mount, filetype)))
68623+ return 0;
68624+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68625 xfs_dir3_get_dtype(dp->i_mount, filetype)))
68626 return 0;
68627 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
68628diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
68629index 3799695..0ddc953 100644
68630--- a/fs/xfs/xfs_ioctl.c
68631+++ b/fs/xfs/xfs_ioctl.c
68632@@ -122,7 +122,7 @@ xfs_find_handle(
68633 }
68634
68635 error = -EFAULT;
68636- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
68637+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
68638 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
68639 goto out_put;
68640
68641diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
68642index d10dc8f..56b3430 100644
68643--- a/fs/xfs/xfs_linux.h
68644+++ b/fs/xfs/xfs_linux.h
68645@@ -230,7 +230,7 @@ static inline kgid_t xfs_gid_to_kgid(__uint32_t gid)
68646 * of the compiler which do not like us using do_div in the middle
68647 * of large functions.
68648 */
68649-static inline __u32 xfs_do_div(void *a, __u32 b, int n)
68650+static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
68651 {
68652 __u32 mod;
68653
68654@@ -286,7 +286,7 @@ static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
68655 return 0;
68656 }
68657 #else
68658-static inline __u32 xfs_do_div(void *a, __u32 b, int n)
68659+static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
68660 {
68661 __u32 mod;
68662
68663diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
68664new file mode 100644
68665index 0000000..f27264e
68666--- /dev/null
68667+++ b/grsecurity/Kconfig
68668@@ -0,0 +1,1166 @@
68669+#
68670+# grecurity configuration
68671+#
68672+menu "Memory Protections"
68673+depends on GRKERNSEC
68674+
68675+config GRKERNSEC_KMEM
68676+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
68677+ default y if GRKERNSEC_CONFIG_AUTO
68678+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
68679+ help
68680+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
68681+ be written to or read from to modify or leak the contents of the running
68682+ kernel. /dev/port will also not be allowed to be opened, writing to
68683+ /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
68684+ If you have module support disabled, enabling this will close up several
68685+ ways that are currently used to insert malicious code into the running
68686+ kernel.
68687+
68688+ Even with this feature enabled, we still highly recommend that
68689+ you use the RBAC system, as it is still possible for an attacker to
68690+ modify the running kernel through other more obscure methods.
68691+
68692+ It is highly recommended that you say Y here if you meet all the
68693+ conditions above.
68694+
68695+config GRKERNSEC_VM86
68696+ bool "Restrict VM86 mode"
68697+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68698+ depends on X86_32
68699+
68700+ help
68701+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
68702+ make use of a special execution mode on 32bit x86 processors called
68703+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
68704+ video cards and will still work with this option enabled. The purpose
68705+ of the option is to prevent exploitation of emulation errors in
68706+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
68707+ Nearly all users should be able to enable this option.
68708+
68709+config GRKERNSEC_IO
68710+ bool "Disable privileged I/O"
68711+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68712+ depends on X86
68713+ select RTC_CLASS
68714+ select RTC_INTF_DEV
68715+ select RTC_DRV_CMOS
68716+
68717+ help
68718+ If you say Y here, all ioperm and iopl calls will return an error.
68719+ Ioperm and iopl can be used to modify the running kernel.
68720+ Unfortunately, some programs need this access to operate properly,
68721+ the most notable of which are XFree86 and hwclock. hwclock can be
68722+ remedied by having RTC support in the kernel, so real-time
68723+ clock support is enabled if this option is enabled, to ensure
68724+ that hwclock operates correctly. If hwclock still does not work,
68725+ either update udev or symlink /dev/rtc to /dev/rtc0.
68726+
68727+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
68728+ you may not be able to boot into a graphical environment with this
68729+ option enabled. In this case, you should use the RBAC system instead.
68730+
68731+config GRKERNSEC_BPF_HARDEN
68732+ bool "Harden BPF interpreter"
68733+ default y if GRKERNSEC_CONFIG_AUTO
68734+ help
68735+ Unlike previous versions of grsecurity that hardened both the BPF
68736+ interpreted code against corruption at rest as well as the JIT code
68737+ against JIT-spray attacks and attacker-controlled immediate values
68738+ for ROP, this feature will enforce disabling of the new eBPF JIT engine
68739+ and will ensure the interpreted code is read-only at rest. This feature
68740+ may be removed at a later time when eBPF stabilizes to entirely revert
68741+ back to the more secure pre-3.16 BPF interpreter/JIT.
68742+
68743+ If you're using KERNEXEC, it's recommended that you enable this option
68744+ to supplement the hardening of the kernel.
68745+
68746+config GRKERNSEC_PERF_HARDEN
68747+ bool "Disable unprivileged PERF_EVENTS usage by default"
68748+ default y if GRKERNSEC_CONFIG_AUTO
68749+ depends on PERF_EVENTS
68750+ help
68751+ If you say Y here, the range of acceptable values for the
68752+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
68753+ default to a new value: 3. When the sysctl is set to this value, no
68754+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
68755+
68756+ Though PERF_EVENTS can be used legitimately for performance monitoring
68757+ and low-level application profiling, it is forced on regardless of
68758+ configuration, has been at fault for several vulnerabilities, and
68759+ creates new opportunities for side channels and other information leaks.
68760+
68761+ This feature puts PERF_EVENTS into a secure default state and permits
68762+ the administrator to change out of it temporarily if unprivileged
68763+ application profiling is needed.
68764+
68765+config GRKERNSEC_RAND_THREADSTACK
68766+ bool "Insert random gaps between thread stacks"
68767+ default y if GRKERNSEC_CONFIG_AUTO
68768+ depends on PAX_RANDMMAP && !PPC
68769+ help
68770+ If you say Y here, a random-sized gap will be enforced between allocated
68771+ thread stacks. Glibc's NPTL and other threading libraries that
68772+ pass MAP_STACK to the kernel for thread stack allocation are supported.
68773+ The implementation currently provides 8 bits of entropy for the gap.
68774+
68775+ Many distributions do not compile threaded remote services with the
68776+ -fstack-check argument to GCC, causing the variable-sized stack-based
68777+ allocator, alloca(), to not probe the stack on allocation. This
68778+ permits an unbounded alloca() to skip over any guard page and potentially
68779+ modify another thread's stack reliably. An enforced random gap
68780+ reduces the reliability of such an attack and increases the chance
68781+ that such a read/write to another thread's stack instead lands in
68782+ an unmapped area, causing a crash and triggering grsecurity's
68783+ anti-bruteforcing logic.
68784+
68785+config GRKERNSEC_PROC_MEMMAP
68786+ bool "Harden ASLR against information leaks and entropy reduction"
68787+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
68788+ depends on PAX_NOEXEC || PAX_ASLR
68789+ help
68790+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
68791+ give no information about the addresses of its mappings if
68792+ PaX features that rely on random addresses are enabled on the task.
68793+ In addition to sanitizing this information and disabling other
68794+ dangerous sources of information, this option causes reads of sensitive
68795+ /proc/<pid> entries where the file descriptor was opened in a different
68796+ task than the one performing the read. Such attempts are logged.
68797+ This option also limits argv/env strings for suid/sgid binaries
68798+ to 512KB to prevent a complete exhaustion of the stack entropy provided
68799+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
68800+ binaries to prevent alternative mmap layouts from being abused.
68801+
68802+ If you use PaX it is essential that you say Y here as it closes up
68803+ several holes that make full ASLR useless locally.
68804+
68805+
68806+config GRKERNSEC_KSTACKOVERFLOW
68807+ bool "Prevent kernel stack overflows"
68808+ default y if GRKERNSEC_CONFIG_AUTO
68809+ depends on !IA64 && 64BIT
68810+ help
68811+ If you say Y here, the kernel's process stacks will be allocated
68812+ with vmalloc instead of the kernel's default allocator. This
68813+ introduces guard pages that in combination with the alloca checking
68814+ of the STACKLEAK feature prevents all forms of kernel process stack
68815+ overflow abuse. Note that this is different from kernel stack
68816+ buffer overflows.
68817+
68818+config GRKERNSEC_BRUTE
68819+ bool "Deter exploit bruteforcing"
68820+ default y if GRKERNSEC_CONFIG_AUTO
68821+ help
68822+ If you say Y here, attempts to bruteforce exploits against forking
68823+ daemons such as apache or sshd, as well as against suid/sgid binaries
68824+ will be deterred. When a child of a forking daemon is killed by PaX
68825+ or crashes due to an illegal instruction or other suspicious signal,
68826+ the parent process will be delayed 30 seconds upon every subsequent
68827+ fork until the administrator is able to assess the situation and
68828+ restart the daemon.
68829+ In the suid/sgid case, the attempt is logged, the user has all their
68830+ existing instances of the suid/sgid binary terminated and will
68831+ be unable to execute any suid/sgid binaries for 15 minutes.
68832+
68833+ It is recommended that you also enable signal logging in the auditing
68834+ section so that logs are generated when a process triggers a suspicious
68835+ signal.
68836+ If the sysctl option is enabled, a sysctl option with name
68837+ "deter_bruteforce" is created.
68838+
68839+config GRKERNSEC_MODHARDEN
68840+ bool "Harden module auto-loading"
68841+ default y if GRKERNSEC_CONFIG_AUTO
68842+ depends on MODULES
68843+ help
68844+ If you say Y here, module auto-loading in response to use of some
68845+ feature implemented by an unloaded module will be restricted to
68846+ root users. Enabling this option helps defend against attacks
68847+ by unprivileged users who abuse the auto-loading behavior to
68848+ cause a vulnerable module to load that is then exploited.
68849+
68850+ If this option prevents a legitimate use of auto-loading for a
68851+ non-root user, the administrator can execute modprobe manually
68852+ with the exact name of the module mentioned in the alert log.
68853+ Alternatively, the administrator can add the module to the list
68854+ of modules loaded at boot by modifying init scripts.
68855+
68856+ Modification of init scripts will most likely be needed on
68857+ Ubuntu servers with encrypted home directory support enabled,
68858+ as the first non-root user logging in will cause the ecb(aes),
68859+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
68860+
68861+config GRKERNSEC_HIDESYM
68862+ bool "Hide kernel symbols"
68863+ default y if GRKERNSEC_CONFIG_AUTO
68864+ select PAX_USERCOPY_SLABS
68865+ help
68866+ If you say Y here, getting information on loaded modules, and
68867+ displaying all kernel symbols through a syscall will be restricted
68868+ to users with CAP_SYS_MODULE. For software compatibility reasons,
68869+ /proc/kallsyms will be restricted to the root user. The RBAC
68870+ system can hide that entry even from root.
68871+
68872+ This option also prevents leaking of kernel addresses through
68873+ several /proc entries.
68874+
68875+ Note that this option is only effective provided the following
68876+ conditions are met:
68877+ 1) The kernel using grsecurity is not precompiled by some distribution
68878+ 2) You have also enabled GRKERNSEC_DMESG
68879+ 3) You are using the RBAC system and hiding other files such as your
68880+ kernel image and System.map. Alternatively, enabling this option
68881+ causes the permissions on /boot, /lib/modules, and the kernel
68882+ source directory to change at compile time to prevent
68883+ reading by non-root users.
68884+ If the above conditions are met, this option will aid in providing a
68885+ useful protection against local kernel exploitation of overflows
68886+ and arbitrary read/write vulnerabilities.
68887+
68888+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
68889+ in addition to this feature.
68890+
68891+config GRKERNSEC_RANDSTRUCT
68892+ bool "Randomize layout of sensitive kernel structures"
68893+ default y if GRKERNSEC_CONFIG_AUTO
68894+ select GRKERNSEC_HIDESYM
68895+ select MODVERSIONS if MODULES
68896+ help
68897+ If you say Y here, the layouts of a number of sensitive kernel
68898+ structures (task, fs, cred, etc) and all structures composed entirely
68899+ of function pointers (aka "ops" structs) will be randomized at compile-time.
68900+ This can introduce the requirement of an additional infoleak
68901+ vulnerability for exploits targeting these structure types.
68902+
68903+ Enabling this feature will introduce some performance impact, slightly
68904+ increase memory usage, and prevent the use of forensic tools like
68905+ Volatility against the system (unless the kernel source tree isn't
68906+ cleaned after kernel installation).
68907+
68908+ The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
68909+ It remains after a make clean to allow for external modules to be compiled
68910+ with the existing seed and will be removed by a make mrproper or
68911+ make distclean.
68912+
68913+ Note that the implementation requires gcc 4.6.4. or newer. You may need
68914+ to install the supporting headers explicitly in addition to the normal
68915+ gcc package.
68916+
68917+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
68918+ bool "Use cacheline-aware structure randomization"
68919+ depends on GRKERNSEC_RANDSTRUCT
68920+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
68921+ help
68922+ If you say Y here, the RANDSTRUCT randomization will make a best effort
68923+ at restricting randomization to cacheline-sized groups of elements. It
68924+ will further not randomize bitfields in structures. This reduces the
68925+ performance hit of RANDSTRUCT at the cost of weakened randomization.
68926+
68927+config GRKERNSEC_KERN_LOCKOUT
68928+ bool "Active kernel exploit response"
68929+ default y if GRKERNSEC_CONFIG_AUTO
68930+ depends on X86 || ARM || PPC || SPARC
68931+ help
68932+ If you say Y here, when a PaX alert is triggered due to suspicious
68933+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
68934+ or an OOPS occurs due to bad memory accesses, instead of just
68935+ terminating the offending process (and potentially allowing
68936+ a subsequent exploit from the same user), we will take one of two
68937+ actions:
68938+ If the user was root, we will panic the system
68939+ If the user was non-root, we will log the attempt, terminate
68940+ all processes owned by the user, then prevent them from creating
68941+ any new processes until the system is restarted
68942+ This deters repeated kernel exploitation/bruteforcing attempts
68943+ and is useful for later forensics.
68944+
68945+config GRKERNSEC_OLD_ARM_USERLAND
68946+ bool "Old ARM userland compatibility"
68947+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
68948+ help
68949+ If you say Y here, stubs of executable code to perform such operations
68950+ as "compare-exchange" will be placed at fixed locations in the ARM vector
68951+ table. This is unfortunately needed for old ARM userland meant to run
68952+ across a wide range of processors. Without this option enabled,
68953+ the get_tls and data memory barrier stubs will be emulated by the kernel,
68954+ which is enough for Linaro userlands or other userlands designed for v6
68955+ and newer ARM CPUs. It's recommended that you try without this option enabled
68956+ first, and only enable it if your userland does not boot (it will likely fail
68957+ at init time).
68958+
68959+endmenu
68960+menu "Role Based Access Control Options"
68961+depends on GRKERNSEC
68962+
68963+config GRKERNSEC_RBAC_DEBUG
68964+ bool
68965+
68966+config GRKERNSEC_NO_RBAC
68967+ bool "Disable RBAC system"
68968+ help
68969+ If you say Y here, the /dev/grsec device will be removed from the kernel,
68970+ preventing the RBAC system from being enabled. You should only say Y
68971+ here if you have no intention of using the RBAC system, so as to prevent
68972+ an attacker with root access from misusing the RBAC system to hide files
68973+ and processes when loadable module support and /dev/[k]mem have been
68974+ locked down.
68975+
68976+config GRKERNSEC_ACL_HIDEKERN
68977+ bool "Hide kernel processes"
68978+ help
68979+ If you say Y here, all kernel threads will be hidden to all
68980+ processes but those whose subject has the "view hidden processes"
68981+ flag.
68982+
68983+config GRKERNSEC_ACL_MAXTRIES
68984+ int "Maximum tries before password lockout"
68985+ default 3
68986+ help
68987+ This option enforces the maximum number of times a user can attempt
68988+ to authorize themselves with the grsecurity RBAC system before being
68989+ denied the ability to attempt authorization again for a specified time.
68990+ The lower the number, the harder it will be to brute-force a password.
68991+
68992+config GRKERNSEC_ACL_TIMEOUT
68993+ int "Time to wait after max password tries, in seconds"
68994+ default 30
68995+ help
68996+ This option specifies the time the user must wait after attempting to
68997+ authorize to the RBAC system with the maximum number of invalid
68998+ passwords. The higher the number, the harder it will be to brute-force
68999+ a password.
69000+
69001+endmenu
69002+menu "Filesystem Protections"
69003+depends on GRKERNSEC
69004+
69005+config GRKERNSEC_PROC
69006+ bool "Proc restrictions"
69007+ default y if GRKERNSEC_CONFIG_AUTO
69008+ help
69009+ If you say Y here, the permissions of the /proc filesystem
69010+ will be altered to enhance system security and privacy. You MUST
69011+ choose either a user only restriction or a user and group restriction.
69012+ Depending upon the option you choose, you can either restrict users to
69013+ see only the processes they themselves run, or choose a group that can
69014+ view all processes and files normally restricted to root if you choose
69015+ the "restrict to user only" option. NOTE: If you're running identd or
69016+ ntpd as a non-root user, you will have to run it as the group you
69017+ specify here.
69018+
69019+config GRKERNSEC_PROC_USER
69020+ bool "Restrict /proc to user only"
69021+ depends on GRKERNSEC_PROC
69022+ help
69023+ If you say Y here, non-root users will only be able to view their own
69024+ processes, and restricts them from viewing network-related information,
69025+ and viewing kernel symbol and module information.
69026+
69027+config GRKERNSEC_PROC_USERGROUP
69028+ bool "Allow special group"
69029+ default y if GRKERNSEC_CONFIG_AUTO
69030+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
69031+ help
69032+ If you say Y here, you will be able to select a group that will be
69033+ able to view all processes and network-related information. If you've
69034+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
69035+ remain hidden. This option is useful if you want to run identd as
69036+ a non-root user. The group you select may also be chosen at boot time
69037+ via "grsec_proc_gid=" on the kernel commandline.
69038+
69039+config GRKERNSEC_PROC_GID
69040+ int "GID for special group"
69041+ depends on GRKERNSEC_PROC_USERGROUP
69042+ default 1001
69043+
69044+config GRKERNSEC_PROC_ADD
69045+ bool "Additional restrictions"
69046+ default y if GRKERNSEC_CONFIG_AUTO
69047+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
69048+ help
69049+ If you say Y here, additional restrictions will be placed on
69050+ /proc that keep normal users from viewing device information and
69051+ slabinfo information that could be useful for exploits.
69052+
69053+config GRKERNSEC_LINK
69054+ bool "Linking restrictions"
69055+ default y if GRKERNSEC_CONFIG_AUTO
69056+ help
69057+ If you say Y here, /tmp race exploits will be prevented, since users
69058+ will no longer be able to follow symlinks owned by other users in
69059+ world-writable +t directories (e.g. /tmp), unless the owner of the
69060+ symlink is the owner of the directory. users will also not be
69061+ able to hardlink to files they do not own. If the sysctl option is
69062+ enabled, a sysctl option with name "linking_restrictions" is created.
69063+
69064+config GRKERNSEC_SYMLINKOWN
69065+ bool "Kernel-enforced SymlinksIfOwnerMatch"
69066+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
69067+ help
69068+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
69069+ that prevents it from being used as a security feature. As Apache
69070+ verifies the symlink by performing a stat() against the target of
69071+ the symlink before it is followed, an attacker can setup a symlink
69072+ to point to a same-owned file, then replace the symlink with one
69073+ that targets another user's file just after Apache "validates" the
69074+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
69075+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
69076+ will be in place for the group you specify. If the sysctl option
69077+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
69078+ created.
69079+
69080+config GRKERNSEC_SYMLINKOWN_GID
69081+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
69082+ depends on GRKERNSEC_SYMLINKOWN
69083+ default 1006
69084+ help
69085+ Setting this GID determines what group kernel-enforced
69086+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
69087+ is enabled, a sysctl option with name "symlinkown_gid" is created.
69088+
69089+config GRKERNSEC_FIFO
69090+ bool "FIFO restrictions"
69091+ default y if GRKERNSEC_CONFIG_AUTO
69092+ help
69093+ If you say Y here, users will not be able to write to FIFOs they don't
69094+ own in world-writable +t directories (e.g. /tmp), unless the owner of
69095+ the FIFO is the same owner of the directory it's held in. If the sysctl
69096+ option is enabled, a sysctl option with name "fifo_restrictions" is
69097+ created.
69098+
69099+config GRKERNSEC_SYSFS_RESTRICT
69100+ bool "Sysfs/debugfs restriction"
69101+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
69102+ depends on SYSFS
69103+ help
69104+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
69105+ any filesystem normally mounted under it (e.g. debugfs) will be
69106+ mostly accessible only by root. These filesystems generally provide access
69107+ to hardware and debug information that isn't appropriate for unprivileged
69108+ users of the system. Sysfs and debugfs have also become a large source
69109+ of new vulnerabilities, ranging from infoleaks to local compromise.
69110+ There has been very little oversight with an eye toward security involved
69111+ in adding new exporters of information to these filesystems, so their
69112+ use is discouraged.
69113+ For reasons of compatibility, a few directories have been whitelisted
69114+ for access by non-root users:
69115+ /sys/fs/selinux
69116+ /sys/fs/fuse
69117+ /sys/devices/system/cpu
69118+
69119+config GRKERNSEC_ROFS
69120+ bool "Runtime read-only mount protection"
69121+ depends on SYSCTL
69122+ help
69123+ If you say Y here, a sysctl option with name "romount_protect" will
69124+ be created. By setting this option to 1 at runtime, filesystems
69125+ will be protected in the following ways:
69126+ * No new writable mounts will be allowed
69127+ * Existing read-only mounts won't be able to be remounted read/write
69128+ * Write operations will be denied on all block devices
69129+ This option acts independently of grsec_lock: once it is set to 1,
69130+ it cannot be turned off. Therefore, please be mindful of the resulting
69131+ behavior if this option is enabled in an init script on a read-only
69132+ filesystem.
69133+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
69134+ and GRKERNSEC_IO should be enabled and module loading disabled via
69135+ config or at runtime.
69136+ This feature is mainly intended for secure embedded systems.
69137+
69138+
69139+config GRKERNSEC_DEVICE_SIDECHANNEL
69140+ bool "Eliminate stat/notify-based device sidechannels"
69141+ default y if GRKERNSEC_CONFIG_AUTO
69142+ help
69143+ If you say Y here, timing analyses on block or character
69144+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
69145+ will be thwarted for unprivileged users. If a process without
69146+ CAP_MKNOD stats such a device, the last access and last modify times
69147+ will match the device's create time. No access or modify events
69148+ will be triggered through inotify/dnotify/fanotify for such devices.
69149+ This feature will prevent attacks that may at a minimum
69150+ allow an attacker to determine the administrator's password length.
69151+
69152+config GRKERNSEC_CHROOT
69153+ bool "Chroot jail restrictions"
69154+ default y if GRKERNSEC_CONFIG_AUTO
69155+ help
69156+ If you say Y here, you will be able to choose several options that will
69157+ make breaking out of a chrooted jail much more difficult. If you
69158+ encounter no software incompatibilities with the following options, it
69159+ is recommended that you enable each one.
69160+
69161+ Note that the chroot restrictions are not intended to apply to "chroots"
69162+ to directories that are simple bind mounts of the global root filesystem.
69163+ For several other reasons, a user shouldn't expect any significant
69164+ security by performing such a chroot.
69165+
69166+config GRKERNSEC_CHROOT_MOUNT
69167+ bool "Deny mounts"
69168+ default y if GRKERNSEC_CONFIG_AUTO
69169+ depends on GRKERNSEC_CHROOT
69170+ help
69171+ If you say Y here, processes inside a chroot will not be able to
69172+ mount or remount filesystems. If the sysctl option is enabled, a
69173+ sysctl option with name "chroot_deny_mount" is created.
69174+
69175+config GRKERNSEC_CHROOT_DOUBLE
69176+ bool "Deny double-chroots"
69177+ default y if GRKERNSEC_CONFIG_AUTO
69178+ depends on GRKERNSEC_CHROOT
69179+ help
69180+ If you say Y here, processes inside a chroot will not be able to chroot
69181+ again outside the chroot. This is a widely used method of breaking
69182+ out of a chroot jail and should not be allowed. If the sysctl
69183+ option is enabled, a sysctl option with name
69184+ "chroot_deny_chroot" is created.
69185+
69186+config GRKERNSEC_CHROOT_PIVOT
69187+ bool "Deny pivot_root in chroot"
69188+ default y if GRKERNSEC_CONFIG_AUTO
69189+ depends on GRKERNSEC_CHROOT
69190+ help
69191+ If you say Y here, processes inside a chroot will not be able to use
69192+ a function called pivot_root() that was introduced in Linux 2.3.41. It
69193+ works similar to chroot in that it changes the root filesystem. This
69194+ function could be misused in a chrooted process to attempt to break out
69195+ of the chroot, and therefore should not be allowed. If the sysctl
69196+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
69197+ created.
69198+
69199+config GRKERNSEC_CHROOT_CHDIR
69200+ bool "Enforce chdir(\"/\") on all chroots"
69201+ default y if GRKERNSEC_CONFIG_AUTO
69202+ depends on GRKERNSEC_CHROOT
69203+ help
69204+ If you say Y here, the current working directory of all newly-chrooted
69205+ applications will be set to the the root directory of the chroot.
69206+ The man page on chroot(2) states:
69207+ Note that this call does not change the current working
69208+ directory, so that `.' can be outside the tree rooted at
69209+ `/'. In particular, the super-user can escape from a
69210+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
69211+
69212+ It is recommended that you say Y here, since it's not known to break
69213+ any software. If the sysctl option is enabled, a sysctl option with
69214+ name "chroot_enforce_chdir" is created.
69215+
69216+config GRKERNSEC_CHROOT_CHMOD
69217+ bool "Deny (f)chmod +s"
69218+ default y if GRKERNSEC_CONFIG_AUTO
69219+ depends on GRKERNSEC_CHROOT
69220+ help
69221+ If you say Y here, processes inside a chroot will not be able to chmod
69222+ or fchmod files to make them have suid or sgid bits. This protects
69223+ against another published method of breaking a chroot. If the sysctl
69224+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
69225+ created.
69226+
69227+config GRKERNSEC_CHROOT_FCHDIR
69228+ bool "Deny fchdir and fhandle out of chroot"
69229+ default y if GRKERNSEC_CONFIG_AUTO
69230+ depends on GRKERNSEC_CHROOT
69231+ help
69232+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
69233+ to a file descriptor of the chrooting process that points to a directory
69234+ outside the filesystem will be stopped. Additionally, this option prevents
69235+ use of the recently-created syscall for opening files by a guessable "file
69236+ handle" inside a chroot. If the sysctl option is enabled, a sysctl option
69237+ with name "chroot_deny_fchdir" is created.
69238+
69239+config GRKERNSEC_CHROOT_MKNOD
69240+ bool "Deny mknod"
69241+ default y if GRKERNSEC_CONFIG_AUTO
69242+ depends on GRKERNSEC_CHROOT
69243+ help
69244+ If you say Y here, processes inside a chroot will not be allowed to
69245+ mknod. The problem with using mknod inside a chroot is that it
69246+ would allow an attacker to create a device entry that is the same
69247+ as one on the physical root of your system, which could range from
69248+ anything from the console device to a device for your harddrive (which
69249+ they could then use to wipe the drive or steal data). It is recommended
69250+ that you say Y here, unless you run into software incompatibilities.
69251+ If the sysctl option is enabled, a sysctl option with name
69252+ "chroot_deny_mknod" is created.
69253+
69254+config GRKERNSEC_CHROOT_SHMAT
69255+ bool "Deny shmat() out of chroot"
69256+ default y if GRKERNSEC_CONFIG_AUTO
69257+ depends on GRKERNSEC_CHROOT
69258+ help
69259+ If you say Y here, processes inside a chroot will not be able to attach
69260+ to shared memory segments that were created outside of the chroot jail.
69261+ It is recommended that you say Y here. If the sysctl option is enabled,
69262+ a sysctl option with name "chroot_deny_shmat" is created.
69263+
69264+config GRKERNSEC_CHROOT_UNIX
69265+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
69266+ default y if GRKERNSEC_CONFIG_AUTO
69267+ depends on GRKERNSEC_CHROOT
69268+ help
69269+ If you say Y here, processes inside a chroot will not be able to
69270+ connect to abstract (meaning not belonging to a filesystem) Unix
69271+ domain sockets that were bound outside of a chroot. It is recommended
69272+ that you say Y here. If the sysctl option is enabled, a sysctl option
69273+ with name "chroot_deny_unix" is created.
69274+
69275+config GRKERNSEC_CHROOT_FINDTASK
69276+ bool "Protect outside processes"
69277+ default y if GRKERNSEC_CONFIG_AUTO
69278+ depends on GRKERNSEC_CHROOT
69279+ help
69280+ If you say Y here, processes inside a chroot will not be able to
69281+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
69282+ getsid, or view any process outside of the chroot. If the sysctl
69283+ option is enabled, a sysctl option with name "chroot_findtask" is
69284+ created.
69285+
69286+config GRKERNSEC_CHROOT_NICE
69287+ bool "Restrict priority changes"
69288+ default y if GRKERNSEC_CONFIG_AUTO
69289+ depends on GRKERNSEC_CHROOT
69290+ help
69291+ If you say Y here, processes inside a chroot will not be able to raise
69292+ the priority of processes in the chroot, or alter the priority of
69293+ processes outside the chroot. This provides more security than simply
69294+ removing CAP_SYS_NICE from the process' capability set. If the
69295+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
69296+ is created.
69297+
69298+config GRKERNSEC_CHROOT_SYSCTL
69299+ bool "Deny sysctl writes"
69300+ default y if GRKERNSEC_CONFIG_AUTO
69301+ depends on GRKERNSEC_CHROOT
69302+ help
69303+ If you say Y here, an attacker in a chroot will not be able to
69304+ write to sysctl entries, either by sysctl(2) or through a /proc
69305+ interface. It is strongly recommended that you say Y here. If the
69306+ sysctl option is enabled, a sysctl option with name
69307+ "chroot_deny_sysctl" is created.
69308+
69309+config GRKERNSEC_CHROOT_CAPS
69310+ bool "Capability restrictions"
69311+ default y if GRKERNSEC_CONFIG_AUTO
69312+ depends on GRKERNSEC_CHROOT
69313+ help
69314+ If you say Y here, the capabilities on all processes within a
69315+ chroot jail will be lowered to stop module insertion, raw i/o,
69316+ system and net admin tasks, rebooting the system, modifying immutable
69317+ files, modifying IPC owned by another, and changing the system time.
69318+ This is left an option because it can break some apps. Disable this
69319+ if your chrooted apps are having problems performing those kinds of
69320+ tasks. If the sysctl option is enabled, a sysctl option with
69321+ name "chroot_caps" is created.
69322+
69323+config GRKERNSEC_CHROOT_INITRD
69324+ bool "Exempt initrd tasks from restrictions"
69325+ default y if GRKERNSEC_CONFIG_AUTO
69326+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
69327+ help
69328+ If you say Y here, tasks started prior to init will be exempted from
69329+ grsecurity's chroot restrictions. This option is mainly meant to
69330+ resolve Plymouth's performing privileged operations unnecessarily
69331+ in a chroot.
69332+
69333+endmenu
69334+menu "Kernel Auditing"
69335+depends on GRKERNSEC
69336+
69337+config GRKERNSEC_AUDIT_GROUP
69338+ bool "Single group for auditing"
69339+ help
69340+ If you say Y here, the exec and chdir logging features will only operate
69341+ on a group you specify. This option is recommended if you only want to
69342+ watch certain users instead of having a large amount of logs from the
69343+ entire system. If the sysctl option is enabled, a sysctl option with
69344+ name "audit_group" is created.
69345+
69346+config GRKERNSEC_AUDIT_GID
69347+ int "GID for auditing"
69348+ depends on GRKERNSEC_AUDIT_GROUP
69349+ default 1007
69350+
69351+config GRKERNSEC_EXECLOG
69352+ bool "Exec logging"
69353+ help
69354+ If you say Y here, all execve() calls will be logged (since the
69355+ other exec*() calls are frontends to execve(), all execution
69356+ will be logged). Useful for shell-servers that like to keep track
69357+ of their users. If the sysctl option is enabled, a sysctl option with
69358+ name "exec_logging" is created.
69359+ WARNING: This option when enabled will produce a LOT of logs, especially
69360+ on an active system.
69361+
69362+config GRKERNSEC_RESLOG
69363+ bool "Resource logging"
69364+ default y if GRKERNSEC_CONFIG_AUTO
69365+ help
69366+ If you say Y here, all attempts to overstep resource limits will
69367+ be logged with the resource name, the requested size, and the current
69368+ limit. It is highly recommended that you say Y here. If the sysctl
69369+ option is enabled, a sysctl option with name "resource_logging" is
69370+ created. If the RBAC system is enabled, the sysctl value is ignored.
69371+
69372+config GRKERNSEC_CHROOT_EXECLOG
69373+ bool "Log execs within chroot"
69374+ help
69375+ If you say Y here, all executions inside a chroot jail will be logged
69376+ to syslog. This can cause a large amount of logs if certain
69377+ applications (eg. djb's daemontools) are installed on the system, and
69378+ is therefore left as an option. If the sysctl option is enabled, a
69379+ sysctl option with name "chroot_execlog" is created.
69380+
69381+config GRKERNSEC_AUDIT_PTRACE
69382+ bool "Ptrace logging"
69383+ help
69384+ If you say Y here, all attempts to attach to a process via ptrace
69385+ will be logged. If the sysctl option is enabled, a sysctl option
69386+ with name "audit_ptrace" is created.
69387+
69388+config GRKERNSEC_AUDIT_CHDIR
69389+ bool "Chdir logging"
69390+ help
69391+ If you say Y here, all chdir() calls will be logged. If the sysctl
69392+ option is enabled, a sysctl option with name "audit_chdir" is created.
69393+
69394+config GRKERNSEC_AUDIT_MOUNT
69395+ bool "(Un)Mount logging"
69396+ help
69397+ If you say Y here, all mounts and unmounts will be logged. If the
69398+ sysctl option is enabled, a sysctl option with name "audit_mount" is
69399+ created.
69400+
69401+config GRKERNSEC_SIGNAL
69402+ bool "Signal logging"
69403+ default y if GRKERNSEC_CONFIG_AUTO
69404+ help
69405+ If you say Y here, certain important signals will be logged, such as
69406+ SIGSEGV, which will as a result inform you of when a error in a program
69407+ occurred, which in some cases could mean a possible exploit attempt.
69408+ If the sysctl option is enabled, a sysctl option with name
69409+ "signal_logging" is created.
69410+
69411+config GRKERNSEC_FORKFAIL
69412+ bool "Fork failure logging"
69413+ help
69414+ If you say Y here, all failed fork() attempts will be logged.
69415+ This could suggest a fork bomb, or someone attempting to overstep
69416+ their process limit. If the sysctl option is enabled, a sysctl option
69417+ with name "forkfail_logging" is created.
69418+
69419+config GRKERNSEC_TIME
69420+ bool "Time change logging"
69421+ default y if GRKERNSEC_CONFIG_AUTO
69422+ help
69423+ If you say Y here, any changes of the system clock will be logged.
69424+ If the sysctl option is enabled, a sysctl option with name
69425+ "timechange_logging" is created.
69426+
69427+config GRKERNSEC_PROC_IPADDR
69428+ bool "/proc/<pid>/ipaddr support"
69429+ default y if GRKERNSEC_CONFIG_AUTO
69430+ help
69431+ If you say Y here, a new entry will be added to each /proc/<pid>
69432+ directory that contains the IP address of the person using the task.
69433+ The IP is carried across local TCP and AF_UNIX stream sockets.
69434+ This information can be useful for IDS/IPSes to perform remote response
69435+ to a local attack. The entry is readable by only the owner of the
69436+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
69437+ the RBAC system), and thus does not create privacy concerns.
69438+
69439+config GRKERNSEC_RWXMAP_LOG
69440+ bool 'Denied RWX mmap/mprotect logging'
69441+ default y if GRKERNSEC_CONFIG_AUTO
69442+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
69443+ help
69444+ If you say Y here, calls to mmap() and mprotect() with explicit
69445+ usage of PROT_WRITE and PROT_EXEC together will be logged when
69446+ denied by the PAX_MPROTECT feature. This feature will also
69447+ log other problematic scenarios that can occur when PAX_MPROTECT
69448+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
69449+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
69450+ is created.
69451+
69452+endmenu
69453+
69454+menu "Executable Protections"
69455+depends on GRKERNSEC
69456+
69457+config GRKERNSEC_DMESG
69458+ bool "Dmesg(8) restriction"
69459+ default y if GRKERNSEC_CONFIG_AUTO
69460+ help
69461+ If you say Y here, non-root users will not be able to use dmesg(8)
69462+ to view the contents of the kernel's circular log buffer.
69463+ The kernel's log buffer often contains kernel addresses and other
69464+ identifying information useful to an attacker in fingerprinting a
69465+ system for a targeted exploit.
69466+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
69467+ created.
69468+
69469+config GRKERNSEC_HARDEN_PTRACE
69470+ bool "Deter ptrace-based process snooping"
69471+ default y if GRKERNSEC_CONFIG_AUTO
69472+ help
69473+ If you say Y here, TTY sniffers and other malicious monitoring
69474+ programs implemented through ptrace will be defeated. If you
69475+ have been using the RBAC system, this option has already been
69476+ enabled for several years for all users, with the ability to make
69477+ fine-grained exceptions.
69478+
69479+ This option only affects the ability of non-root users to ptrace
69480+ processes that are not a descendent of the ptracing process.
69481+ This means that strace ./binary and gdb ./binary will still work,
69482+ but attaching to arbitrary processes will not. If the sysctl
69483+ option is enabled, a sysctl option with name "harden_ptrace" is
69484+ created.
69485+
69486+config GRKERNSEC_PTRACE_READEXEC
69487+ bool "Require read access to ptrace sensitive binaries"
69488+ default y if GRKERNSEC_CONFIG_AUTO
69489+ help
69490+ If you say Y here, unprivileged users will not be able to ptrace unreadable
69491+ binaries. This option is useful in environments that
69492+ remove the read bits (e.g. file mode 4711) from suid binaries to
69493+ prevent infoleaking of their contents. This option adds
69494+ consistency to the use of that file mode, as the binary could normally
69495+ be read out when run without privileges while ptracing.
69496+
69497+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
69498+ is created.
69499+
69500+config GRKERNSEC_SETXID
69501+ bool "Enforce consistent multithreaded privileges"
69502+ default y if GRKERNSEC_CONFIG_AUTO
69503+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
69504+ help
69505+ If you say Y here, a change from a root uid to a non-root uid
69506+ in a multithreaded application will cause the resulting uids,
69507+ gids, supplementary groups, and capabilities in that thread
69508+ to be propagated to the other threads of the process. In most
69509+ cases this is unnecessary, as glibc will emulate this behavior
69510+ on behalf of the application. Other libcs do not act in the
69511+ same way, allowing the other threads of the process to continue
69512+ running with root privileges. If the sysctl option is enabled,
69513+ a sysctl option with name "consistent_setxid" is created.
69514+
69515+config GRKERNSEC_HARDEN_IPC
69516+ bool "Disallow access to overly-permissive IPC objects"
69517+ default y if GRKERNSEC_CONFIG_AUTO
69518+ depends on SYSVIPC
69519+ help
69520+ If you say Y here, access to overly-permissive IPC objects (shared
69521+ memory, message queues, and semaphores) will be denied for processes
69522+ given the following criteria beyond normal permission checks:
69523+ 1) If the IPC object is world-accessible and the euid doesn't match
69524+ that of the creator or current uid for the IPC object
69525+ 2) If the IPC object is group-accessible and the egid doesn't
69526+ match that of the creator or current gid for the IPC object
69527+ It's a common error to grant too much permission to these objects,
69528+ with impact ranging from denial of service and information leaking to
69529+ privilege escalation. This feature was developed in response to
69530+ research by Tim Brown:
69531+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
69532+ who found hundreds of such insecure usages. Processes with
69533+ CAP_IPC_OWNER are still permitted to access these IPC objects.
69534+ If the sysctl option is enabled, a sysctl option with name
69535+ "harden_ipc" is created.
69536+
69537+config GRKERNSEC_TPE
69538+ bool "Trusted Path Execution (TPE)"
69539+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
69540+ help
69541+ If you say Y here, you will be able to choose a gid to add to the
69542+ supplementary groups of users you want to mark as "untrusted."
69543+ These users will not be able to execute any files that are not in
69544+ root-owned directories writable only by root. If the sysctl option
69545+ is enabled, a sysctl option with name "tpe" is created.
69546+
69547+config GRKERNSEC_TPE_ALL
69548+ bool "Partially restrict all non-root users"
69549+ depends on GRKERNSEC_TPE
69550+ help
69551+ If you say Y here, all non-root users will be covered under
69552+ a weaker TPE restriction. This is separate from, and in addition to,
69553+ the main TPE options that you have selected elsewhere. Thus, if a
69554+ "trusted" GID is chosen, this restriction applies to even that GID.
69555+ Under this restriction, all non-root users will only be allowed to
69556+ execute files in directories they own that are not group or
69557+ world-writable, or in directories owned by root and writable only by
69558+ root. If the sysctl option is enabled, a sysctl option with name
69559+ "tpe_restrict_all" is created.
69560+
69561+config GRKERNSEC_TPE_INVERT
69562+ bool "Invert GID option"
69563+ depends on GRKERNSEC_TPE
69564+ help
69565+ If you say Y here, the group you specify in the TPE configuration will
69566+ decide what group TPE restrictions will be *disabled* for. This
69567+ option is useful if you want TPE restrictions to be applied to most
69568+ users on the system. If the sysctl option is enabled, a sysctl option
69569+ with name "tpe_invert" is created. Unlike other sysctl options, this
69570+ entry will default to on for backward-compatibility.
69571+
69572+config GRKERNSEC_TPE_GID
69573+ int
69574+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
69575+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
69576+
69577+config GRKERNSEC_TPE_UNTRUSTED_GID
69578+ int "GID for TPE-untrusted users"
69579+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
69580+ default 1005
69581+ help
69582+ Setting this GID determines what group TPE restrictions will be
69583+ *enabled* for. If the sysctl option is enabled, a sysctl option
69584+ with name "tpe_gid" is created.
69585+
69586+config GRKERNSEC_TPE_TRUSTED_GID
69587+ int "GID for TPE-trusted users"
69588+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
69589+ default 1005
69590+ help
69591+ Setting this GID determines what group TPE restrictions will be
69592+ *disabled* for. If the sysctl option is enabled, a sysctl option
69593+ with name "tpe_gid" is created.
69594+
69595+endmenu
69596+menu "Network Protections"
69597+depends on GRKERNSEC
69598+
69599+config GRKERNSEC_BLACKHOLE
69600+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
69601+ default y if GRKERNSEC_CONFIG_AUTO
69602+ depends on NET
69603+ help
69604+ If you say Y here, neither TCP resets nor ICMP
69605+ destination-unreachable packets will be sent in response to packets
69606+ sent to ports for which no associated listening process exists.
69607+ It will also prevent the sending of ICMP protocol unreachable packets
69608+ in response to packets with unknown protocols.
69609+ This feature supports both IPV4 and IPV6 and exempts the
69610+ loopback interface from blackholing. Enabling this feature
69611+ makes a host more resilient to DoS attacks and reduces network
69612+ visibility against scanners.
69613+
69614+ The blackhole feature as-implemented is equivalent to the FreeBSD
69615+ blackhole feature, as it prevents RST responses to all packets, not
69616+ just SYNs. Under most application behavior this causes no
69617+ problems, but applications (like haproxy) may not close certain
69618+ connections in a way that cleanly terminates them on the remote
69619+ end, leaving the remote host in LAST_ACK state. Because of this
69620+ side-effect and to prevent intentional LAST_ACK DoSes, this
69621+ feature also adds automatic mitigation against such attacks.
69622+ The mitigation drastically reduces the amount of time a socket
69623+ can spend in LAST_ACK state. If you're using haproxy and not
69624+ all servers it connects to have this option enabled, consider
69625+ disabling this feature on the haproxy host.
69626+
69627+ If the sysctl option is enabled, two sysctl options with names
69628+ "ip_blackhole" and "lastack_retries" will be created.
69629+ While "ip_blackhole" takes the standard zero/non-zero on/off
69630+ toggle, "lastack_retries" uses the same kinds of values as
69631+ "tcp_retries1" and "tcp_retries2". The default value of 4
69632+ prevents a socket from lasting more than 45 seconds in LAST_ACK
69633+ state.
69634+
69635+config GRKERNSEC_NO_SIMULT_CONNECT
69636+ bool "Disable TCP Simultaneous Connect"
69637+ default y if GRKERNSEC_CONFIG_AUTO
69638+ depends on NET
69639+ help
69640+ If you say Y here, a feature by Willy Tarreau will be enabled that
69641+ removes a weakness in Linux's strict implementation of TCP that
69642+ allows two clients to connect to each other without either entering
69643+ a listening state. The weakness allows an attacker to easily prevent
69644+ a client from connecting to a known server provided the source port
69645+ for the connection is guessed correctly.
69646+
69647+ As the weakness could be used to prevent an antivirus or IPS from
69648+ fetching updates, or prevent an SSL gateway from fetching a CRL,
69649+ it should be eliminated by enabling this option. Though Linux is
69650+ one of few operating systems supporting simultaneous connect, it
69651+ has no legitimate use in practice and is rarely supported by firewalls.
69652+
69653+config GRKERNSEC_SOCKET
69654+ bool "Socket restrictions"
69655+ depends on NET
69656+ help
69657+ If you say Y here, you will be able to choose from several options.
69658+ If you assign a GID on your system and add it to the supplementary
69659+ groups of users you want to restrict socket access to, this patch
69660+ will perform up to three things, based on the option(s) you choose.
69661+
69662+config GRKERNSEC_SOCKET_ALL
69663+ bool "Deny any sockets to group"
69664+ depends on GRKERNSEC_SOCKET
69665+ help
69666+ If you say Y here, you will be able to choose a GID of whose users will
69667+ be unable to connect to other hosts from your machine or run server
69668+ applications from your machine. If the sysctl option is enabled, a
69669+ sysctl option with name "socket_all" is created.
69670+
69671+config GRKERNSEC_SOCKET_ALL_GID
69672+ int "GID to deny all sockets for"
69673+ depends on GRKERNSEC_SOCKET_ALL
69674+ default 1004
69675+ help
69676+ Here you can choose the GID to disable socket access for. Remember to
69677+ add the users you want socket access disabled for to the GID
69678+ specified here. If the sysctl option is enabled, a sysctl option
69679+ with name "socket_all_gid" is created.
69680+
69681+config GRKERNSEC_SOCKET_CLIENT
69682+ bool "Deny client sockets to group"
69683+ depends on GRKERNSEC_SOCKET
69684+ help
69685+ If you say Y here, you will be able to choose a GID of whose users will
69686+ be unable to connect to other hosts from your machine, but will be
69687+ able to run servers. If this option is enabled, all users in the group
69688+ you specify will have to use passive mode when initiating ftp transfers
69689+ from the shell on your machine. If the sysctl option is enabled, a
69690+ sysctl option with name "socket_client" is created.
69691+
69692+config GRKERNSEC_SOCKET_CLIENT_GID
69693+ int "GID to deny client sockets for"
69694+ depends on GRKERNSEC_SOCKET_CLIENT
69695+ default 1003
69696+ help
69697+ Here you can choose the GID to disable client socket access for.
69698+ Remember to add the users you want client socket access disabled for to
69699+ the GID specified here. If the sysctl option is enabled, a sysctl
69700+ option with name "socket_client_gid" is created.
69701+
69702+config GRKERNSEC_SOCKET_SERVER
69703+ bool "Deny server sockets to group"
69704+ depends on GRKERNSEC_SOCKET
69705+ help
69706+ If you say Y here, you will be able to choose a GID of whose users will
69707+ be unable to run server applications from your machine. If the sysctl
69708+ option is enabled, a sysctl option with name "socket_server" is created.
69709+
69710+config GRKERNSEC_SOCKET_SERVER_GID
69711+ int "GID to deny server sockets for"
69712+ depends on GRKERNSEC_SOCKET_SERVER
69713+ default 1002
69714+ help
69715+ Here you can choose the GID to disable server socket access for.
69716+ Remember to add the users you want server socket access disabled for to
69717+ the GID specified here. If the sysctl option is enabled, a sysctl
69718+ option with name "socket_server_gid" is created.
69719+
69720+endmenu
69721+
69722+menu "Physical Protections"
69723+depends on GRKERNSEC
69724+
69725+config GRKERNSEC_DENYUSB
69726+ bool "Deny new USB connections after toggle"
69727+ default y if GRKERNSEC_CONFIG_AUTO
69728+ depends on SYSCTL && USB_SUPPORT
69729+ help
69730+ If you say Y here, a new sysctl option with name "deny_new_usb"
69731+ will be created. Setting its value to 1 will prevent any new
69732+ USB devices from being recognized by the OS. Any attempted USB
69733+ device insertion will be logged. This option is intended to be
69734+ used against custom USB devices designed to exploit vulnerabilities
69735+ in various USB device drivers.
69736+
69737+ For greatest effectiveness, this sysctl should be set after any
69738+ relevant init scripts. This option is safe to enable in distros
69739+ as each user can choose whether or not to toggle the sysctl.
69740+
69741+config GRKERNSEC_DENYUSB_FORCE
69742+ bool "Reject all USB devices not connected at boot"
69743+ select USB
69744+ depends on GRKERNSEC_DENYUSB
69745+ help
69746+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
69747+ that doesn't involve a sysctl entry. This option should only be
69748+ enabled if you're sure you want to deny all new USB connections
69749+ at runtime and don't want to modify init scripts. This should not
69750+ be enabled by distros. It forces the core USB code to be built
69751+ into the kernel image so that all devices connected at boot time
69752+ can be recognized and new USB device connections can be prevented
69753+ prior to init running.
69754+
69755+endmenu
69756+
69757+menu "Sysctl Support"
69758+depends on GRKERNSEC && SYSCTL
69759+
69760+config GRKERNSEC_SYSCTL
69761+ bool "Sysctl support"
69762+ default y if GRKERNSEC_CONFIG_AUTO
69763+ help
69764+ If you say Y here, you will be able to change the options that
69765+ grsecurity runs with at bootup, without having to recompile your
69766+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
69767+ to enable (1) or disable (0) various features. All the sysctl entries
69768+ are mutable until the "grsec_lock" entry is set to a non-zero value.
69769+ All features enabled in the kernel configuration are disabled at boot
69770+ if you do not say Y to the "Turn on features by default" option.
69771+ All options should be set at startup, and the grsec_lock entry should
69772+ be set to a non-zero value after all the options are set.
69773+ *THIS IS EXTREMELY IMPORTANT*
69774+
69775+config GRKERNSEC_SYSCTL_DISTRO
69776+ bool "Extra sysctl support for distro makers (READ HELP)"
69777+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
69778+ help
69779+ If you say Y here, additional sysctl options will be created
69780+ for features that affect processes running as root. Therefore,
69781+ it is critical when using this option that the grsec_lock entry be
69782+ enabled after boot. Only distros with prebuilt kernel packages
69783+ with this option enabled that can ensure grsec_lock is enabled
69784+ after boot should use this option.
69785+ *Failure to set grsec_lock after boot makes all grsec features
69786+ this option covers useless*
69787+
69788+ Currently this option creates the following sysctl entries:
69789+ "Disable Privileged I/O": "disable_priv_io"
69790+
69791+config GRKERNSEC_SYSCTL_ON
69792+ bool "Turn on features by default"
69793+ default y if GRKERNSEC_CONFIG_AUTO
69794+ depends on GRKERNSEC_SYSCTL
69795+ help
69796+ If you say Y here, instead of having all features enabled in the
69797+ kernel configuration disabled at boot time, the features will be
69798+ enabled at boot time. It is recommended you say Y here unless
69799+ there is some reason you would want all sysctl-tunable features to
69800+ be disabled by default. As mentioned elsewhere, it is important
69801+ to enable the grsec_lock entry once you have finished modifying
69802+ the sysctl entries.
69803+
69804+endmenu
69805+menu "Logging Options"
69806+depends on GRKERNSEC
69807+
69808+config GRKERNSEC_FLOODTIME
69809+ int "Seconds in between log messages (minimum)"
69810+ default 10
69811+ help
69812+ This option allows you to enforce the number of seconds between
69813+ grsecurity log messages. The default should be suitable for most
69814+ people, however, if you choose to change it, choose a value small enough
69815+ to allow informative logs to be produced, but large enough to
69816+ prevent flooding.
69817+
69818+ Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
69819+ any rate limiting on grsecurity log messages.
69820+
69821+config GRKERNSEC_FLOODBURST
69822+ int "Number of messages in a burst (maximum)"
69823+ default 6
69824+ help
69825+ This option allows you to choose the maximum number of messages allowed
69826+ within the flood time interval you chose in a separate option. The
69827+ default should be suitable for most people, however if you find that
69828+ many of your logs are being interpreted as flooding, you may want to
69829+ raise this value.
69830+
69831+ Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
69832+ any rate limiting on grsecurity log messages.
69833+
69834+endmenu
69835diff --git a/grsecurity/Makefile b/grsecurity/Makefile
69836new file mode 100644
69837index 0000000..30ababb
69838--- /dev/null
69839+++ b/grsecurity/Makefile
69840@@ -0,0 +1,54 @@
69841+# grsecurity – access control and security hardening for Linux
69842+# All code in this directory and various hooks located throughout the Linux kernel are
69843+# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
69844+# http://www.grsecurity.net spender@grsecurity.net
69845+#
69846+# This program is free software; you can redistribute it and/or
69847+# modify it under the terms of the GNU General Public License version 2
69848+# as published by the Free Software Foundation.
69849+#
69850+# This program is distributed in the hope that it will be useful,
69851+# but WITHOUT ANY WARRANTY; without even the implied warranty of
69852+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69853+# GNU General Public License for more details.
69854+#
69855+# You should have received a copy of the GNU General Public License
69856+# along with this program; if not, write to the Free Software
69857+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
69858+
69859+KBUILD_CFLAGS += -Werror
69860+
69861+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
69862+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
69863+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
69864+ grsec_usb.o grsec_ipc.o grsec_proc.o
69865+
69866+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
69867+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
69868+ gracl_learn.o grsec_log.o gracl_policy.o
69869+ifdef CONFIG_COMPAT
69870+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
69871+endif
69872+
69873+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
69874+
69875+ifdef CONFIG_NET
69876+obj-y += grsec_sock.o
69877+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
69878+endif
69879+
69880+ifndef CONFIG_GRKERNSEC
69881+obj-y += grsec_disabled.o
69882+endif
69883+
69884+ifdef CONFIG_GRKERNSEC_HIDESYM
69885+extra-y := grsec_hidesym.o
69886+$(obj)/grsec_hidesym.o:
69887+ @-chmod -f 500 /boot
69888+ @-chmod -f 500 /lib/modules
69889+ @-chmod -f 500 /lib64/modules
69890+ @-chmod -f 500 /lib32/modules
69891+ @-chmod -f 700 .
69892+ @-chmod -f 700 $(objtree)
69893+ @echo ' grsec: protected kernel image paths'
69894+endif
69895diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
69896new file mode 100644
69897index 0000000..6ae3aa0
69898--- /dev/null
69899+++ b/grsecurity/gracl.c
69900@@ -0,0 +1,2703 @@
69901+#include <linux/kernel.h>
69902+#include <linux/module.h>
69903+#include <linux/sched.h>
69904+#include <linux/mm.h>
69905+#include <linux/file.h>
69906+#include <linux/fs.h>
69907+#include <linux/namei.h>
69908+#include <linux/mount.h>
69909+#include <linux/tty.h>
69910+#include <linux/proc_fs.h>
69911+#include <linux/lglock.h>
69912+#include <linux/slab.h>
69913+#include <linux/vmalloc.h>
69914+#include <linux/types.h>
69915+#include <linux/sysctl.h>
69916+#include <linux/netdevice.h>
69917+#include <linux/ptrace.h>
69918+#include <linux/gracl.h>
69919+#include <linux/gralloc.h>
69920+#include <linux/security.h>
69921+#include <linux/grinternal.h>
69922+#include <linux/pid_namespace.h>
69923+#include <linux/stop_machine.h>
69924+#include <linux/fdtable.h>
69925+#include <linux/percpu.h>
69926+#include <linux/lglock.h>
69927+#include <linux/hugetlb.h>
69928+#include <linux/posix-timers.h>
69929+#include <linux/prefetch.h>
69930+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69931+#include <linux/magic.h>
69932+#include <linux/pagemap.h>
69933+#include "../fs/btrfs/async-thread.h"
69934+#include "../fs/btrfs/ctree.h"
69935+#include "../fs/btrfs/btrfs_inode.h"
69936+#endif
69937+#include "../fs/mount.h"
69938+
69939+#include <asm/uaccess.h>
69940+#include <asm/errno.h>
69941+#include <asm/mman.h>
69942+
69943+#define FOR_EACH_ROLE_START(role) \
69944+ role = running_polstate.role_list; \
69945+ while (role) {
69946+
69947+#define FOR_EACH_ROLE_END(role) \
69948+ role = role->prev; \
69949+ }
69950+
69951+extern struct path gr_real_root;
69952+
69953+static struct gr_policy_state running_polstate;
69954+struct gr_policy_state *polstate = &running_polstate;
69955+extern struct gr_alloc_state *current_alloc_state;
69956+
69957+extern char *gr_shared_page[4];
69958+DEFINE_RWLOCK(gr_inode_lock);
69959+
69960+static unsigned int gr_status __read_only = GR_STATUS_INIT;
69961+
69962+#ifdef CONFIG_NET
69963+extern struct vfsmount *sock_mnt;
69964+#endif
69965+
69966+extern struct vfsmount *pipe_mnt;
69967+extern struct vfsmount *shm_mnt;
69968+
69969+#ifdef CONFIG_HUGETLBFS
69970+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
69971+#endif
69972+
69973+extern u16 acl_sp_role_value;
69974+extern struct acl_object_label *fakefs_obj_rw;
69975+extern struct acl_object_label *fakefs_obj_rwx;
69976+
69977+int gr_acl_is_enabled(void)
69978+{
69979+ return (gr_status & GR_READY);
69980+}
69981+
69982+void gr_enable_rbac_system(void)
69983+{
69984+ pax_open_kernel();
69985+ gr_status |= GR_READY;
69986+ pax_close_kernel();
69987+}
69988+
69989+int gr_rbac_disable(void *unused)
69990+{
69991+ pax_open_kernel();
69992+ gr_status &= ~GR_READY;
69993+ pax_close_kernel();
69994+
69995+ return 0;
69996+}
69997+
69998+static inline dev_t __get_dev(const struct dentry *dentry)
69999+{
70000+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
70001+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
70002+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
70003+ else
70004+#endif
70005+ return dentry->d_sb->s_dev;
70006+}
70007+
70008+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
70009+{
70010+ return __get_dev(dentry);
70011+}
70012+
70013+static char gr_task_roletype_to_char(struct task_struct *task)
70014+{
70015+ switch (task->role->roletype &
70016+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
70017+ GR_ROLE_SPECIAL)) {
70018+ case GR_ROLE_DEFAULT:
70019+ return 'D';
70020+ case GR_ROLE_USER:
70021+ return 'U';
70022+ case GR_ROLE_GROUP:
70023+ return 'G';
70024+ case GR_ROLE_SPECIAL:
70025+ return 'S';
70026+ }
70027+
70028+ return 'X';
70029+}
70030+
70031+char gr_roletype_to_char(void)
70032+{
70033+ return gr_task_roletype_to_char(current);
70034+}
70035+
70036+__inline__ int
70037+gr_acl_tpe_check(void)
70038+{
70039+ if (unlikely(!(gr_status & GR_READY)))
70040+ return 0;
70041+ if (current->role->roletype & GR_ROLE_TPE)
70042+ return 1;
70043+ else
70044+ return 0;
70045+}
70046+
70047+int
70048+gr_handle_rawio(const struct inode *inode)
70049+{
70050+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
70051+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
70052+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
70053+ !capable(CAP_SYS_RAWIO))
70054+ return 1;
70055+#endif
70056+ return 0;
70057+}
70058+
70059+int
70060+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
70061+{
70062+ if (likely(lena != lenb))
70063+ return 0;
70064+
70065+ return !memcmp(a, b, lena);
70066+}
70067+
70068+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
70069+{
70070+ *buflen -= namelen;
70071+ if (*buflen < 0)
70072+ return -ENAMETOOLONG;
70073+ *buffer -= namelen;
70074+ memcpy(*buffer, str, namelen);
70075+ return 0;
70076+}
70077+
70078+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
70079+{
70080+ return prepend(buffer, buflen, name->name, name->len);
70081+}
70082+
70083+static int prepend_path(const struct path *path, struct path *root,
70084+ char **buffer, int *buflen)
70085+{
70086+ struct dentry *dentry = path->dentry;
70087+ struct vfsmount *vfsmnt = path->mnt;
70088+ struct mount *mnt = real_mount(vfsmnt);
70089+ bool slash = false;
70090+ int error = 0;
70091+
70092+ while (dentry != root->dentry || vfsmnt != root->mnt) {
70093+ struct dentry * parent;
70094+
70095+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
70096+ /* Global root? */
70097+ if (!mnt_has_parent(mnt)) {
70098+ goto out;
70099+ }
70100+ dentry = mnt->mnt_mountpoint;
70101+ mnt = mnt->mnt_parent;
70102+ vfsmnt = &mnt->mnt;
70103+ continue;
70104+ }
70105+ parent = dentry->d_parent;
70106+ prefetch(parent);
70107+ spin_lock(&dentry->d_lock);
70108+ error = prepend_name(buffer, buflen, &dentry->d_name);
70109+ spin_unlock(&dentry->d_lock);
70110+ if (!error)
70111+ error = prepend(buffer, buflen, "/", 1);
70112+ if (error)
70113+ break;
70114+
70115+ slash = true;
70116+ dentry = parent;
70117+ }
70118+
70119+out:
70120+ if (!error && !slash)
70121+ error = prepend(buffer, buflen, "/", 1);
70122+
70123+ return error;
70124+}
70125+
70126+/* this must be called with mount_lock and rename_lock held */
70127+
70128+static char *__our_d_path(const struct path *path, struct path *root,
70129+ char *buf, int buflen)
70130+{
70131+ char *res = buf + buflen;
70132+ int error;
70133+
70134+ prepend(&res, &buflen, "\0", 1);
70135+ error = prepend_path(path, root, &res, &buflen);
70136+ if (error)
70137+ return ERR_PTR(error);
70138+
70139+ return res;
70140+}
70141+
70142+static char *
70143+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
70144+{
70145+ char *retval;
70146+
70147+ retval = __our_d_path(path, root, buf, buflen);
70148+ if (unlikely(IS_ERR(retval)))
70149+ retval = strcpy(buf, "<path too long>");
70150+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
70151+ retval[1] = '\0';
70152+
70153+ return retval;
70154+}
70155+
70156+static char *
70157+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
70158+ char *buf, int buflen)
70159+{
70160+ struct path path;
70161+ char *res;
70162+
70163+ path.dentry = (struct dentry *)dentry;
70164+ path.mnt = (struct vfsmount *)vfsmnt;
70165+
70166+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
70167+ by the RBAC system */
70168+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
70169+
70170+ return res;
70171+}
70172+
70173+static char *
70174+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
70175+ char *buf, int buflen)
70176+{
70177+ char *res;
70178+ struct path path;
70179+ struct path root;
70180+ struct task_struct *reaper = init_pid_ns.child_reaper;
70181+
70182+ path.dentry = (struct dentry *)dentry;
70183+ path.mnt = (struct vfsmount *)vfsmnt;
70184+
70185+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
70186+ get_fs_root(reaper->fs, &root);
70187+
70188+ read_seqlock_excl(&mount_lock);
70189+ write_seqlock(&rename_lock);
70190+ res = gen_full_path(&path, &root, buf, buflen);
70191+ write_sequnlock(&rename_lock);
70192+ read_sequnlock_excl(&mount_lock);
70193+
70194+ path_put(&root);
70195+ return res;
70196+}
70197+
70198+char *
70199+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
70200+{
70201+ char *ret;
70202+ read_seqlock_excl(&mount_lock);
70203+ write_seqlock(&rename_lock);
70204+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
70205+ PAGE_SIZE);
70206+ write_sequnlock(&rename_lock);
70207+ read_sequnlock_excl(&mount_lock);
70208+ return ret;
70209+}
70210+
70211+static char *
70212+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
70213+{
70214+ char *ret;
70215+ char *buf;
70216+ int buflen;
70217+
70218+ read_seqlock_excl(&mount_lock);
70219+ write_seqlock(&rename_lock);
70220+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
70221+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
70222+ buflen = (int)(ret - buf);
70223+ if (buflen >= 5)
70224+ prepend(&ret, &buflen, "/proc", 5);
70225+ else
70226+ ret = strcpy(buf, "<path too long>");
70227+ write_sequnlock(&rename_lock);
70228+ read_sequnlock_excl(&mount_lock);
70229+ return ret;
70230+}
70231+
70232+char *
70233+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
70234+{
70235+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
70236+ PAGE_SIZE);
70237+}
70238+
70239+char *
70240+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
70241+{
70242+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
70243+ PAGE_SIZE);
70244+}
70245+
70246+char *
70247+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
70248+{
70249+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
70250+ PAGE_SIZE);
70251+}
70252+
70253+char *
70254+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
70255+{
70256+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
70257+ PAGE_SIZE);
70258+}
70259+
70260+char *
70261+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
70262+{
70263+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
70264+ PAGE_SIZE);
70265+}
70266+
70267+__inline__ __u32
70268+to_gr_audit(const __u32 reqmode)
70269+{
70270+ /* masks off auditable permission flags, then shifts them to create
70271+ auditing flags, and adds the special case of append auditing if
70272+ we're requesting write */
70273+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
70274+}
70275+
70276+struct acl_role_label *
70277+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
70278+ const gid_t gid)
70279+{
70280+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
70281+ struct acl_role_label *match;
70282+ struct role_allowed_ip *ipp;
70283+ unsigned int x;
70284+ u32 curr_ip = task->signal->saved_ip;
70285+
70286+ match = state->acl_role_set.r_hash[index];
70287+
70288+ while (match) {
70289+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
70290+ for (x = 0; x < match->domain_child_num; x++) {
70291+ if (match->domain_children[x] == uid)
70292+ goto found;
70293+ }
70294+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
70295+ break;
70296+ match = match->next;
70297+ }
70298+found:
70299+ if (match == NULL) {
70300+ try_group:
70301+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
70302+ match = state->acl_role_set.r_hash[index];
70303+
70304+ while (match) {
70305+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
70306+ for (x = 0; x < match->domain_child_num; x++) {
70307+ if (match->domain_children[x] == gid)
70308+ goto found2;
70309+ }
70310+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
70311+ break;
70312+ match = match->next;
70313+ }
70314+found2:
70315+ if (match == NULL)
70316+ match = state->default_role;
70317+ if (match->allowed_ips == NULL)
70318+ return match;
70319+ else {
70320+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
70321+ if (likely
70322+ ((ntohl(curr_ip) & ipp->netmask) ==
70323+ (ntohl(ipp->addr) & ipp->netmask)))
70324+ return match;
70325+ }
70326+ match = state->default_role;
70327+ }
70328+ } else if (match->allowed_ips == NULL) {
70329+ return match;
70330+ } else {
70331+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
70332+ if (likely
70333+ ((ntohl(curr_ip) & ipp->netmask) ==
70334+ (ntohl(ipp->addr) & ipp->netmask)))
70335+ return match;
70336+ }
70337+ goto try_group;
70338+ }
70339+
70340+ return match;
70341+}
70342+
70343+static struct acl_role_label *
70344+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
70345+ const gid_t gid)
70346+{
70347+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
70348+}
70349+
70350+struct acl_subject_label *
70351+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
70352+ const struct acl_role_label *role)
70353+{
70354+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
70355+ struct acl_subject_label *match;
70356+
70357+ match = role->subj_hash[index];
70358+
70359+ while (match && (match->inode != ino || match->device != dev ||
70360+ (match->mode & GR_DELETED))) {
70361+ match = match->next;
70362+ }
70363+
70364+ if (match && !(match->mode & GR_DELETED))
70365+ return match;
70366+ else
70367+ return NULL;
70368+}
70369+
70370+struct acl_subject_label *
70371+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
70372+ const struct acl_role_label *role)
70373+{
70374+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
70375+ struct acl_subject_label *match;
70376+
70377+ match = role->subj_hash[index];
70378+
70379+ while (match && (match->inode != ino || match->device != dev ||
70380+ !(match->mode & GR_DELETED))) {
70381+ match = match->next;
70382+ }
70383+
70384+ if (match && (match->mode & GR_DELETED))
70385+ return match;
70386+ else
70387+ return NULL;
70388+}
70389+
70390+static struct acl_object_label *
70391+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
70392+ const struct acl_subject_label *subj)
70393+{
70394+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70395+ struct acl_object_label *match;
70396+
70397+ match = subj->obj_hash[index];
70398+
70399+ while (match && (match->inode != ino || match->device != dev ||
70400+ (match->mode & GR_DELETED))) {
70401+ match = match->next;
70402+ }
70403+
70404+ if (match && !(match->mode & GR_DELETED))
70405+ return match;
70406+ else
70407+ return NULL;
70408+}
70409+
70410+static struct acl_object_label *
70411+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
70412+ const struct acl_subject_label *subj)
70413+{
70414+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70415+ struct acl_object_label *match;
70416+
70417+ match = subj->obj_hash[index];
70418+
70419+ while (match && (match->inode != ino || match->device != dev ||
70420+ !(match->mode & GR_DELETED))) {
70421+ match = match->next;
70422+ }
70423+
70424+ if (match && (match->mode & GR_DELETED))
70425+ return match;
70426+
70427+ match = subj->obj_hash[index];
70428+
70429+ while (match && (match->inode != ino || match->device != dev ||
70430+ (match->mode & GR_DELETED))) {
70431+ match = match->next;
70432+ }
70433+
70434+ if (match && !(match->mode & GR_DELETED))
70435+ return match;
70436+ else
70437+ return NULL;
70438+}
70439+
70440+struct name_entry *
70441+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
70442+{
70443+ unsigned int len = strlen(name);
70444+ unsigned int key = full_name_hash(name, len);
70445+ unsigned int index = key % state->name_set.n_size;
70446+ struct name_entry *match;
70447+
70448+ match = state->name_set.n_hash[index];
70449+
70450+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
70451+ match = match->next;
70452+
70453+ return match;
70454+}
70455+
70456+static struct name_entry *
70457+lookup_name_entry(const char *name)
70458+{
70459+ return __lookup_name_entry(&running_polstate, name);
70460+}
70461+
70462+static struct name_entry *
70463+lookup_name_entry_create(const char *name)
70464+{
70465+ unsigned int len = strlen(name);
70466+ unsigned int key = full_name_hash(name, len);
70467+ unsigned int index = key % running_polstate.name_set.n_size;
70468+ struct name_entry *match;
70469+
70470+ match = running_polstate.name_set.n_hash[index];
70471+
70472+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70473+ !match->deleted))
70474+ match = match->next;
70475+
70476+ if (match && match->deleted)
70477+ return match;
70478+
70479+ match = running_polstate.name_set.n_hash[index];
70480+
70481+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70482+ match->deleted))
70483+ match = match->next;
70484+
70485+ if (match && !match->deleted)
70486+ return match;
70487+ else
70488+ return NULL;
70489+}
70490+
70491+static struct inodev_entry *
70492+lookup_inodev_entry(const ino_t ino, const dev_t dev)
70493+{
70494+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
70495+ struct inodev_entry *match;
70496+
70497+ match = running_polstate.inodev_set.i_hash[index];
70498+
70499+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
70500+ match = match->next;
70501+
70502+ return match;
70503+}
70504+
70505+void
70506+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
70507+{
70508+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
70509+ state->inodev_set.i_size);
70510+ struct inodev_entry **curr;
70511+
70512+ entry->prev = NULL;
70513+
70514+ curr = &state->inodev_set.i_hash[index];
70515+ if (*curr != NULL)
70516+ (*curr)->prev = entry;
70517+
70518+ entry->next = *curr;
70519+ *curr = entry;
70520+
70521+ return;
70522+}
70523+
70524+static void
70525+insert_inodev_entry(struct inodev_entry *entry)
70526+{
70527+ __insert_inodev_entry(&running_polstate, entry);
70528+}
70529+
70530+void
70531+insert_acl_obj_label(struct acl_object_label *obj,
70532+ struct acl_subject_label *subj)
70533+{
70534+ unsigned int index =
70535+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
70536+ struct acl_object_label **curr;
70537+
70538+ obj->prev = NULL;
70539+
70540+ curr = &subj->obj_hash[index];
70541+ if (*curr != NULL)
70542+ (*curr)->prev = obj;
70543+
70544+ obj->next = *curr;
70545+ *curr = obj;
70546+
70547+ return;
70548+}
70549+
70550+void
70551+insert_acl_subj_label(struct acl_subject_label *obj,
70552+ struct acl_role_label *role)
70553+{
70554+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
70555+ struct acl_subject_label **curr;
70556+
70557+ obj->prev = NULL;
70558+
70559+ curr = &role->subj_hash[index];
70560+ if (*curr != NULL)
70561+ (*curr)->prev = obj;
70562+
70563+ obj->next = *curr;
70564+ *curr = obj;
70565+
70566+ return;
70567+}
70568+
70569+/* derived from glibc fnmatch() 0: match, 1: no match*/
70570+
70571+static int
70572+glob_match(const char *p, const char *n)
70573+{
70574+ char c;
70575+
70576+ while ((c = *p++) != '\0') {
70577+ switch (c) {
70578+ case '?':
70579+ if (*n == '\0')
70580+ return 1;
70581+ else if (*n == '/')
70582+ return 1;
70583+ break;
70584+ case '\\':
70585+ if (*n != c)
70586+ return 1;
70587+ break;
70588+ case '*':
70589+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
70590+ if (*n == '/')
70591+ return 1;
70592+ else if (c == '?') {
70593+ if (*n == '\0')
70594+ return 1;
70595+ else
70596+ ++n;
70597+ }
70598+ }
70599+ if (c == '\0') {
70600+ return 0;
70601+ } else {
70602+ const char *endp;
70603+
70604+ if ((endp = strchr(n, '/')) == NULL)
70605+ endp = n + strlen(n);
70606+
70607+ if (c == '[') {
70608+ for (--p; n < endp; ++n)
70609+ if (!glob_match(p, n))
70610+ return 0;
70611+ } else if (c == '/') {
70612+ while (*n != '\0' && *n != '/')
70613+ ++n;
70614+ if (*n == '/' && !glob_match(p, n + 1))
70615+ return 0;
70616+ } else {
70617+ for (--p; n < endp; ++n)
70618+ if (*n == c && !glob_match(p, n))
70619+ return 0;
70620+ }
70621+
70622+ return 1;
70623+ }
70624+ case '[':
70625+ {
70626+ int not;
70627+ char cold;
70628+
70629+ if (*n == '\0' || *n == '/')
70630+ return 1;
70631+
70632+ not = (*p == '!' || *p == '^');
70633+ if (not)
70634+ ++p;
70635+
70636+ c = *p++;
70637+ for (;;) {
70638+ unsigned char fn = (unsigned char)*n;
70639+
70640+ if (c == '\0')
70641+ return 1;
70642+ else {
70643+ if (c == fn)
70644+ goto matched;
70645+ cold = c;
70646+ c = *p++;
70647+
70648+ if (c == '-' && *p != ']') {
70649+ unsigned char cend = *p++;
70650+
70651+ if (cend == '\0')
70652+ return 1;
70653+
70654+ if (cold <= fn && fn <= cend)
70655+ goto matched;
70656+
70657+ c = *p++;
70658+ }
70659+ }
70660+
70661+ if (c == ']')
70662+ break;
70663+ }
70664+ if (!not)
70665+ return 1;
70666+ break;
70667+ matched:
70668+ while (c != ']') {
70669+ if (c == '\0')
70670+ return 1;
70671+
70672+ c = *p++;
70673+ }
70674+ if (not)
70675+ return 1;
70676+ }
70677+ break;
70678+ default:
70679+ if (c != *n)
70680+ return 1;
70681+ }
70682+
70683+ ++n;
70684+ }
70685+
70686+ if (*n == '\0')
70687+ return 0;
70688+
70689+ if (*n == '/')
70690+ return 0;
70691+
70692+ return 1;
70693+}
70694+
70695+static struct acl_object_label *
70696+chk_glob_label(struct acl_object_label *globbed,
70697+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
70698+{
70699+ struct acl_object_label *tmp;
70700+
70701+ if (*path == NULL)
70702+ *path = gr_to_filename_nolock(dentry, mnt);
70703+
70704+ tmp = globbed;
70705+
70706+ while (tmp) {
70707+ if (!glob_match(tmp->filename, *path))
70708+ return tmp;
70709+ tmp = tmp->next;
70710+ }
70711+
70712+ return NULL;
70713+}
70714+
70715+static struct acl_object_label *
70716+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70717+ const ino_t curr_ino, const dev_t curr_dev,
70718+ const struct acl_subject_label *subj, char **path, const int checkglob)
70719+{
70720+ struct acl_subject_label *tmpsubj;
70721+ struct acl_object_label *retval;
70722+ struct acl_object_label *retval2;
70723+
70724+ tmpsubj = (struct acl_subject_label *) subj;
70725+ read_lock(&gr_inode_lock);
70726+ do {
70727+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
70728+ if (retval) {
70729+ if (checkglob && retval->globbed) {
70730+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
70731+ if (retval2)
70732+ retval = retval2;
70733+ }
70734+ break;
70735+ }
70736+ } while ((tmpsubj = tmpsubj->parent_subject));
70737+ read_unlock(&gr_inode_lock);
70738+
70739+ return retval;
70740+}
70741+
70742+static __inline__ struct acl_object_label *
70743+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70744+ struct dentry *curr_dentry,
70745+ const struct acl_subject_label *subj, char **path, const int checkglob)
70746+{
70747+ int newglob = checkglob;
70748+ ino_t inode;
70749+ dev_t device;
70750+
70751+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
70752+ as we don't want a / * rule to match instead of the / object
70753+ don't do this for create lookups that call this function though, since they're looking up
70754+ on the parent and thus need globbing checks on all paths
70755+ */
70756+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
70757+ newglob = GR_NO_GLOB;
70758+
70759+ spin_lock(&curr_dentry->d_lock);
70760+ inode = curr_dentry->d_inode->i_ino;
70761+ device = __get_dev(curr_dentry);
70762+ spin_unlock(&curr_dentry->d_lock);
70763+
70764+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
70765+}
70766+
70767+#ifdef CONFIG_HUGETLBFS
70768+static inline bool
70769+is_hugetlbfs_mnt(const struct vfsmount *mnt)
70770+{
70771+ int i;
70772+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
70773+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
70774+ return true;
70775+ }
70776+
70777+ return false;
70778+}
70779+#endif
70780+
70781+static struct acl_object_label *
70782+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70783+ const struct acl_subject_label *subj, char *path, const int checkglob)
70784+{
70785+ struct dentry *dentry = (struct dentry *) l_dentry;
70786+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70787+ struct mount *real_mnt = real_mount(mnt);
70788+ struct acl_object_label *retval;
70789+ struct dentry *parent;
70790+
70791+ read_seqlock_excl(&mount_lock);
70792+ write_seqlock(&rename_lock);
70793+
70794+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
70795+#ifdef CONFIG_NET
70796+ mnt == sock_mnt ||
70797+#endif
70798+#ifdef CONFIG_HUGETLBFS
70799+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
70800+#endif
70801+ /* ignore Eric Biederman */
70802+ IS_PRIVATE(l_dentry->d_inode))) {
70803+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
70804+ goto out;
70805+ }
70806+
70807+ for (;;) {
70808+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70809+ break;
70810+
70811+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70812+ if (!mnt_has_parent(real_mnt))
70813+ break;
70814+
70815+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70816+ if (retval != NULL)
70817+ goto out;
70818+
70819+ dentry = real_mnt->mnt_mountpoint;
70820+ real_mnt = real_mnt->mnt_parent;
70821+ mnt = &real_mnt->mnt;
70822+ continue;
70823+ }
70824+
70825+ parent = dentry->d_parent;
70826+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70827+ if (retval != NULL)
70828+ goto out;
70829+
70830+ dentry = parent;
70831+ }
70832+
70833+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70834+
70835+ /* gr_real_root is pinned so we don't have to hold a reference */
70836+ if (retval == NULL)
70837+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
70838+out:
70839+ write_sequnlock(&rename_lock);
70840+ read_sequnlock_excl(&mount_lock);
70841+
70842+ BUG_ON(retval == NULL);
70843+
70844+ return retval;
70845+}
70846+
70847+static __inline__ struct acl_object_label *
70848+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70849+ const struct acl_subject_label *subj)
70850+{
70851+ char *path = NULL;
70852+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
70853+}
70854+
70855+static __inline__ struct acl_object_label *
70856+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70857+ const struct acl_subject_label *subj)
70858+{
70859+ char *path = NULL;
70860+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
70861+}
70862+
70863+static __inline__ struct acl_object_label *
70864+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70865+ const struct acl_subject_label *subj, char *path)
70866+{
70867+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
70868+}
70869+
70870+struct acl_subject_label *
70871+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70872+ const struct acl_role_label *role)
70873+{
70874+ struct dentry *dentry = (struct dentry *) l_dentry;
70875+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70876+ struct mount *real_mnt = real_mount(mnt);
70877+ struct acl_subject_label *retval;
70878+ struct dentry *parent;
70879+
70880+ read_seqlock_excl(&mount_lock);
70881+ write_seqlock(&rename_lock);
70882+
70883+ for (;;) {
70884+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70885+ break;
70886+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70887+ if (!mnt_has_parent(real_mnt))
70888+ break;
70889+
70890+ spin_lock(&dentry->d_lock);
70891+ read_lock(&gr_inode_lock);
70892+ retval =
70893+ lookup_acl_subj_label(dentry->d_inode->i_ino,
70894+ __get_dev(dentry), role);
70895+ read_unlock(&gr_inode_lock);
70896+ spin_unlock(&dentry->d_lock);
70897+ if (retval != NULL)
70898+ goto out;
70899+
70900+ dentry = real_mnt->mnt_mountpoint;
70901+ real_mnt = real_mnt->mnt_parent;
70902+ mnt = &real_mnt->mnt;
70903+ continue;
70904+ }
70905+
70906+ spin_lock(&dentry->d_lock);
70907+ read_lock(&gr_inode_lock);
70908+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70909+ __get_dev(dentry), role);
70910+ read_unlock(&gr_inode_lock);
70911+ parent = dentry->d_parent;
70912+ spin_unlock(&dentry->d_lock);
70913+
70914+ if (retval != NULL)
70915+ goto out;
70916+
70917+ dentry = parent;
70918+ }
70919+
70920+ spin_lock(&dentry->d_lock);
70921+ read_lock(&gr_inode_lock);
70922+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70923+ __get_dev(dentry), role);
70924+ read_unlock(&gr_inode_lock);
70925+ spin_unlock(&dentry->d_lock);
70926+
70927+ if (unlikely(retval == NULL)) {
70928+ /* gr_real_root is pinned, we don't need to hold a reference */
70929+ read_lock(&gr_inode_lock);
70930+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
70931+ __get_dev(gr_real_root.dentry), role);
70932+ read_unlock(&gr_inode_lock);
70933+ }
70934+out:
70935+ write_sequnlock(&rename_lock);
70936+ read_sequnlock_excl(&mount_lock);
70937+
70938+ BUG_ON(retval == NULL);
70939+
70940+ return retval;
70941+}
70942+
70943+void
70944+assign_special_role(const char *rolename)
70945+{
70946+ struct acl_object_label *obj;
70947+ struct acl_role_label *r;
70948+ struct acl_role_label *assigned = NULL;
70949+ struct task_struct *tsk;
70950+ struct file *filp;
70951+
70952+ FOR_EACH_ROLE_START(r)
70953+ if (!strcmp(rolename, r->rolename) &&
70954+ (r->roletype & GR_ROLE_SPECIAL)) {
70955+ assigned = r;
70956+ break;
70957+ }
70958+ FOR_EACH_ROLE_END(r)
70959+
70960+ if (!assigned)
70961+ return;
70962+
70963+ read_lock(&tasklist_lock);
70964+ read_lock(&grsec_exec_file_lock);
70965+
70966+ tsk = current->real_parent;
70967+ if (tsk == NULL)
70968+ goto out_unlock;
70969+
70970+ filp = tsk->exec_file;
70971+ if (filp == NULL)
70972+ goto out_unlock;
70973+
70974+ tsk->is_writable = 0;
70975+ tsk->inherited = 0;
70976+
70977+ tsk->acl_sp_role = 1;
70978+ tsk->acl_role_id = ++acl_sp_role_value;
70979+ tsk->role = assigned;
70980+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
70981+
70982+ /* ignore additional mmap checks for processes that are writable
70983+ by the default ACL */
70984+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
70985+ if (unlikely(obj->mode & GR_WRITE))
70986+ tsk->is_writable = 1;
70987+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
70988+ if (unlikely(obj->mode & GR_WRITE))
70989+ tsk->is_writable = 1;
70990+
70991+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70992+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
70993+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
70994+#endif
70995+
70996+out_unlock:
70997+ read_unlock(&grsec_exec_file_lock);
70998+ read_unlock(&tasklist_lock);
70999+ return;
71000+}
71001+
71002+
71003+static void
71004+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
71005+{
71006+ struct task_struct *task = current;
71007+ const struct cred *cred = current_cred();
71008+
71009+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
71010+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
71011+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
71012+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
71013+
71014+ return;
71015+}
71016+
71017+static void
71018+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
71019+{
71020+ struct task_struct *task = current;
71021+ const struct cred *cred = current_cred();
71022+
71023+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
71024+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
71025+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
71026+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
71027+
71028+ return;
71029+}
71030+
71031+static void
71032+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
71033+{
71034+ struct task_struct *task = current;
71035+ const struct cred *cred = current_cred();
71036+
71037+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
71038+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
71039+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
71040+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
71041+
71042+ return;
71043+}
71044+
71045+static void
71046+gr_set_proc_res(struct task_struct *task)
71047+{
71048+ struct acl_subject_label *proc;
71049+ unsigned short i;
71050+
71051+ proc = task->acl;
71052+
71053+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
71054+ return;
71055+
71056+ for (i = 0; i < RLIM_NLIMITS; i++) {
71057+ if (!(proc->resmask & (1U << i)))
71058+ continue;
71059+
71060+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
71061+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
71062+
71063+ if (i == RLIMIT_CPU)
71064+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
71065+ }
71066+
71067+ return;
71068+}
71069+
71070+/* both of the below must be called with
71071+ rcu_read_lock();
71072+ read_lock(&tasklist_lock);
71073+ read_lock(&grsec_exec_file_lock);
71074+*/
71075+
71076+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
71077+{
71078+ char *tmpname;
71079+ struct acl_subject_label *tmpsubj;
71080+ struct file *filp;
71081+ struct name_entry *nmatch;
71082+
71083+ filp = task->exec_file;
71084+ if (filp == NULL)
71085+ return NULL;
71086+
71087+ /* the following is to apply the correct subject
71088+ on binaries running when the RBAC system
71089+ is enabled, when the binaries have been
71090+ replaced or deleted since their execution
71091+ -----
71092+ when the RBAC system starts, the inode/dev
71093+ from exec_file will be one the RBAC system
71094+ is unaware of. It only knows the inode/dev
71095+ of the present file on disk, or the absence
71096+ of it.
71097+ */
71098+
71099+ if (filename)
71100+ nmatch = __lookup_name_entry(state, filename);
71101+ else {
71102+ preempt_disable();
71103+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
71104+
71105+ nmatch = __lookup_name_entry(state, tmpname);
71106+ preempt_enable();
71107+ }
71108+ tmpsubj = NULL;
71109+ if (nmatch) {
71110+ if (nmatch->deleted)
71111+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
71112+ else
71113+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
71114+ }
71115+ /* this also works for the reload case -- if we don't match a potentially inherited subject
71116+ then we fall back to a normal lookup based on the binary's ino/dev
71117+ */
71118+ if (tmpsubj == NULL)
71119+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
71120+
71121+ return tmpsubj;
71122+}
71123+
71124+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
71125+{
71126+ return __gr_get_subject_for_task(&running_polstate, task, filename);
71127+}
71128+
71129+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
71130+{
71131+ struct acl_object_label *obj;
71132+ struct file *filp;
71133+
71134+ filp = task->exec_file;
71135+
71136+ task->acl = subj;
71137+ task->is_writable = 0;
71138+ /* ignore additional mmap checks for processes that are writable
71139+ by the default ACL */
71140+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
71141+ if (unlikely(obj->mode & GR_WRITE))
71142+ task->is_writable = 1;
71143+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
71144+ if (unlikely(obj->mode & GR_WRITE))
71145+ task->is_writable = 1;
71146+
71147+ gr_set_proc_res(task);
71148+
71149+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71150+ 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);
71151+#endif
71152+}
71153+
71154+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
71155+{
71156+ __gr_apply_subject_to_task(&running_polstate, task, subj);
71157+}
71158+
71159+__u32
71160+gr_search_file(const struct dentry * dentry, const __u32 mode,
71161+ const struct vfsmount * mnt)
71162+{
71163+ __u32 retval = mode;
71164+ struct acl_subject_label *curracl;
71165+ struct acl_object_label *currobj;
71166+
71167+ if (unlikely(!(gr_status & GR_READY)))
71168+ return (mode & ~GR_AUDITS);
71169+
71170+ curracl = current->acl;
71171+
71172+ currobj = chk_obj_label(dentry, mnt, curracl);
71173+ retval = currobj->mode & mode;
71174+
71175+ /* if we're opening a specified transfer file for writing
71176+ (e.g. /dev/initctl), then transfer our role to init
71177+ */
71178+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
71179+ current->role->roletype & GR_ROLE_PERSIST)) {
71180+ struct task_struct *task = init_pid_ns.child_reaper;
71181+
71182+ if (task->role != current->role) {
71183+ struct acl_subject_label *subj;
71184+
71185+ task->acl_sp_role = 0;
71186+ task->acl_role_id = current->acl_role_id;
71187+ task->role = current->role;
71188+ rcu_read_lock();
71189+ read_lock(&grsec_exec_file_lock);
71190+ subj = gr_get_subject_for_task(task, NULL);
71191+ gr_apply_subject_to_task(task, subj);
71192+ read_unlock(&grsec_exec_file_lock);
71193+ rcu_read_unlock();
71194+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
71195+ }
71196+ }
71197+
71198+ if (unlikely
71199+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
71200+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
71201+ __u32 new_mode = mode;
71202+
71203+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
71204+
71205+ retval = new_mode;
71206+
71207+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
71208+ new_mode |= GR_INHERIT;
71209+
71210+ if (!(mode & GR_NOLEARN))
71211+ gr_log_learn(dentry, mnt, new_mode);
71212+ }
71213+
71214+ return retval;
71215+}
71216+
71217+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
71218+ const struct dentry *parent,
71219+ const struct vfsmount *mnt)
71220+{
71221+ struct name_entry *match;
71222+ struct acl_object_label *matchpo;
71223+ struct acl_subject_label *curracl;
71224+ char *path;
71225+
71226+ if (unlikely(!(gr_status & GR_READY)))
71227+ return NULL;
71228+
71229+ preempt_disable();
71230+ path = gr_to_filename_rbac(new_dentry, mnt);
71231+ match = lookup_name_entry_create(path);
71232+
71233+ curracl = current->acl;
71234+
71235+ if (match) {
71236+ read_lock(&gr_inode_lock);
71237+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
71238+ read_unlock(&gr_inode_lock);
71239+
71240+ if (matchpo) {
71241+ preempt_enable();
71242+ return matchpo;
71243+ }
71244+ }
71245+
71246+ // lookup parent
71247+
71248+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
71249+
71250+ preempt_enable();
71251+ return matchpo;
71252+}
71253+
71254+__u32
71255+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
71256+ const struct vfsmount * mnt, const __u32 mode)
71257+{
71258+ struct acl_object_label *matchpo;
71259+ __u32 retval;
71260+
71261+ if (unlikely(!(gr_status & GR_READY)))
71262+ return (mode & ~GR_AUDITS);
71263+
71264+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
71265+
71266+ retval = matchpo->mode & mode;
71267+
71268+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
71269+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
71270+ __u32 new_mode = mode;
71271+
71272+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
71273+
71274+ gr_log_learn(new_dentry, mnt, new_mode);
71275+ return new_mode;
71276+ }
71277+
71278+ return retval;
71279+}
71280+
71281+__u32
71282+gr_check_link(const struct dentry * new_dentry,
71283+ const struct dentry * parent_dentry,
71284+ const struct vfsmount * parent_mnt,
71285+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
71286+{
71287+ struct acl_object_label *obj;
71288+ __u32 oldmode, newmode;
71289+ __u32 needmode;
71290+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
71291+ GR_DELETE | GR_INHERIT;
71292+
71293+ if (unlikely(!(gr_status & GR_READY)))
71294+ return (GR_CREATE | GR_LINK);
71295+
71296+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
71297+ oldmode = obj->mode;
71298+
71299+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
71300+ newmode = obj->mode;
71301+
71302+ needmode = newmode & checkmodes;
71303+
71304+ // old name for hardlink must have at least the permissions of the new name
71305+ if ((oldmode & needmode) != needmode)
71306+ goto bad;
71307+
71308+ // if old name had restrictions/auditing, make sure the new name does as well
71309+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
71310+
71311+ // don't allow hardlinking of suid/sgid/fcapped files without permission
71312+ if (is_privileged_binary(old_dentry))
71313+ needmode |= GR_SETID;
71314+
71315+ if ((newmode & needmode) != needmode)
71316+ goto bad;
71317+
71318+ // enforce minimum permissions
71319+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
71320+ return newmode;
71321+bad:
71322+ needmode = oldmode;
71323+ if (is_privileged_binary(old_dentry))
71324+ needmode |= GR_SETID;
71325+
71326+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
71327+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
71328+ return (GR_CREATE | GR_LINK);
71329+ } else if (newmode & GR_SUPPRESS)
71330+ return GR_SUPPRESS;
71331+ else
71332+ return 0;
71333+}
71334+
71335+int
71336+gr_check_hidden_task(const struct task_struct *task)
71337+{
71338+ if (unlikely(!(gr_status & GR_READY)))
71339+ return 0;
71340+
71341+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
71342+ return 1;
71343+
71344+ return 0;
71345+}
71346+
71347+int
71348+gr_check_protected_task(const struct task_struct *task)
71349+{
71350+ if (unlikely(!(gr_status & GR_READY) || !task))
71351+ return 0;
71352+
71353+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
71354+ task->acl != current->acl)
71355+ return 1;
71356+
71357+ return 0;
71358+}
71359+
71360+int
71361+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
71362+{
71363+ struct task_struct *p;
71364+ int ret = 0;
71365+
71366+ if (unlikely(!(gr_status & GR_READY) || !pid))
71367+ return ret;
71368+
71369+ read_lock(&tasklist_lock);
71370+ do_each_pid_task(pid, type, p) {
71371+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
71372+ p->acl != current->acl) {
71373+ ret = 1;
71374+ goto out;
71375+ }
71376+ } while_each_pid_task(pid, type, p);
71377+out:
71378+ read_unlock(&tasklist_lock);
71379+
71380+ return ret;
71381+}
71382+
71383+void
71384+gr_copy_label(struct task_struct *tsk)
71385+{
71386+ struct task_struct *p = current;
71387+
71388+ tsk->inherited = p->inherited;
71389+ tsk->acl_sp_role = 0;
71390+ tsk->acl_role_id = p->acl_role_id;
71391+ tsk->acl = p->acl;
71392+ tsk->role = p->role;
71393+ tsk->signal->used_accept = 0;
71394+ tsk->signal->curr_ip = p->signal->curr_ip;
71395+ tsk->signal->saved_ip = p->signal->saved_ip;
71396+ if (p->exec_file)
71397+ get_file(p->exec_file);
71398+ tsk->exec_file = p->exec_file;
71399+ tsk->is_writable = p->is_writable;
71400+ if (unlikely(p->signal->used_accept)) {
71401+ p->signal->curr_ip = 0;
71402+ p->signal->saved_ip = 0;
71403+ }
71404+
71405+ return;
71406+}
71407+
71408+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
71409+
71410+int
71411+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
71412+{
71413+ unsigned int i;
71414+ __u16 num;
71415+ uid_t *uidlist;
71416+ uid_t curuid;
71417+ int realok = 0;
71418+ int effectiveok = 0;
71419+ int fsok = 0;
71420+ uid_t globalreal, globaleffective, globalfs;
71421+
71422+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
71423+ struct user_struct *user;
71424+
71425+ if (!uid_valid(real))
71426+ goto skipit;
71427+
71428+ /* find user based on global namespace */
71429+
71430+ globalreal = GR_GLOBAL_UID(real);
71431+
71432+ user = find_user(make_kuid(&init_user_ns, globalreal));
71433+ if (user == NULL)
71434+ goto skipit;
71435+
71436+ if (gr_process_kernel_setuid_ban(user)) {
71437+ /* for find_user */
71438+ free_uid(user);
71439+ return 1;
71440+ }
71441+
71442+ /* for find_user */
71443+ free_uid(user);
71444+
71445+skipit:
71446+#endif
71447+
71448+ if (unlikely(!(gr_status & GR_READY)))
71449+ return 0;
71450+
71451+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71452+ gr_log_learn_uid_change(real, effective, fs);
71453+
71454+ num = current->acl->user_trans_num;
71455+ uidlist = current->acl->user_transitions;
71456+
71457+ if (uidlist == NULL)
71458+ return 0;
71459+
71460+ if (!uid_valid(real)) {
71461+ realok = 1;
71462+ globalreal = (uid_t)-1;
71463+ } else {
71464+ globalreal = GR_GLOBAL_UID(real);
71465+ }
71466+ if (!uid_valid(effective)) {
71467+ effectiveok = 1;
71468+ globaleffective = (uid_t)-1;
71469+ } else {
71470+ globaleffective = GR_GLOBAL_UID(effective);
71471+ }
71472+ if (!uid_valid(fs)) {
71473+ fsok = 1;
71474+ globalfs = (uid_t)-1;
71475+ } else {
71476+ globalfs = GR_GLOBAL_UID(fs);
71477+ }
71478+
71479+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
71480+ for (i = 0; i < num; i++) {
71481+ curuid = uidlist[i];
71482+ if (globalreal == curuid)
71483+ realok = 1;
71484+ if (globaleffective == curuid)
71485+ effectiveok = 1;
71486+ if (globalfs == curuid)
71487+ fsok = 1;
71488+ }
71489+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
71490+ for (i = 0; i < num; i++) {
71491+ curuid = uidlist[i];
71492+ if (globalreal == curuid)
71493+ break;
71494+ if (globaleffective == curuid)
71495+ break;
71496+ if (globalfs == curuid)
71497+ break;
71498+ }
71499+ /* not in deny list */
71500+ if (i == num) {
71501+ realok = 1;
71502+ effectiveok = 1;
71503+ fsok = 1;
71504+ }
71505+ }
71506+
71507+ if (realok && effectiveok && fsok)
71508+ return 0;
71509+ else {
71510+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71511+ return 1;
71512+ }
71513+}
71514+
71515+int
71516+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
71517+{
71518+ unsigned int i;
71519+ __u16 num;
71520+ gid_t *gidlist;
71521+ gid_t curgid;
71522+ int realok = 0;
71523+ int effectiveok = 0;
71524+ int fsok = 0;
71525+ gid_t globalreal, globaleffective, globalfs;
71526+
71527+ if (unlikely(!(gr_status & GR_READY)))
71528+ return 0;
71529+
71530+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71531+ gr_log_learn_gid_change(real, effective, fs);
71532+
71533+ num = current->acl->group_trans_num;
71534+ gidlist = current->acl->group_transitions;
71535+
71536+ if (gidlist == NULL)
71537+ return 0;
71538+
71539+ if (!gid_valid(real)) {
71540+ realok = 1;
71541+ globalreal = (gid_t)-1;
71542+ } else {
71543+ globalreal = GR_GLOBAL_GID(real);
71544+ }
71545+ if (!gid_valid(effective)) {
71546+ effectiveok = 1;
71547+ globaleffective = (gid_t)-1;
71548+ } else {
71549+ globaleffective = GR_GLOBAL_GID(effective);
71550+ }
71551+ if (!gid_valid(fs)) {
71552+ fsok = 1;
71553+ globalfs = (gid_t)-1;
71554+ } else {
71555+ globalfs = GR_GLOBAL_GID(fs);
71556+ }
71557+
71558+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
71559+ for (i = 0; i < num; i++) {
71560+ curgid = gidlist[i];
71561+ if (globalreal == curgid)
71562+ realok = 1;
71563+ if (globaleffective == curgid)
71564+ effectiveok = 1;
71565+ if (globalfs == curgid)
71566+ fsok = 1;
71567+ }
71568+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
71569+ for (i = 0; i < num; i++) {
71570+ curgid = gidlist[i];
71571+ if (globalreal == curgid)
71572+ break;
71573+ if (globaleffective == curgid)
71574+ break;
71575+ if (globalfs == curgid)
71576+ break;
71577+ }
71578+ /* not in deny list */
71579+ if (i == num) {
71580+ realok = 1;
71581+ effectiveok = 1;
71582+ fsok = 1;
71583+ }
71584+ }
71585+
71586+ if (realok && effectiveok && fsok)
71587+ return 0;
71588+ else {
71589+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71590+ return 1;
71591+ }
71592+}
71593+
71594+extern int gr_acl_is_capable(const int cap);
71595+
71596+void
71597+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
71598+{
71599+ struct acl_role_label *role = task->role;
71600+ struct acl_subject_label *subj = NULL;
71601+ struct acl_object_label *obj;
71602+ struct file *filp;
71603+ uid_t uid;
71604+ gid_t gid;
71605+
71606+ if (unlikely(!(gr_status & GR_READY)))
71607+ return;
71608+
71609+ uid = GR_GLOBAL_UID(kuid);
71610+ gid = GR_GLOBAL_GID(kgid);
71611+
71612+ filp = task->exec_file;
71613+
71614+ /* kernel process, we'll give them the kernel role */
71615+ if (unlikely(!filp)) {
71616+ task->role = running_polstate.kernel_role;
71617+ task->acl = running_polstate.kernel_role->root_label;
71618+ return;
71619+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
71620+ /* save the current ip at time of role lookup so that the proper
71621+ IP will be learned for role_allowed_ip */
71622+ task->signal->saved_ip = task->signal->curr_ip;
71623+ role = lookup_acl_role_label(task, uid, gid);
71624+ }
71625+
71626+ /* don't change the role if we're not a privileged process */
71627+ if (role && task->role != role &&
71628+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
71629+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
71630+ return;
71631+
71632+ /* perform subject lookup in possibly new role
71633+ we can use this result below in the case where role == task->role
71634+ */
71635+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
71636+
71637+ /* if we changed uid/gid, but result in the same role
71638+ and are using inheritance, don't lose the inherited subject
71639+ if current subject is other than what normal lookup
71640+ would result in, we arrived via inheritance, don't
71641+ lose subject
71642+ */
71643+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
71644+ (subj == task->acl)))
71645+ task->acl = subj;
71646+
71647+ /* leave task->inherited unaffected */
71648+
71649+ task->role = role;
71650+
71651+ task->is_writable = 0;
71652+
71653+ /* ignore additional mmap checks for processes that are writable
71654+ by the default ACL */
71655+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71656+ if (unlikely(obj->mode & GR_WRITE))
71657+ task->is_writable = 1;
71658+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
71659+ if (unlikely(obj->mode & GR_WRITE))
71660+ task->is_writable = 1;
71661+
71662+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71663+ 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);
71664+#endif
71665+
71666+ gr_set_proc_res(task);
71667+
71668+ return;
71669+}
71670+
71671+int
71672+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
71673+ const int unsafe_flags)
71674+{
71675+ struct task_struct *task = current;
71676+ struct acl_subject_label *newacl;
71677+ struct acl_object_label *obj;
71678+ __u32 retmode;
71679+
71680+ if (unlikely(!(gr_status & GR_READY)))
71681+ return 0;
71682+
71683+ newacl = chk_subj_label(dentry, mnt, task->role);
71684+
71685+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
71686+ did an exec
71687+ */
71688+ rcu_read_lock();
71689+ read_lock(&tasklist_lock);
71690+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
71691+ (task->parent->acl->mode & GR_POVERRIDE))) {
71692+ read_unlock(&tasklist_lock);
71693+ rcu_read_unlock();
71694+ goto skip_check;
71695+ }
71696+ read_unlock(&tasklist_lock);
71697+ rcu_read_unlock();
71698+
71699+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
71700+ !(task->role->roletype & GR_ROLE_GOD) &&
71701+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
71702+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
71703+ if (unsafe_flags & LSM_UNSAFE_SHARE)
71704+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
71705+ else
71706+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
71707+ return -EACCES;
71708+ }
71709+
71710+skip_check:
71711+
71712+ obj = chk_obj_label(dentry, mnt, task->acl);
71713+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
71714+
71715+ if (!(task->acl->mode & GR_INHERITLEARN) &&
71716+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
71717+ if (obj->nested)
71718+ task->acl = obj->nested;
71719+ else
71720+ task->acl = newacl;
71721+ task->inherited = 0;
71722+ } else {
71723+ task->inherited = 1;
71724+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
71725+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
71726+ }
71727+
71728+ task->is_writable = 0;
71729+
71730+ /* ignore additional mmap checks for processes that are writable
71731+ by the default ACL */
71732+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
71733+ if (unlikely(obj->mode & GR_WRITE))
71734+ task->is_writable = 1;
71735+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
71736+ if (unlikely(obj->mode & GR_WRITE))
71737+ task->is_writable = 1;
71738+
71739+ gr_set_proc_res(task);
71740+
71741+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71742+ 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);
71743+#endif
71744+ return 0;
71745+}
71746+
71747+/* always called with valid inodev ptr */
71748+static void
71749+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
71750+{
71751+ struct acl_object_label *matchpo;
71752+ struct acl_subject_label *matchps;
71753+ struct acl_subject_label *subj;
71754+ struct acl_role_label *role;
71755+ unsigned int x;
71756+
71757+ FOR_EACH_ROLE_START(role)
71758+ FOR_EACH_SUBJECT_START(role, subj, x)
71759+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71760+ matchpo->mode |= GR_DELETED;
71761+ FOR_EACH_SUBJECT_END(subj,x)
71762+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
71763+ /* nested subjects aren't in the role's subj_hash table */
71764+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71765+ matchpo->mode |= GR_DELETED;
71766+ FOR_EACH_NESTED_SUBJECT_END(subj)
71767+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
71768+ matchps->mode |= GR_DELETED;
71769+ FOR_EACH_ROLE_END(role)
71770+
71771+ inodev->nentry->deleted = 1;
71772+
71773+ return;
71774+}
71775+
71776+void
71777+gr_handle_delete(const ino_t ino, const dev_t dev)
71778+{
71779+ struct inodev_entry *inodev;
71780+
71781+ if (unlikely(!(gr_status & GR_READY)))
71782+ return;
71783+
71784+ write_lock(&gr_inode_lock);
71785+ inodev = lookup_inodev_entry(ino, dev);
71786+ if (inodev != NULL)
71787+ do_handle_delete(inodev, ino, dev);
71788+ write_unlock(&gr_inode_lock);
71789+
71790+ return;
71791+}
71792+
71793+static void
71794+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
71795+ const ino_t newinode, const dev_t newdevice,
71796+ struct acl_subject_label *subj)
71797+{
71798+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
71799+ struct acl_object_label *match;
71800+
71801+ match = subj->obj_hash[index];
71802+
71803+ while (match && (match->inode != oldinode ||
71804+ match->device != olddevice ||
71805+ !(match->mode & GR_DELETED)))
71806+ match = match->next;
71807+
71808+ if (match && (match->inode == oldinode)
71809+ && (match->device == olddevice)
71810+ && (match->mode & GR_DELETED)) {
71811+ if (match->prev == NULL) {
71812+ subj->obj_hash[index] = match->next;
71813+ if (match->next != NULL)
71814+ match->next->prev = NULL;
71815+ } else {
71816+ match->prev->next = match->next;
71817+ if (match->next != NULL)
71818+ match->next->prev = match->prev;
71819+ }
71820+ match->prev = NULL;
71821+ match->next = NULL;
71822+ match->inode = newinode;
71823+ match->device = newdevice;
71824+ match->mode &= ~GR_DELETED;
71825+
71826+ insert_acl_obj_label(match, subj);
71827+ }
71828+
71829+ return;
71830+}
71831+
71832+static void
71833+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
71834+ const ino_t newinode, const dev_t newdevice,
71835+ struct acl_role_label *role)
71836+{
71837+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
71838+ struct acl_subject_label *match;
71839+
71840+ match = role->subj_hash[index];
71841+
71842+ while (match && (match->inode != oldinode ||
71843+ match->device != olddevice ||
71844+ !(match->mode & GR_DELETED)))
71845+ match = match->next;
71846+
71847+ if (match && (match->inode == oldinode)
71848+ && (match->device == olddevice)
71849+ && (match->mode & GR_DELETED)) {
71850+ if (match->prev == NULL) {
71851+ role->subj_hash[index] = match->next;
71852+ if (match->next != NULL)
71853+ match->next->prev = NULL;
71854+ } else {
71855+ match->prev->next = match->next;
71856+ if (match->next != NULL)
71857+ match->next->prev = match->prev;
71858+ }
71859+ match->prev = NULL;
71860+ match->next = NULL;
71861+ match->inode = newinode;
71862+ match->device = newdevice;
71863+ match->mode &= ~GR_DELETED;
71864+
71865+ insert_acl_subj_label(match, role);
71866+ }
71867+
71868+ return;
71869+}
71870+
71871+static void
71872+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
71873+ const ino_t newinode, const dev_t newdevice)
71874+{
71875+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
71876+ struct inodev_entry *match;
71877+
71878+ match = running_polstate.inodev_set.i_hash[index];
71879+
71880+ while (match && (match->nentry->inode != oldinode ||
71881+ match->nentry->device != olddevice || !match->nentry->deleted))
71882+ match = match->next;
71883+
71884+ if (match && (match->nentry->inode == oldinode)
71885+ && (match->nentry->device == olddevice) &&
71886+ match->nentry->deleted) {
71887+ if (match->prev == NULL) {
71888+ running_polstate.inodev_set.i_hash[index] = match->next;
71889+ if (match->next != NULL)
71890+ match->next->prev = NULL;
71891+ } else {
71892+ match->prev->next = match->next;
71893+ if (match->next != NULL)
71894+ match->next->prev = match->prev;
71895+ }
71896+ match->prev = NULL;
71897+ match->next = NULL;
71898+ match->nentry->inode = newinode;
71899+ match->nentry->device = newdevice;
71900+ match->nentry->deleted = 0;
71901+
71902+ insert_inodev_entry(match);
71903+ }
71904+
71905+ return;
71906+}
71907+
71908+static void
71909+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
71910+{
71911+ struct acl_subject_label *subj;
71912+ struct acl_role_label *role;
71913+ unsigned int x;
71914+
71915+ FOR_EACH_ROLE_START(role)
71916+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
71917+
71918+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
71919+ if ((subj->inode == ino) && (subj->device == dev)) {
71920+ subj->inode = ino;
71921+ subj->device = dev;
71922+ }
71923+ /* nested subjects aren't in the role's subj_hash table */
71924+ update_acl_obj_label(matchn->inode, matchn->device,
71925+ ino, dev, subj);
71926+ FOR_EACH_NESTED_SUBJECT_END(subj)
71927+ FOR_EACH_SUBJECT_START(role, subj, x)
71928+ update_acl_obj_label(matchn->inode, matchn->device,
71929+ ino, dev, subj);
71930+ FOR_EACH_SUBJECT_END(subj,x)
71931+ FOR_EACH_ROLE_END(role)
71932+
71933+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
71934+
71935+ return;
71936+}
71937+
71938+static void
71939+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
71940+ const struct vfsmount *mnt)
71941+{
71942+ ino_t ino = dentry->d_inode->i_ino;
71943+ dev_t dev = __get_dev(dentry);
71944+
71945+ __do_handle_create(matchn, ino, dev);
71946+
71947+ return;
71948+}
71949+
71950+void
71951+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
71952+{
71953+ struct name_entry *matchn;
71954+
71955+ if (unlikely(!(gr_status & GR_READY)))
71956+ return;
71957+
71958+ preempt_disable();
71959+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
71960+
71961+ if (unlikely((unsigned long)matchn)) {
71962+ write_lock(&gr_inode_lock);
71963+ do_handle_create(matchn, dentry, mnt);
71964+ write_unlock(&gr_inode_lock);
71965+ }
71966+ preempt_enable();
71967+
71968+ return;
71969+}
71970+
71971+void
71972+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
71973+{
71974+ struct name_entry *matchn;
71975+
71976+ if (unlikely(!(gr_status & GR_READY)))
71977+ return;
71978+
71979+ preempt_disable();
71980+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
71981+
71982+ if (unlikely((unsigned long)matchn)) {
71983+ write_lock(&gr_inode_lock);
71984+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
71985+ write_unlock(&gr_inode_lock);
71986+ }
71987+ preempt_enable();
71988+
71989+ return;
71990+}
71991+
71992+void
71993+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
71994+ struct dentry *old_dentry,
71995+ struct dentry *new_dentry,
71996+ struct vfsmount *mnt, const __u8 replace, unsigned int flags)
71997+{
71998+ struct name_entry *matchn;
71999+ struct name_entry *matchn2 = NULL;
72000+ struct inodev_entry *inodev;
72001+ struct inode *inode = new_dentry->d_inode;
72002+ ino_t old_ino = old_dentry->d_inode->i_ino;
72003+ dev_t old_dev = __get_dev(old_dentry);
72004+ unsigned int exchange = flags & RENAME_EXCHANGE;
72005+
72006+ /* vfs_rename swaps the name and parent link for old_dentry and
72007+ new_dentry
72008+ at this point, old_dentry has the new name, parent link, and inode
72009+ for the renamed file
72010+ if a file is being replaced by a rename, new_dentry has the inode
72011+ and name for the replaced file
72012+ */
72013+
72014+ if (unlikely(!(gr_status & GR_READY)))
72015+ return;
72016+
72017+ preempt_disable();
72018+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
72019+
72020+ /* exchange cases:
72021+ a filename exists for the source, but not dest
72022+ do a recreate on source
72023+ a filename exists for the dest, but not source
72024+ do a recreate on dest
72025+ a filename exists for both source and dest
72026+ delete source and dest, then create source and dest
72027+ a filename exists for neither source nor dest
72028+ no updates needed
72029+
72030+ the name entry lookups get us the old inode/dev associated with
72031+ each name, so do the deletes first (if possible) so that when
72032+ we do the create, we pick up on the right entries
72033+ */
72034+
72035+ if (exchange)
72036+ matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
72037+
72038+ /* we wouldn't have to check d_inode if it weren't for
72039+ NFS silly-renaming
72040+ */
72041+
72042+ write_lock(&gr_inode_lock);
72043+ if (unlikely((replace || exchange) && inode)) {
72044+ ino_t new_ino = inode->i_ino;
72045+ dev_t new_dev = __get_dev(new_dentry);
72046+
72047+ inodev = lookup_inodev_entry(new_ino, new_dev);
72048+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
72049+ do_handle_delete(inodev, new_ino, new_dev);
72050+ }
72051+
72052+ inodev = lookup_inodev_entry(old_ino, old_dev);
72053+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
72054+ do_handle_delete(inodev, old_ino, old_dev);
72055+
72056+ if (unlikely(matchn != NULL))
72057+ do_handle_create(matchn, old_dentry, mnt);
72058+
72059+ if (unlikely(matchn2 != NULL))
72060+ do_handle_create(matchn2, new_dentry, mnt);
72061+
72062+ write_unlock(&gr_inode_lock);
72063+ preempt_enable();
72064+
72065+ return;
72066+}
72067+
72068+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
72069+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
72070+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
72071+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
72072+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
72073+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
72074+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
72075+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
72076+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
72077+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
72078+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
72079+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
72080+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
72081+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
72082+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
72083+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
72084+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
72085+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
72086+};
72087+
72088+void
72089+gr_learn_resource(const struct task_struct *task,
72090+ const int res, const unsigned long wanted, const int gt)
72091+{
72092+ struct acl_subject_label *acl;
72093+ const struct cred *cred;
72094+
72095+ if (unlikely((gr_status & GR_READY) &&
72096+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
72097+ goto skip_reslog;
72098+
72099+ gr_log_resource(task, res, wanted, gt);
72100+skip_reslog:
72101+
72102+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
72103+ return;
72104+
72105+ acl = task->acl;
72106+
72107+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
72108+ !(acl->resmask & (1U << (unsigned short) res))))
72109+ return;
72110+
72111+ if (wanted >= acl->res[res].rlim_cur) {
72112+ unsigned long res_add;
72113+
72114+ res_add = wanted + res_learn_bumps[res];
72115+
72116+ acl->res[res].rlim_cur = res_add;
72117+
72118+ if (wanted > acl->res[res].rlim_max)
72119+ acl->res[res].rlim_max = res_add;
72120+
72121+ /* only log the subject filename, since resource logging is supported for
72122+ single-subject learning only */
72123+ rcu_read_lock();
72124+ cred = __task_cred(task);
72125+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
72126+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
72127+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
72128+ "", (unsigned long) res, &task->signal->saved_ip);
72129+ rcu_read_unlock();
72130+ }
72131+
72132+ return;
72133+}
72134+EXPORT_SYMBOL_GPL(gr_learn_resource);
72135+#endif
72136+
72137+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
72138+void
72139+pax_set_initial_flags(struct linux_binprm *bprm)
72140+{
72141+ struct task_struct *task = current;
72142+ struct acl_subject_label *proc;
72143+ unsigned long flags;
72144+
72145+ if (unlikely(!(gr_status & GR_READY)))
72146+ return;
72147+
72148+ flags = pax_get_flags(task);
72149+
72150+ proc = task->acl;
72151+
72152+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
72153+ flags &= ~MF_PAX_PAGEEXEC;
72154+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
72155+ flags &= ~MF_PAX_SEGMEXEC;
72156+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
72157+ flags &= ~MF_PAX_RANDMMAP;
72158+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
72159+ flags &= ~MF_PAX_EMUTRAMP;
72160+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
72161+ flags &= ~MF_PAX_MPROTECT;
72162+
72163+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
72164+ flags |= MF_PAX_PAGEEXEC;
72165+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
72166+ flags |= MF_PAX_SEGMEXEC;
72167+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
72168+ flags |= MF_PAX_RANDMMAP;
72169+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
72170+ flags |= MF_PAX_EMUTRAMP;
72171+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
72172+ flags |= MF_PAX_MPROTECT;
72173+
72174+ pax_set_flags(task, flags);
72175+
72176+ return;
72177+}
72178+#endif
72179+
72180+int
72181+gr_handle_proc_ptrace(struct task_struct *task)
72182+{
72183+ struct file *filp;
72184+ struct task_struct *tmp = task;
72185+ struct task_struct *curtemp = current;
72186+ __u32 retmode;
72187+
72188+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
72189+ if (unlikely(!(gr_status & GR_READY)))
72190+ return 0;
72191+#endif
72192+
72193+ read_lock(&tasklist_lock);
72194+ read_lock(&grsec_exec_file_lock);
72195+ filp = task->exec_file;
72196+
72197+ while (task_pid_nr(tmp) > 0) {
72198+ if (tmp == curtemp)
72199+ break;
72200+ tmp = tmp->real_parent;
72201+ }
72202+
72203+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
72204+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
72205+ read_unlock(&grsec_exec_file_lock);
72206+ read_unlock(&tasklist_lock);
72207+ return 1;
72208+ }
72209+
72210+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
72211+ if (!(gr_status & GR_READY)) {
72212+ read_unlock(&grsec_exec_file_lock);
72213+ read_unlock(&tasklist_lock);
72214+ return 0;
72215+ }
72216+#endif
72217+
72218+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
72219+ read_unlock(&grsec_exec_file_lock);
72220+ read_unlock(&tasklist_lock);
72221+
72222+ if (retmode & GR_NOPTRACE)
72223+ return 1;
72224+
72225+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
72226+ && (current->acl != task->acl || (current->acl != current->role->root_label
72227+ && task_pid_nr(current) != task_pid_nr(task))))
72228+ return 1;
72229+
72230+ return 0;
72231+}
72232+
72233+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
72234+{
72235+ if (unlikely(!(gr_status & GR_READY)))
72236+ return;
72237+
72238+ if (!(current->role->roletype & GR_ROLE_GOD))
72239+ return;
72240+
72241+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
72242+ p->role->rolename, gr_task_roletype_to_char(p),
72243+ p->acl->filename);
72244+}
72245+
72246+int
72247+gr_handle_ptrace(struct task_struct *task, const long request)
72248+{
72249+ struct task_struct *tmp = task;
72250+ struct task_struct *curtemp = current;
72251+ __u32 retmode;
72252+
72253+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
72254+ if (unlikely(!(gr_status & GR_READY)))
72255+ return 0;
72256+#endif
72257+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
72258+ read_lock(&tasklist_lock);
72259+ while (task_pid_nr(tmp) > 0) {
72260+ if (tmp == curtemp)
72261+ break;
72262+ tmp = tmp->real_parent;
72263+ }
72264+
72265+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
72266+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
72267+ read_unlock(&tasklist_lock);
72268+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72269+ return 1;
72270+ }
72271+ read_unlock(&tasklist_lock);
72272+ }
72273+
72274+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
72275+ if (!(gr_status & GR_READY))
72276+ return 0;
72277+#endif
72278+
72279+ read_lock(&grsec_exec_file_lock);
72280+ if (unlikely(!task->exec_file)) {
72281+ read_unlock(&grsec_exec_file_lock);
72282+ return 0;
72283+ }
72284+
72285+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
72286+ read_unlock(&grsec_exec_file_lock);
72287+
72288+ if (retmode & GR_NOPTRACE) {
72289+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72290+ return 1;
72291+ }
72292+
72293+ if (retmode & GR_PTRACERD) {
72294+ switch (request) {
72295+ case PTRACE_SEIZE:
72296+ case PTRACE_POKETEXT:
72297+ case PTRACE_POKEDATA:
72298+ case PTRACE_POKEUSR:
72299+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
72300+ case PTRACE_SETREGS:
72301+ case PTRACE_SETFPREGS:
72302+#endif
72303+#ifdef CONFIG_X86
72304+ case PTRACE_SETFPXREGS:
72305+#endif
72306+#ifdef CONFIG_ALTIVEC
72307+ case PTRACE_SETVRREGS:
72308+#endif
72309+ return 1;
72310+ default:
72311+ return 0;
72312+ }
72313+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
72314+ !(current->role->roletype & GR_ROLE_GOD) &&
72315+ (current->acl != task->acl)) {
72316+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
72317+ return 1;
72318+ }
72319+
72320+ return 0;
72321+}
72322+
72323+static int is_writable_mmap(const struct file *filp)
72324+{
72325+ struct task_struct *task = current;
72326+ struct acl_object_label *obj, *obj2;
72327+
72328+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
72329+ !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))) {
72330+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
72331+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
72332+ task->role->root_label);
72333+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
72334+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
72335+ return 1;
72336+ }
72337+ }
72338+ return 0;
72339+}
72340+
72341+int
72342+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
72343+{
72344+ __u32 mode;
72345+
72346+ if (unlikely(!file || !(prot & PROT_EXEC)))
72347+ return 1;
72348+
72349+ if (is_writable_mmap(file))
72350+ return 0;
72351+
72352+ mode =
72353+ gr_search_file(file->f_path.dentry,
72354+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
72355+ file->f_path.mnt);
72356+
72357+ if (!gr_tpe_allow(file))
72358+ return 0;
72359+
72360+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
72361+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72362+ return 0;
72363+ } else if (unlikely(!(mode & GR_EXEC))) {
72364+ return 0;
72365+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72366+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72367+ return 1;
72368+ }
72369+
72370+ return 1;
72371+}
72372+
72373+int
72374+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
72375+{
72376+ __u32 mode;
72377+
72378+ if (unlikely(!file || !(prot & PROT_EXEC)))
72379+ return 1;
72380+
72381+ if (is_writable_mmap(file))
72382+ return 0;
72383+
72384+ mode =
72385+ gr_search_file(file->f_path.dentry,
72386+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
72387+ file->f_path.mnt);
72388+
72389+ if (!gr_tpe_allow(file))
72390+ return 0;
72391+
72392+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
72393+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72394+ return 0;
72395+ } else if (unlikely(!(mode & GR_EXEC))) {
72396+ return 0;
72397+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72398+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72399+ return 1;
72400+ }
72401+
72402+ return 1;
72403+}
72404+
72405+void
72406+gr_acl_handle_psacct(struct task_struct *task, const long code)
72407+{
72408+ unsigned long runtime, cputime;
72409+ cputime_t utime, stime;
72410+ unsigned int wday, cday;
72411+ __u8 whr, chr;
72412+ __u8 wmin, cmin;
72413+ __u8 wsec, csec;
72414+ struct timespec curtime, starttime;
72415+
72416+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
72417+ !(task->acl->mode & GR_PROCACCT)))
72418+ return;
72419+
72420+ curtime = ns_to_timespec(ktime_get_ns());
72421+ starttime = ns_to_timespec(task->start_time);
72422+ runtime = curtime.tv_sec - starttime.tv_sec;
72423+ wday = runtime / (60 * 60 * 24);
72424+ runtime -= wday * (60 * 60 * 24);
72425+ whr = runtime / (60 * 60);
72426+ runtime -= whr * (60 * 60);
72427+ wmin = runtime / 60;
72428+ runtime -= wmin * 60;
72429+ wsec = runtime;
72430+
72431+ task_cputime(task, &utime, &stime);
72432+ cputime = cputime_to_secs(utime + stime);
72433+ cday = cputime / (60 * 60 * 24);
72434+ cputime -= cday * (60 * 60 * 24);
72435+ chr = cputime / (60 * 60);
72436+ cputime -= chr * (60 * 60);
72437+ cmin = cputime / 60;
72438+ cputime -= cmin * 60;
72439+ csec = cputime;
72440+
72441+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
72442+
72443+ return;
72444+}
72445+
72446+#ifdef CONFIG_TASKSTATS
72447+int gr_is_taskstats_denied(int pid)
72448+{
72449+ struct task_struct *task;
72450+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72451+ const struct cred *cred;
72452+#endif
72453+ int ret = 0;
72454+
72455+ /* restrict taskstats viewing to un-chrooted root users
72456+ who have the 'view' subject flag if the RBAC system is enabled
72457+ */
72458+
72459+ rcu_read_lock();
72460+ read_lock(&tasklist_lock);
72461+ task = find_task_by_vpid(pid);
72462+ if (task) {
72463+#ifdef CONFIG_GRKERNSEC_CHROOT
72464+ if (proc_is_chrooted(task))
72465+ ret = -EACCES;
72466+#endif
72467+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72468+ cred = __task_cred(task);
72469+#ifdef CONFIG_GRKERNSEC_PROC_USER
72470+ if (gr_is_global_nonroot(cred->uid))
72471+ ret = -EACCES;
72472+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72473+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
72474+ ret = -EACCES;
72475+#endif
72476+#endif
72477+ if (gr_status & GR_READY) {
72478+ if (!(task->acl->mode & GR_VIEW))
72479+ ret = -EACCES;
72480+ }
72481+ } else
72482+ ret = -ENOENT;
72483+
72484+ read_unlock(&tasklist_lock);
72485+ rcu_read_unlock();
72486+
72487+ return ret;
72488+}
72489+#endif
72490+
72491+/* AUXV entries are filled via a descendant of search_binary_handler
72492+ after we've already applied the subject for the target
72493+*/
72494+int gr_acl_enable_at_secure(void)
72495+{
72496+ if (unlikely(!(gr_status & GR_READY)))
72497+ return 0;
72498+
72499+ if (current->acl->mode & GR_ATSECURE)
72500+ return 1;
72501+
72502+ return 0;
72503+}
72504+
72505+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
72506+{
72507+ struct task_struct *task = current;
72508+ struct dentry *dentry = file->f_path.dentry;
72509+ struct vfsmount *mnt = file->f_path.mnt;
72510+ struct acl_object_label *obj, *tmp;
72511+ struct acl_subject_label *subj;
72512+ unsigned int bufsize;
72513+ int is_not_root;
72514+ char *path;
72515+ dev_t dev = __get_dev(dentry);
72516+
72517+ if (unlikely(!(gr_status & GR_READY)))
72518+ return 1;
72519+
72520+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
72521+ return 1;
72522+
72523+ /* ignore Eric Biederman */
72524+ if (IS_PRIVATE(dentry->d_inode))
72525+ return 1;
72526+
72527+ subj = task->acl;
72528+ read_lock(&gr_inode_lock);
72529+ do {
72530+ obj = lookup_acl_obj_label(ino, dev, subj);
72531+ if (obj != NULL) {
72532+ read_unlock(&gr_inode_lock);
72533+ return (obj->mode & GR_FIND) ? 1 : 0;
72534+ }
72535+ } while ((subj = subj->parent_subject));
72536+ read_unlock(&gr_inode_lock);
72537+
72538+ /* this is purely an optimization since we're looking for an object
72539+ for the directory we're doing a readdir on
72540+ if it's possible for any globbed object to match the entry we're
72541+ filling into the directory, then the object we find here will be
72542+ an anchor point with attached globbed objects
72543+ */
72544+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
72545+ if (obj->globbed == NULL)
72546+ return (obj->mode & GR_FIND) ? 1 : 0;
72547+
72548+ is_not_root = ((obj->filename[0] == '/') &&
72549+ (obj->filename[1] == '\0')) ? 0 : 1;
72550+ bufsize = PAGE_SIZE - namelen - is_not_root;
72551+
72552+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
72553+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
72554+ return 1;
72555+
72556+ preempt_disable();
72557+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
72558+ bufsize);
72559+
72560+ bufsize = strlen(path);
72561+
72562+ /* if base is "/", don't append an additional slash */
72563+ if (is_not_root)
72564+ *(path + bufsize) = '/';
72565+ memcpy(path + bufsize + is_not_root, name, namelen);
72566+ *(path + bufsize + namelen + is_not_root) = '\0';
72567+
72568+ tmp = obj->globbed;
72569+ while (tmp) {
72570+ if (!glob_match(tmp->filename, path)) {
72571+ preempt_enable();
72572+ return (tmp->mode & GR_FIND) ? 1 : 0;
72573+ }
72574+ tmp = tmp->next;
72575+ }
72576+ preempt_enable();
72577+ return (obj->mode & GR_FIND) ? 1 : 0;
72578+}
72579+
72580+void gr_put_exec_file(struct task_struct *task)
72581+{
72582+ struct file *filp;
72583+
72584+ write_lock(&grsec_exec_file_lock);
72585+ filp = task->exec_file;
72586+ task->exec_file = NULL;
72587+ write_unlock(&grsec_exec_file_lock);
72588+
72589+ if (filp)
72590+ fput(filp);
72591+
72592+ return;
72593+}
72594+
72595+
72596+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
72597+EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
72598+#endif
72599+#ifdef CONFIG_SECURITY
72600+EXPORT_SYMBOL_GPL(gr_check_user_change);
72601+EXPORT_SYMBOL_GPL(gr_check_group_change);
72602+#endif
72603+
72604diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
72605new file mode 100644
72606index 0000000..18ffbbd
72607--- /dev/null
72608+++ b/grsecurity/gracl_alloc.c
72609@@ -0,0 +1,105 @@
72610+#include <linux/kernel.h>
72611+#include <linux/mm.h>
72612+#include <linux/slab.h>
72613+#include <linux/vmalloc.h>
72614+#include <linux/gracl.h>
72615+#include <linux/grsecurity.h>
72616+
72617+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
72618+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
72619+
72620+static __inline__ int
72621+alloc_pop(void)
72622+{
72623+ if (current_alloc_state->alloc_stack_next == 1)
72624+ return 0;
72625+
72626+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
72627+
72628+ current_alloc_state->alloc_stack_next--;
72629+
72630+ return 1;
72631+}
72632+
72633+static __inline__ int
72634+alloc_push(void *buf)
72635+{
72636+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
72637+ return 1;
72638+
72639+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
72640+
72641+ current_alloc_state->alloc_stack_next++;
72642+
72643+ return 0;
72644+}
72645+
72646+void *
72647+acl_alloc(unsigned long len)
72648+{
72649+ void *ret = NULL;
72650+
72651+ if (!len || len > PAGE_SIZE)
72652+ goto out;
72653+
72654+ ret = kmalloc(len, GFP_KERNEL);
72655+
72656+ if (ret) {
72657+ if (alloc_push(ret)) {
72658+ kfree(ret);
72659+ ret = NULL;
72660+ }
72661+ }
72662+
72663+out:
72664+ return ret;
72665+}
72666+
72667+void *
72668+acl_alloc_num(unsigned long num, unsigned long len)
72669+{
72670+ if (!len || (num > (PAGE_SIZE / len)))
72671+ return NULL;
72672+
72673+ return acl_alloc(num * len);
72674+}
72675+
72676+void
72677+acl_free_all(void)
72678+{
72679+ if (!current_alloc_state->alloc_stack)
72680+ return;
72681+
72682+ while (alloc_pop()) ;
72683+
72684+ if (current_alloc_state->alloc_stack) {
72685+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
72686+ kfree(current_alloc_state->alloc_stack);
72687+ else
72688+ vfree(current_alloc_state->alloc_stack);
72689+ }
72690+
72691+ current_alloc_state->alloc_stack = NULL;
72692+ current_alloc_state->alloc_stack_size = 1;
72693+ current_alloc_state->alloc_stack_next = 1;
72694+
72695+ return;
72696+}
72697+
72698+int
72699+acl_alloc_stack_init(unsigned long size)
72700+{
72701+ if ((size * sizeof (void *)) <= PAGE_SIZE)
72702+ current_alloc_state->alloc_stack =
72703+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
72704+ else
72705+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
72706+
72707+ current_alloc_state->alloc_stack_size = size;
72708+ current_alloc_state->alloc_stack_next = 1;
72709+
72710+ if (!current_alloc_state->alloc_stack)
72711+ return 0;
72712+ else
72713+ return 1;
72714+}
72715diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
72716new file mode 100644
72717index 0000000..1a94c11
72718--- /dev/null
72719+++ b/grsecurity/gracl_cap.c
72720@@ -0,0 +1,127 @@
72721+#include <linux/kernel.h>
72722+#include <linux/module.h>
72723+#include <linux/sched.h>
72724+#include <linux/gracl.h>
72725+#include <linux/grsecurity.h>
72726+#include <linux/grinternal.h>
72727+
72728+extern const char *captab_log[];
72729+extern int captab_log_entries;
72730+
72731+int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
72732+{
72733+ struct acl_subject_label *curracl;
72734+
72735+ if (!gr_acl_is_enabled())
72736+ return 1;
72737+
72738+ curracl = task->acl;
72739+
72740+ if (curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
72741+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
72742+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
72743+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
72744+ gr_to_filename(task->exec_file->f_path.dentry,
72745+ task->exec_file->f_path.mnt) : curracl->filename,
72746+ curracl->filename, 0UL,
72747+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
72748+ return 1;
72749+ }
72750+
72751+ return 0;
72752+}
72753+
72754+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72755+{
72756+ struct acl_subject_label *curracl;
72757+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72758+ kernel_cap_t cap_audit = __cap_empty_set;
72759+
72760+ if (!gr_acl_is_enabled())
72761+ return 1;
72762+
72763+ curracl = task->acl;
72764+
72765+ cap_drop = curracl->cap_lower;
72766+ cap_mask = curracl->cap_mask;
72767+ cap_audit = curracl->cap_invert_audit;
72768+
72769+ while ((curracl = curracl->parent_subject)) {
72770+ /* if the cap isn't specified in the current computed mask but is specified in the
72771+ current level subject, and is lowered in the current level subject, then add
72772+ it to the set of dropped capabilities
72773+ otherwise, add the current level subject's mask to the current computed mask
72774+ */
72775+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72776+ cap_raise(cap_mask, cap);
72777+ if (cap_raised(curracl->cap_lower, cap))
72778+ cap_raise(cap_drop, cap);
72779+ if (cap_raised(curracl->cap_invert_audit, cap))
72780+ cap_raise(cap_audit, cap);
72781+ }
72782+ }
72783+
72784+ if (!cap_raised(cap_drop, cap)) {
72785+ if (cap_raised(cap_audit, cap))
72786+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
72787+ return 1;
72788+ }
72789+
72790+ /* only learn the capability use if the process has the capability in the
72791+ general case, the two uses in sys.c of gr_learn_cap are an exception
72792+ to this rule to ensure any role transition involves what the full-learned
72793+ policy believes in a privileged process
72794+ */
72795+ if (cap_raised(cred->cap_effective, cap) && gr_learn_cap(task, cred, cap))
72796+ return 1;
72797+
72798+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
72799+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
72800+
72801+ return 0;
72802+}
72803+
72804+int
72805+gr_acl_is_capable(const int cap)
72806+{
72807+ return gr_task_acl_is_capable(current, current_cred(), cap);
72808+}
72809+
72810+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
72811+{
72812+ struct acl_subject_label *curracl;
72813+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72814+
72815+ if (!gr_acl_is_enabled())
72816+ return 1;
72817+
72818+ curracl = task->acl;
72819+
72820+ cap_drop = curracl->cap_lower;
72821+ cap_mask = curracl->cap_mask;
72822+
72823+ while ((curracl = curracl->parent_subject)) {
72824+ /* if the cap isn't specified in the current computed mask but is specified in the
72825+ current level subject, and is lowered in the current level subject, then add
72826+ it to the set of dropped capabilities
72827+ otherwise, add the current level subject's mask to the current computed mask
72828+ */
72829+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72830+ cap_raise(cap_mask, cap);
72831+ if (cap_raised(curracl->cap_lower, cap))
72832+ cap_raise(cap_drop, cap);
72833+ }
72834+ }
72835+
72836+ if (!cap_raised(cap_drop, cap))
72837+ return 1;
72838+
72839+ return 0;
72840+}
72841+
72842+int
72843+gr_acl_is_capable_nolog(const int cap)
72844+{
72845+ return gr_task_acl_is_capable_nolog(current, cap);
72846+}
72847+
72848diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
72849new file mode 100644
72850index 0000000..ca25605
72851--- /dev/null
72852+++ b/grsecurity/gracl_compat.c
72853@@ -0,0 +1,270 @@
72854+#include <linux/kernel.h>
72855+#include <linux/gracl.h>
72856+#include <linux/compat.h>
72857+#include <linux/gracl_compat.h>
72858+
72859+#include <asm/uaccess.h>
72860+
72861+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
72862+{
72863+ struct gr_arg_wrapper_compat uwrapcompat;
72864+
72865+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
72866+ return -EFAULT;
72867+
72868+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
72869+ (uwrapcompat.version != 0x2901)) ||
72870+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
72871+ return -EINVAL;
72872+
72873+ uwrap->arg = compat_ptr(uwrapcompat.arg);
72874+ uwrap->version = uwrapcompat.version;
72875+ uwrap->size = sizeof(struct gr_arg);
72876+
72877+ return 0;
72878+}
72879+
72880+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
72881+{
72882+ struct gr_arg_compat argcompat;
72883+
72884+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
72885+ return -EFAULT;
72886+
72887+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
72888+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
72889+ arg->role_db.num_roles = argcompat.role_db.num_roles;
72890+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
72891+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
72892+ arg->role_db.num_objects = argcompat.role_db.num_objects;
72893+
72894+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
72895+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
72896+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
72897+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
72898+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
72899+ arg->segv_device = argcompat.segv_device;
72900+ arg->segv_inode = argcompat.segv_inode;
72901+ arg->segv_uid = argcompat.segv_uid;
72902+ arg->num_sprole_pws = argcompat.num_sprole_pws;
72903+ arg->mode = argcompat.mode;
72904+
72905+ return 0;
72906+}
72907+
72908+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
72909+{
72910+ struct acl_object_label_compat objcompat;
72911+
72912+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
72913+ return -EFAULT;
72914+
72915+ obj->filename = compat_ptr(objcompat.filename);
72916+ obj->inode = objcompat.inode;
72917+ obj->device = objcompat.device;
72918+ obj->mode = objcompat.mode;
72919+
72920+ obj->nested = compat_ptr(objcompat.nested);
72921+ obj->globbed = compat_ptr(objcompat.globbed);
72922+
72923+ obj->prev = compat_ptr(objcompat.prev);
72924+ obj->next = compat_ptr(objcompat.next);
72925+
72926+ return 0;
72927+}
72928+
72929+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
72930+{
72931+ unsigned int i;
72932+ struct acl_subject_label_compat subjcompat;
72933+
72934+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
72935+ return -EFAULT;
72936+
72937+ subj->filename = compat_ptr(subjcompat.filename);
72938+ subj->inode = subjcompat.inode;
72939+ subj->device = subjcompat.device;
72940+ subj->mode = subjcompat.mode;
72941+ subj->cap_mask = subjcompat.cap_mask;
72942+ subj->cap_lower = subjcompat.cap_lower;
72943+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
72944+
72945+ for (i = 0; i < GR_NLIMITS; i++) {
72946+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
72947+ subj->res[i].rlim_cur = RLIM_INFINITY;
72948+ else
72949+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
72950+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
72951+ subj->res[i].rlim_max = RLIM_INFINITY;
72952+ else
72953+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
72954+ }
72955+ subj->resmask = subjcompat.resmask;
72956+
72957+ subj->user_trans_type = subjcompat.user_trans_type;
72958+ subj->group_trans_type = subjcompat.group_trans_type;
72959+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
72960+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
72961+ subj->user_trans_num = subjcompat.user_trans_num;
72962+ subj->group_trans_num = subjcompat.group_trans_num;
72963+
72964+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
72965+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
72966+ subj->ip_type = subjcompat.ip_type;
72967+ subj->ips = compat_ptr(subjcompat.ips);
72968+ subj->ip_num = subjcompat.ip_num;
72969+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
72970+
72971+ subj->crashes = subjcompat.crashes;
72972+ subj->expires = subjcompat.expires;
72973+
72974+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
72975+ subj->hash = compat_ptr(subjcompat.hash);
72976+ subj->prev = compat_ptr(subjcompat.prev);
72977+ subj->next = compat_ptr(subjcompat.next);
72978+
72979+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
72980+ subj->obj_hash_size = subjcompat.obj_hash_size;
72981+ subj->pax_flags = subjcompat.pax_flags;
72982+
72983+ return 0;
72984+}
72985+
72986+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
72987+{
72988+ struct acl_role_label_compat rolecompat;
72989+
72990+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
72991+ return -EFAULT;
72992+
72993+ role->rolename = compat_ptr(rolecompat.rolename);
72994+ role->uidgid = rolecompat.uidgid;
72995+ role->roletype = rolecompat.roletype;
72996+
72997+ role->auth_attempts = rolecompat.auth_attempts;
72998+ role->expires = rolecompat.expires;
72999+
73000+ role->root_label = compat_ptr(rolecompat.root_label);
73001+ role->hash = compat_ptr(rolecompat.hash);
73002+
73003+ role->prev = compat_ptr(rolecompat.prev);
73004+ role->next = compat_ptr(rolecompat.next);
73005+
73006+ role->transitions = compat_ptr(rolecompat.transitions);
73007+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
73008+ role->domain_children = compat_ptr(rolecompat.domain_children);
73009+ role->domain_child_num = rolecompat.domain_child_num;
73010+
73011+ role->umask = rolecompat.umask;
73012+
73013+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
73014+ role->subj_hash_size = rolecompat.subj_hash_size;
73015+
73016+ return 0;
73017+}
73018+
73019+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
73020+{
73021+ struct role_allowed_ip_compat roleip_compat;
73022+
73023+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
73024+ return -EFAULT;
73025+
73026+ roleip->addr = roleip_compat.addr;
73027+ roleip->netmask = roleip_compat.netmask;
73028+
73029+ roleip->prev = compat_ptr(roleip_compat.prev);
73030+ roleip->next = compat_ptr(roleip_compat.next);
73031+
73032+ return 0;
73033+}
73034+
73035+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
73036+{
73037+ struct role_transition_compat trans_compat;
73038+
73039+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
73040+ return -EFAULT;
73041+
73042+ trans->rolename = compat_ptr(trans_compat.rolename);
73043+
73044+ trans->prev = compat_ptr(trans_compat.prev);
73045+ trans->next = compat_ptr(trans_compat.next);
73046+
73047+ return 0;
73048+
73049+}
73050+
73051+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
73052+{
73053+ struct gr_hash_struct_compat hash_compat;
73054+
73055+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
73056+ return -EFAULT;
73057+
73058+ hash->table = compat_ptr(hash_compat.table);
73059+ hash->nametable = compat_ptr(hash_compat.nametable);
73060+ hash->first = compat_ptr(hash_compat.first);
73061+
73062+ hash->table_size = hash_compat.table_size;
73063+ hash->used_size = hash_compat.used_size;
73064+
73065+ hash->type = hash_compat.type;
73066+
73067+ return 0;
73068+}
73069+
73070+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
73071+{
73072+ compat_uptr_t ptrcompat;
73073+
73074+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
73075+ return -EFAULT;
73076+
73077+ *(void **)ptr = compat_ptr(ptrcompat);
73078+
73079+ return 0;
73080+}
73081+
73082+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
73083+{
73084+ struct acl_ip_label_compat ip_compat;
73085+
73086+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
73087+ return -EFAULT;
73088+
73089+ ip->iface = compat_ptr(ip_compat.iface);
73090+ ip->addr = ip_compat.addr;
73091+ ip->netmask = ip_compat.netmask;
73092+ ip->low = ip_compat.low;
73093+ ip->high = ip_compat.high;
73094+ ip->mode = ip_compat.mode;
73095+ ip->type = ip_compat.type;
73096+
73097+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
73098+
73099+ ip->prev = compat_ptr(ip_compat.prev);
73100+ ip->next = compat_ptr(ip_compat.next);
73101+
73102+ return 0;
73103+}
73104+
73105+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
73106+{
73107+ struct sprole_pw_compat pw_compat;
73108+
73109+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
73110+ return -EFAULT;
73111+
73112+ pw->rolename = compat_ptr(pw_compat.rolename);
73113+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
73114+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
73115+
73116+ return 0;
73117+}
73118+
73119+size_t get_gr_arg_wrapper_size_compat(void)
73120+{
73121+ return sizeof(struct gr_arg_wrapper_compat);
73122+}
73123+
73124diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
73125new file mode 100644
73126index 0000000..4008fdc
73127--- /dev/null
73128+++ b/grsecurity/gracl_fs.c
73129@@ -0,0 +1,445 @@
73130+#include <linux/kernel.h>
73131+#include <linux/sched.h>
73132+#include <linux/types.h>
73133+#include <linux/fs.h>
73134+#include <linux/file.h>
73135+#include <linux/stat.h>
73136+#include <linux/grsecurity.h>
73137+#include <linux/grinternal.h>
73138+#include <linux/gracl.h>
73139+
73140+umode_t
73141+gr_acl_umask(void)
73142+{
73143+ if (unlikely(!gr_acl_is_enabled()))
73144+ return 0;
73145+
73146+ return current->role->umask;
73147+}
73148+
73149+__u32
73150+gr_acl_handle_hidden_file(const struct dentry * dentry,
73151+ const struct vfsmount * mnt)
73152+{
73153+ __u32 mode;
73154+
73155+ if (unlikely(d_is_negative(dentry)))
73156+ return GR_FIND;
73157+
73158+ mode =
73159+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
73160+
73161+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
73162+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
73163+ return mode;
73164+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
73165+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
73166+ return 0;
73167+ } else if (unlikely(!(mode & GR_FIND)))
73168+ return 0;
73169+
73170+ return GR_FIND;
73171+}
73172+
73173+__u32
73174+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
73175+ int acc_mode)
73176+{
73177+ __u32 reqmode = GR_FIND;
73178+ __u32 mode;
73179+
73180+ if (unlikely(d_is_negative(dentry)))
73181+ return reqmode;
73182+
73183+ if (acc_mode & MAY_APPEND)
73184+ reqmode |= GR_APPEND;
73185+ else if (acc_mode & MAY_WRITE)
73186+ reqmode |= GR_WRITE;
73187+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
73188+ reqmode |= GR_READ;
73189+
73190+ mode =
73191+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
73192+ mnt);
73193+
73194+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
73195+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
73196+ reqmode & GR_READ ? " reading" : "",
73197+ reqmode & GR_WRITE ? " writing" : reqmode &
73198+ GR_APPEND ? " appending" : "");
73199+ return reqmode;
73200+ } else
73201+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
73202+ {
73203+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
73204+ reqmode & GR_READ ? " reading" : "",
73205+ reqmode & GR_WRITE ? " writing" : reqmode &
73206+ GR_APPEND ? " appending" : "");
73207+ return 0;
73208+ } else if (unlikely((mode & reqmode) != reqmode))
73209+ return 0;
73210+
73211+ return reqmode;
73212+}
73213+
73214+__u32
73215+gr_acl_handle_creat(const struct dentry * dentry,
73216+ const struct dentry * p_dentry,
73217+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
73218+ const int imode)
73219+{
73220+ __u32 reqmode = GR_WRITE | GR_CREATE;
73221+ __u32 mode;
73222+
73223+ if (acc_mode & MAY_APPEND)
73224+ reqmode |= GR_APPEND;
73225+ // if a directory was required or the directory already exists, then
73226+ // don't count this open as a read
73227+ if ((acc_mode & MAY_READ) &&
73228+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
73229+ reqmode |= GR_READ;
73230+ if ((open_flags & O_CREAT) &&
73231+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
73232+ reqmode |= GR_SETID;
73233+
73234+ mode =
73235+ gr_check_create(dentry, p_dentry, p_mnt,
73236+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
73237+
73238+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
73239+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
73240+ reqmode & GR_READ ? " reading" : "",
73241+ reqmode & GR_WRITE ? " writing" : reqmode &
73242+ GR_APPEND ? " appending" : "");
73243+ return reqmode;
73244+ } else
73245+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
73246+ {
73247+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
73248+ reqmode & GR_READ ? " reading" : "",
73249+ reqmode & GR_WRITE ? " writing" : reqmode &
73250+ GR_APPEND ? " appending" : "");
73251+ return 0;
73252+ } else if (unlikely((mode & reqmode) != reqmode))
73253+ return 0;
73254+
73255+ return reqmode;
73256+}
73257+
73258+__u32
73259+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
73260+ const int fmode)
73261+{
73262+ __u32 mode, reqmode = GR_FIND;
73263+
73264+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
73265+ reqmode |= GR_EXEC;
73266+ if (fmode & S_IWOTH)
73267+ reqmode |= GR_WRITE;
73268+ if (fmode & S_IROTH)
73269+ reqmode |= GR_READ;
73270+
73271+ mode =
73272+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
73273+ mnt);
73274+
73275+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
73276+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
73277+ reqmode & GR_READ ? " reading" : "",
73278+ reqmode & GR_WRITE ? " writing" : "",
73279+ reqmode & GR_EXEC ? " executing" : "");
73280+ return reqmode;
73281+ } else
73282+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
73283+ {
73284+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
73285+ reqmode & GR_READ ? " reading" : "",
73286+ reqmode & GR_WRITE ? " writing" : "",
73287+ reqmode & GR_EXEC ? " executing" : "");
73288+ return 0;
73289+ } else if (unlikely((mode & reqmode) != reqmode))
73290+ return 0;
73291+
73292+ return reqmode;
73293+}
73294+
73295+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
73296+{
73297+ __u32 mode;
73298+
73299+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
73300+
73301+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73302+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
73303+ return mode;
73304+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73305+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
73306+ return 0;
73307+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
73308+ return 0;
73309+
73310+ return (reqmode);
73311+}
73312+
73313+__u32
73314+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73315+{
73316+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
73317+}
73318+
73319+__u32
73320+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
73321+{
73322+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
73323+}
73324+
73325+__u32
73326+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
73327+{
73328+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
73329+}
73330+
73331+__u32
73332+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
73333+{
73334+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
73335+}
73336+
73337+__u32
73338+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
73339+ umode_t *modeptr)
73340+{
73341+ umode_t mode;
73342+
73343+ *modeptr &= ~gr_acl_umask();
73344+ mode = *modeptr;
73345+
73346+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
73347+ return 1;
73348+
73349+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
73350+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
73351+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
73352+ GR_CHMOD_ACL_MSG);
73353+ } else {
73354+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
73355+ }
73356+}
73357+
73358+__u32
73359+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
73360+{
73361+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
73362+}
73363+
73364+__u32
73365+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
73366+{
73367+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
73368+}
73369+
73370+__u32
73371+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
73372+{
73373+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
73374+}
73375+
73376+__u32
73377+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
73378+{
73379+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
73380+}
73381+
73382+__u32
73383+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
73384+{
73385+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
73386+ GR_UNIXCONNECT_ACL_MSG);
73387+}
73388+
73389+/* hardlinks require at minimum create and link permission,
73390+ any additional privilege required is based on the
73391+ privilege of the file being linked to
73392+*/
73393+__u32
73394+gr_acl_handle_link(const struct dentry * new_dentry,
73395+ const struct dentry * parent_dentry,
73396+ const struct vfsmount * parent_mnt,
73397+ const struct dentry * old_dentry,
73398+ const struct vfsmount * old_mnt, const struct filename *to)
73399+{
73400+ __u32 mode;
73401+ __u32 needmode = GR_CREATE | GR_LINK;
73402+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
73403+
73404+ mode =
73405+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
73406+ old_mnt);
73407+
73408+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
73409+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73410+ return mode;
73411+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73412+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73413+ return 0;
73414+ } else if (unlikely((mode & needmode) != needmode))
73415+ return 0;
73416+
73417+ return 1;
73418+}
73419+
73420+__u32
73421+gr_acl_handle_symlink(const struct dentry * new_dentry,
73422+ const struct dentry * parent_dentry,
73423+ const struct vfsmount * parent_mnt, const struct filename *from)
73424+{
73425+ __u32 needmode = GR_WRITE | GR_CREATE;
73426+ __u32 mode;
73427+
73428+ mode =
73429+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
73430+ GR_CREATE | GR_AUDIT_CREATE |
73431+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
73432+
73433+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
73434+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73435+ return mode;
73436+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73437+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73438+ return 0;
73439+ } else if (unlikely((mode & needmode) != needmode))
73440+ return 0;
73441+
73442+ return (GR_WRITE | GR_CREATE);
73443+}
73444+
73445+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)
73446+{
73447+ __u32 mode;
73448+
73449+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
73450+
73451+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73452+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
73453+ return mode;
73454+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73455+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
73456+ return 0;
73457+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
73458+ return 0;
73459+
73460+ return (reqmode);
73461+}
73462+
73463+__u32
73464+gr_acl_handle_mknod(const struct dentry * new_dentry,
73465+ const struct dentry * parent_dentry,
73466+ const struct vfsmount * parent_mnt,
73467+ const int mode)
73468+{
73469+ __u32 reqmode = GR_WRITE | GR_CREATE;
73470+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
73471+ reqmode |= GR_SETID;
73472+
73473+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73474+ reqmode, GR_MKNOD_ACL_MSG);
73475+}
73476+
73477+__u32
73478+gr_acl_handle_mkdir(const struct dentry *new_dentry,
73479+ const struct dentry *parent_dentry,
73480+ const struct vfsmount *parent_mnt)
73481+{
73482+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73483+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
73484+}
73485+
73486+#define RENAME_CHECK_SUCCESS(old, new) \
73487+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
73488+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
73489+
73490+int
73491+gr_acl_handle_rename(struct dentry *new_dentry,
73492+ struct dentry *parent_dentry,
73493+ const struct vfsmount *parent_mnt,
73494+ struct dentry *old_dentry,
73495+ struct inode *old_parent_inode,
73496+ struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
73497+{
73498+ __u32 comp1, comp2;
73499+ int error = 0;
73500+
73501+ if (unlikely(!gr_acl_is_enabled()))
73502+ return 0;
73503+
73504+ if (flags & RENAME_EXCHANGE) {
73505+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73506+ GR_AUDIT_READ | GR_AUDIT_WRITE |
73507+ GR_SUPPRESS, parent_mnt);
73508+ comp2 =
73509+ gr_search_file(old_dentry,
73510+ GR_READ | GR_WRITE | GR_AUDIT_READ |
73511+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73512+ } else if (d_is_negative(new_dentry)) {
73513+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
73514+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
73515+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
73516+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
73517+ GR_DELETE | GR_AUDIT_DELETE |
73518+ GR_AUDIT_READ | GR_AUDIT_WRITE |
73519+ GR_SUPPRESS, old_mnt);
73520+ } else {
73521+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73522+ GR_CREATE | GR_DELETE |
73523+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
73524+ GR_AUDIT_READ | GR_AUDIT_WRITE |
73525+ GR_SUPPRESS, parent_mnt);
73526+ comp2 =
73527+ gr_search_file(old_dentry,
73528+ GR_READ | GR_WRITE | GR_AUDIT_READ |
73529+ GR_DELETE | GR_AUDIT_DELETE |
73530+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73531+ }
73532+
73533+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
73534+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
73535+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73536+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
73537+ && !(comp2 & GR_SUPPRESS)) {
73538+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73539+ error = -EACCES;
73540+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
73541+ error = -EACCES;
73542+
73543+ return error;
73544+}
73545+
73546+void
73547+gr_acl_handle_exit(void)
73548+{
73549+ u16 id;
73550+ char *rolename;
73551+
73552+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
73553+ !(current->role->roletype & GR_ROLE_PERSIST))) {
73554+ id = current->acl_role_id;
73555+ rolename = current->role->rolename;
73556+ gr_set_acls(1);
73557+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
73558+ }
73559+
73560+ gr_put_exec_file(current);
73561+ return;
73562+}
73563+
73564+int
73565+gr_acl_handle_procpidmem(const struct task_struct *task)
73566+{
73567+ if (unlikely(!gr_acl_is_enabled()))
73568+ return 0;
73569+
73570+ if (task != current && task->acl->mode & GR_PROTPROCFD)
73571+ return -EACCES;
73572+
73573+ return 0;
73574+}
73575diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
73576new file mode 100644
73577index 0000000..f056b81
73578--- /dev/null
73579+++ b/grsecurity/gracl_ip.c
73580@@ -0,0 +1,386 @@
73581+#include <linux/kernel.h>
73582+#include <asm/uaccess.h>
73583+#include <asm/errno.h>
73584+#include <net/sock.h>
73585+#include <linux/file.h>
73586+#include <linux/fs.h>
73587+#include <linux/net.h>
73588+#include <linux/in.h>
73589+#include <linux/skbuff.h>
73590+#include <linux/ip.h>
73591+#include <linux/udp.h>
73592+#include <linux/types.h>
73593+#include <linux/sched.h>
73594+#include <linux/netdevice.h>
73595+#include <linux/inetdevice.h>
73596+#include <linux/gracl.h>
73597+#include <linux/grsecurity.h>
73598+#include <linux/grinternal.h>
73599+
73600+#define GR_BIND 0x01
73601+#define GR_CONNECT 0x02
73602+#define GR_INVERT 0x04
73603+#define GR_BINDOVERRIDE 0x08
73604+#define GR_CONNECTOVERRIDE 0x10
73605+#define GR_SOCK_FAMILY 0x20
73606+
73607+static const char * gr_protocols[IPPROTO_MAX] = {
73608+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
73609+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
73610+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
73611+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
73612+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
73613+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
73614+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
73615+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
73616+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
73617+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
73618+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
73619+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
73620+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
73621+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
73622+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
73623+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
73624+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
73625+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
73626+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
73627+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
73628+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
73629+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
73630+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
73631+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
73632+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
73633+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
73634+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
73635+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
73636+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
73637+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
73638+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
73639+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
73640+ };
73641+
73642+static const char * gr_socktypes[SOCK_MAX] = {
73643+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
73644+ "unknown:7", "unknown:8", "unknown:9", "packet"
73645+ };
73646+
73647+static const char * gr_sockfamilies[AF_MAX+1] = {
73648+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
73649+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
73650+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
73651+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
73652+ };
73653+
73654+const char *
73655+gr_proto_to_name(unsigned char proto)
73656+{
73657+ return gr_protocols[proto];
73658+}
73659+
73660+const char *
73661+gr_socktype_to_name(unsigned char type)
73662+{
73663+ return gr_socktypes[type];
73664+}
73665+
73666+const char *
73667+gr_sockfamily_to_name(unsigned char family)
73668+{
73669+ return gr_sockfamilies[family];
73670+}
73671+
73672+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
73673+
73674+int
73675+gr_search_socket(const int domain, const int type, const int protocol)
73676+{
73677+ struct acl_subject_label *curr;
73678+ const struct cred *cred = current_cred();
73679+
73680+ if (unlikely(!gr_acl_is_enabled()))
73681+ goto exit;
73682+
73683+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
73684+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
73685+ goto exit; // let the kernel handle it
73686+
73687+ curr = current->acl;
73688+
73689+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
73690+ /* the family is allowed, if this is PF_INET allow it only if
73691+ the extra sock type/protocol checks pass */
73692+ if (domain == PF_INET)
73693+ goto inet_check;
73694+ goto exit;
73695+ } else {
73696+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73697+ __u32 fakeip = 0;
73698+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73699+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
73700+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
73701+ gr_to_filename(current->exec_file->f_path.dentry,
73702+ current->exec_file->f_path.mnt) :
73703+ curr->filename, curr->filename,
73704+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
73705+ &current->signal->saved_ip);
73706+ goto exit;
73707+ }
73708+ goto exit_fail;
73709+ }
73710+
73711+inet_check:
73712+ /* the rest of this checking is for IPv4 only */
73713+ if (!curr->ips)
73714+ goto exit;
73715+
73716+ if ((curr->ip_type & (1U << type)) &&
73717+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
73718+ goto exit;
73719+
73720+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73721+ /* we don't place acls on raw sockets , and sometimes
73722+ dgram/ip sockets are opened for ioctl and not
73723+ bind/connect, so we'll fake a bind learn log */
73724+ if (type == SOCK_RAW || type == SOCK_PACKET) {
73725+ __u32 fakeip = 0;
73726+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73727+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
73728+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
73729+ gr_to_filename(current->exec_file->f_path.dentry,
73730+ current->exec_file->f_path.mnt) :
73731+ curr->filename, curr->filename,
73732+ &fakeip, 0, type,
73733+ protocol, GR_CONNECT, &current->signal->saved_ip);
73734+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
73735+ __u32 fakeip = 0;
73736+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73737+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
73738+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
73739+ gr_to_filename(current->exec_file->f_path.dentry,
73740+ current->exec_file->f_path.mnt) :
73741+ curr->filename, curr->filename,
73742+ &fakeip, 0, type,
73743+ protocol, GR_BIND, &current->signal->saved_ip);
73744+ }
73745+ /* we'll log when they use connect or bind */
73746+ goto exit;
73747+ }
73748+
73749+exit_fail:
73750+ if (domain == PF_INET)
73751+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
73752+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
73753+ else if (rcu_access_pointer(net_families[domain]) != NULL)
73754+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
73755+ gr_socktype_to_name(type), protocol);
73756+
73757+ return 0;
73758+exit:
73759+ return 1;
73760+}
73761+
73762+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)
73763+{
73764+ if ((ip->mode & mode) &&
73765+ (ip_port >= ip->low) &&
73766+ (ip_port <= ip->high) &&
73767+ ((ntohl(ip_addr) & our_netmask) ==
73768+ (ntohl(our_addr) & our_netmask))
73769+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
73770+ && (ip->type & (1U << type))) {
73771+ if (ip->mode & GR_INVERT)
73772+ return 2; // specifically denied
73773+ else
73774+ return 1; // allowed
73775+ }
73776+
73777+ return 0; // not specifically allowed, may continue parsing
73778+}
73779+
73780+static int
73781+gr_search_connectbind(const int full_mode, struct sock *sk,
73782+ struct sockaddr_in *addr, const int type)
73783+{
73784+ char iface[IFNAMSIZ] = {0};
73785+ struct acl_subject_label *curr;
73786+ struct acl_ip_label *ip;
73787+ struct inet_sock *isk;
73788+ struct net_device *dev;
73789+ struct in_device *idev;
73790+ unsigned long i;
73791+ int ret;
73792+ int mode = full_mode & (GR_BIND | GR_CONNECT);
73793+ __u32 ip_addr = 0;
73794+ __u32 our_addr;
73795+ __u32 our_netmask;
73796+ char *p;
73797+ __u16 ip_port = 0;
73798+ const struct cred *cred = current_cred();
73799+
73800+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
73801+ return 0;
73802+
73803+ curr = current->acl;
73804+ isk = inet_sk(sk);
73805+
73806+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
73807+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
73808+ addr->sin_addr.s_addr = curr->inaddr_any_override;
73809+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
73810+ struct sockaddr_in saddr;
73811+ int err;
73812+
73813+ saddr.sin_family = AF_INET;
73814+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
73815+ saddr.sin_port = isk->inet_sport;
73816+
73817+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73818+ if (err)
73819+ return err;
73820+
73821+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73822+ if (err)
73823+ return err;
73824+ }
73825+
73826+ if (!curr->ips)
73827+ return 0;
73828+
73829+ ip_addr = addr->sin_addr.s_addr;
73830+ ip_port = ntohs(addr->sin_port);
73831+
73832+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73833+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73834+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
73835+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
73836+ gr_to_filename(current->exec_file->f_path.dentry,
73837+ current->exec_file->f_path.mnt) :
73838+ curr->filename, curr->filename,
73839+ &ip_addr, ip_port, type,
73840+ sk->sk_protocol, mode, &current->signal->saved_ip);
73841+ return 0;
73842+ }
73843+
73844+ for (i = 0; i < curr->ip_num; i++) {
73845+ ip = *(curr->ips + i);
73846+ if (ip->iface != NULL) {
73847+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
73848+ p = strchr(iface, ':');
73849+ if (p != NULL)
73850+ *p = '\0';
73851+ dev = dev_get_by_name(sock_net(sk), iface);
73852+ if (dev == NULL)
73853+ continue;
73854+ idev = in_dev_get(dev);
73855+ if (idev == NULL) {
73856+ dev_put(dev);
73857+ continue;
73858+ }
73859+ rcu_read_lock();
73860+ for_ifa(idev) {
73861+ if (!strcmp(ip->iface, ifa->ifa_label)) {
73862+ our_addr = ifa->ifa_address;
73863+ our_netmask = 0xffffffff;
73864+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73865+ if (ret == 1) {
73866+ rcu_read_unlock();
73867+ in_dev_put(idev);
73868+ dev_put(dev);
73869+ return 0;
73870+ } else if (ret == 2) {
73871+ rcu_read_unlock();
73872+ in_dev_put(idev);
73873+ dev_put(dev);
73874+ goto denied;
73875+ }
73876+ }
73877+ } endfor_ifa(idev);
73878+ rcu_read_unlock();
73879+ in_dev_put(idev);
73880+ dev_put(dev);
73881+ } else {
73882+ our_addr = ip->addr;
73883+ our_netmask = ip->netmask;
73884+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73885+ if (ret == 1)
73886+ return 0;
73887+ else if (ret == 2)
73888+ goto denied;
73889+ }
73890+ }
73891+
73892+denied:
73893+ if (mode == GR_BIND)
73894+ 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));
73895+ else if (mode == GR_CONNECT)
73896+ 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));
73897+
73898+ return -EACCES;
73899+}
73900+
73901+int
73902+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
73903+{
73904+ /* always allow disconnection of dgram sockets with connect */
73905+ if (addr->sin_family == AF_UNSPEC)
73906+ return 0;
73907+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
73908+}
73909+
73910+int
73911+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
73912+{
73913+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
73914+}
73915+
73916+int gr_search_listen(struct socket *sock)
73917+{
73918+ struct sock *sk = sock->sk;
73919+ struct sockaddr_in addr;
73920+
73921+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73922+ addr.sin_port = inet_sk(sk)->inet_sport;
73923+
73924+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73925+}
73926+
73927+int gr_search_accept(struct socket *sock)
73928+{
73929+ struct sock *sk = sock->sk;
73930+ struct sockaddr_in addr;
73931+
73932+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73933+ addr.sin_port = inet_sk(sk)->inet_sport;
73934+
73935+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73936+}
73937+
73938+int
73939+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
73940+{
73941+ if (addr)
73942+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
73943+ else {
73944+ struct sockaddr_in sin;
73945+ const struct inet_sock *inet = inet_sk(sk);
73946+
73947+ sin.sin_addr.s_addr = inet->inet_daddr;
73948+ sin.sin_port = inet->inet_dport;
73949+
73950+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73951+ }
73952+}
73953+
73954+int
73955+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
73956+{
73957+ struct sockaddr_in sin;
73958+
73959+ if (unlikely(skb->len < sizeof (struct udphdr)))
73960+ return 0; // skip this packet
73961+
73962+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
73963+ sin.sin_port = udp_hdr(skb)->source;
73964+
73965+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73966+}
73967diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
73968new file mode 100644
73969index 0000000..25f54ef
73970--- /dev/null
73971+++ b/grsecurity/gracl_learn.c
73972@@ -0,0 +1,207 @@
73973+#include <linux/kernel.h>
73974+#include <linux/mm.h>
73975+#include <linux/sched.h>
73976+#include <linux/poll.h>
73977+#include <linux/string.h>
73978+#include <linux/file.h>
73979+#include <linux/types.h>
73980+#include <linux/vmalloc.h>
73981+#include <linux/grinternal.h>
73982+
73983+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
73984+ size_t count, loff_t *ppos);
73985+extern int gr_acl_is_enabled(void);
73986+
73987+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
73988+static int gr_learn_attached;
73989+
73990+/* use a 512k buffer */
73991+#define LEARN_BUFFER_SIZE (512 * 1024)
73992+
73993+static DEFINE_SPINLOCK(gr_learn_lock);
73994+static DEFINE_MUTEX(gr_learn_user_mutex);
73995+
73996+/* we need to maintain two buffers, so that the kernel context of grlearn
73997+ uses a semaphore around the userspace copying, and the other kernel contexts
73998+ use a spinlock when copying into the buffer, since they cannot sleep
73999+*/
74000+static char *learn_buffer;
74001+static char *learn_buffer_user;
74002+static int learn_buffer_len;
74003+static int learn_buffer_user_len;
74004+
74005+static ssize_t
74006+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
74007+{
74008+ DECLARE_WAITQUEUE(wait, current);
74009+ ssize_t retval = 0;
74010+
74011+ add_wait_queue(&learn_wait, &wait);
74012+ set_current_state(TASK_INTERRUPTIBLE);
74013+ do {
74014+ mutex_lock(&gr_learn_user_mutex);
74015+ spin_lock(&gr_learn_lock);
74016+ if (learn_buffer_len)
74017+ break;
74018+ spin_unlock(&gr_learn_lock);
74019+ mutex_unlock(&gr_learn_user_mutex);
74020+ if (file->f_flags & O_NONBLOCK) {
74021+ retval = -EAGAIN;
74022+ goto out;
74023+ }
74024+ if (signal_pending(current)) {
74025+ retval = -ERESTARTSYS;
74026+ goto out;
74027+ }
74028+
74029+ schedule();
74030+ } while (1);
74031+
74032+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
74033+ learn_buffer_user_len = learn_buffer_len;
74034+ retval = learn_buffer_len;
74035+ learn_buffer_len = 0;
74036+
74037+ spin_unlock(&gr_learn_lock);
74038+
74039+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
74040+ retval = -EFAULT;
74041+
74042+ mutex_unlock(&gr_learn_user_mutex);
74043+out:
74044+ set_current_state(TASK_RUNNING);
74045+ remove_wait_queue(&learn_wait, &wait);
74046+ return retval;
74047+}
74048+
74049+static unsigned int
74050+poll_learn(struct file * file, poll_table * wait)
74051+{
74052+ poll_wait(file, &learn_wait, wait);
74053+
74054+ if (learn_buffer_len)
74055+ return (POLLIN | POLLRDNORM);
74056+
74057+ return 0;
74058+}
74059+
74060+void
74061+gr_clear_learn_entries(void)
74062+{
74063+ char *tmp;
74064+
74065+ mutex_lock(&gr_learn_user_mutex);
74066+ spin_lock(&gr_learn_lock);
74067+ tmp = learn_buffer;
74068+ learn_buffer = NULL;
74069+ spin_unlock(&gr_learn_lock);
74070+ if (tmp)
74071+ vfree(tmp);
74072+ if (learn_buffer_user != NULL) {
74073+ vfree(learn_buffer_user);
74074+ learn_buffer_user = NULL;
74075+ }
74076+ learn_buffer_len = 0;
74077+ mutex_unlock(&gr_learn_user_mutex);
74078+
74079+ return;
74080+}
74081+
74082+void
74083+gr_add_learn_entry(const char *fmt, ...)
74084+{
74085+ va_list args;
74086+ unsigned int len;
74087+
74088+ if (!gr_learn_attached)
74089+ return;
74090+
74091+ spin_lock(&gr_learn_lock);
74092+
74093+ /* leave a gap at the end so we know when it's "full" but don't have to
74094+ compute the exact length of the string we're trying to append
74095+ */
74096+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
74097+ spin_unlock(&gr_learn_lock);
74098+ wake_up_interruptible(&learn_wait);
74099+ return;
74100+ }
74101+ if (learn_buffer == NULL) {
74102+ spin_unlock(&gr_learn_lock);
74103+ return;
74104+ }
74105+
74106+ va_start(args, fmt);
74107+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
74108+ va_end(args);
74109+
74110+ learn_buffer_len += len + 1;
74111+
74112+ spin_unlock(&gr_learn_lock);
74113+ wake_up_interruptible(&learn_wait);
74114+
74115+ return;
74116+}
74117+
74118+static int
74119+open_learn(struct inode *inode, struct file *file)
74120+{
74121+ if (file->f_mode & FMODE_READ && gr_learn_attached)
74122+ return -EBUSY;
74123+ if (file->f_mode & FMODE_READ) {
74124+ int retval = 0;
74125+ mutex_lock(&gr_learn_user_mutex);
74126+ if (learn_buffer == NULL)
74127+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
74128+ if (learn_buffer_user == NULL)
74129+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
74130+ if (learn_buffer == NULL) {
74131+ retval = -ENOMEM;
74132+ goto out_error;
74133+ }
74134+ if (learn_buffer_user == NULL) {
74135+ retval = -ENOMEM;
74136+ goto out_error;
74137+ }
74138+ learn_buffer_len = 0;
74139+ learn_buffer_user_len = 0;
74140+ gr_learn_attached = 1;
74141+out_error:
74142+ mutex_unlock(&gr_learn_user_mutex);
74143+ return retval;
74144+ }
74145+ return 0;
74146+}
74147+
74148+static int
74149+close_learn(struct inode *inode, struct file *file)
74150+{
74151+ if (file->f_mode & FMODE_READ) {
74152+ char *tmp = NULL;
74153+ mutex_lock(&gr_learn_user_mutex);
74154+ spin_lock(&gr_learn_lock);
74155+ tmp = learn_buffer;
74156+ learn_buffer = NULL;
74157+ spin_unlock(&gr_learn_lock);
74158+ if (tmp)
74159+ vfree(tmp);
74160+ if (learn_buffer_user != NULL) {
74161+ vfree(learn_buffer_user);
74162+ learn_buffer_user = NULL;
74163+ }
74164+ learn_buffer_len = 0;
74165+ learn_buffer_user_len = 0;
74166+ gr_learn_attached = 0;
74167+ mutex_unlock(&gr_learn_user_mutex);
74168+ }
74169+
74170+ return 0;
74171+}
74172+
74173+const struct file_operations grsec_fops = {
74174+ .read = read_learn,
74175+ .write = write_grsec_handler,
74176+ .open = open_learn,
74177+ .release = close_learn,
74178+ .poll = poll_learn,
74179+};
74180diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
74181new file mode 100644
74182index 0000000..3f8ade0
74183--- /dev/null
74184+++ b/grsecurity/gracl_policy.c
74185@@ -0,0 +1,1782 @@
74186+#include <linux/kernel.h>
74187+#include <linux/module.h>
74188+#include <linux/sched.h>
74189+#include <linux/mm.h>
74190+#include <linux/file.h>
74191+#include <linux/fs.h>
74192+#include <linux/namei.h>
74193+#include <linux/mount.h>
74194+#include <linux/tty.h>
74195+#include <linux/proc_fs.h>
74196+#include <linux/lglock.h>
74197+#include <linux/slab.h>
74198+#include <linux/vmalloc.h>
74199+#include <linux/types.h>
74200+#include <linux/sysctl.h>
74201+#include <linux/netdevice.h>
74202+#include <linux/ptrace.h>
74203+#include <linux/gracl.h>
74204+#include <linux/gralloc.h>
74205+#include <linux/security.h>
74206+#include <linux/grinternal.h>
74207+#include <linux/pid_namespace.h>
74208+#include <linux/stop_machine.h>
74209+#include <linux/fdtable.h>
74210+#include <linux/percpu.h>
74211+#include <linux/lglock.h>
74212+#include <linux/hugetlb.h>
74213+#include <linux/posix-timers.h>
74214+#include "../fs/mount.h"
74215+
74216+#include <asm/uaccess.h>
74217+#include <asm/errno.h>
74218+#include <asm/mman.h>
74219+
74220+extern struct gr_policy_state *polstate;
74221+
74222+#define FOR_EACH_ROLE_START(role) \
74223+ role = polstate->role_list; \
74224+ while (role) {
74225+
74226+#define FOR_EACH_ROLE_END(role) \
74227+ role = role->prev; \
74228+ }
74229+
74230+struct path gr_real_root;
74231+
74232+extern struct gr_alloc_state *current_alloc_state;
74233+
74234+u16 acl_sp_role_value;
74235+
74236+static DEFINE_MUTEX(gr_dev_mutex);
74237+
74238+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
74239+extern void gr_clear_learn_entries(void);
74240+
74241+struct gr_arg *gr_usermode __read_only;
74242+unsigned char *gr_system_salt __read_only;
74243+unsigned char *gr_system_sum __read_only;
74244+
74245+static unsigned int gr_auth_attempts = 0;
74246+static unsigned long gr_auth_expires = 0UL;
74247+
74248+struct acl_object_label *fakefs_obj_rw;
74249+struct acl_object_label *fakefs_obj_rwx;
74250+
74251+extern int gr_init_uidset(void);
74252+extern void gr_free_uidset(void);
74253+extern void gr_remove_uid(uid_t uid);
74254+extern int gr_find_uid(uid_t uid);
74255+
74256+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
74257+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
74258+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
74259+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
74260+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);
74261+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
74262+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
74263+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
74264+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
74265+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
74266+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
74267+extern void assign_special_role(const char *rolename);
74268+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
74269+extern int gr_rbac_disable(void *unused);
74270+extern void gr_enable_rbac_system(void);
74271+
74272+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
74273+{
74274+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
74275+ return -EFAULT;
74276+
74277+ return 0;
74278+}
74279+
74280+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
74281+{
74282+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
74283+ return -EFAULT;
74284+
74285+ return 0;
74286+}
74287+
74288+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
74289+{
74290+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
74291+ return -EFAULT;
74292+
74293+ return 0;
74294+}
74295+
74296+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
74297+{
74298+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
74299+ return -EFAULT;
74300+
74301+ return 0;
74302+}
74303+
74304+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
74305+{
74306+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
74307+ return -EFAULT;
74308+
74309+ return 0;
74310+}
74311+
74312+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
74313+{
74314+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
74315+ return -EFAULT;
74316+
74317+ return 0;
74318+}
74319+
74320+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
74321+{
74322+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
74323+ return -EFAULT;
74324+
74325+ return 0;
74326+}
74327+
74328+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
74329+{
74330+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
74331+ return -EFAULT;
74332+
74333+ return 0;
74334+}
74335+
74336+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
74337+{
74338+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
74339+ return -EFAULT;
74340+
74341+ return 0;
74342+}
74343+
74344+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
74345+{
74346+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
74347+ return -EFAULT;
74348+
74349+ if (((uwrap->version != GRSECURITY_VERSION) &&
74350+ (uwrap->version != 0x2901)) ||
74351+ (uwrap->size != sizeof(struct gr_arg)))
74352+ return -EINVAL;
74353+
74354+ return 0;
74355+}
74356+
74357+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
74358+{
74359+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
74360+ return -EFAULT;
74361+
74362+ return 0;
74363+}
74364+
74365+static size_t get_gr_arg_wrapper_size_normal(void)
74366+{
74367+ return sizeof(struct gr_arg_wrapper);
74368+}
74369+
74370+#ifdef CONFIG_COMPAT
74371+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
74372+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
74373+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
74374+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
74375+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
74376+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
74377+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
74378+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
74379+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
74380+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
74381+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
74382+extern size_t get_gr_arg_wrapper_size_compat(void);
74383+
74384+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
74385+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
74386+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
74387+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
74388+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
74389+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
74390+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
74391+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
74392+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
74393+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
74394+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
74395+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
74396+
74397+#else
74398+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
74399+#define copy_gr_arg copy_gr_arg_normal
74400+#define copy_gr_hash_struct copy_gr_hash_struct_normal
74401+#define copy_acl_object_label copy_acl_object_label_normal
74402+#define copy_acl_subject_label copy_acl_subject_label_normal
74403+#define copy_acl_role_label copy_acl_role_label_normal
74404+#define copy_acl_ip_label copy_acl_ip_label_normal
74405+#define copy_pointer_from_array copy_pointer_from_array_normal
74406+#define copy_sprole_pw copy_sprole_pw_normal
74407+#define copy_role_transition copy_role_transition_normal
74408+#define copy_role_allowed_ip copy_role_allowed_ip_normal
74409+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
74410+#endif
74411+
74412+static struct acl_subject_label *
74413+lookup_subject_map(const struct acl_subject_label *userp)
74414+{
74415+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
74416+ struct subject_map *match;
74417+
74418+ match = polstate->subj_map_set.s_hash[index];
74419+
74420+ while (match && match->user != userp)
74421+ match = match->next;
74422+
74423+ if (match != NULL)
74424+ return match->kernel;
74425+ else
74426+ return NULL;
74427+}
74428+
74429+static void
74430+insert_subj_map_entry(struct subject_map *subjmap)
74431+{
74432+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
74433+ struct subject_map **curr;
74434+
74435+ subjmap->prev = NULL;
74436+
74437+ curr = &polstate->subj_map_set.s_hash[index];
74438+ if (*curr != NULL)
74439+ (*curr)->prev = subjmap;
74440+
74441+ subjmap->next = *curr;
74442+ *curr = subjmap;
74443+
74444+ return;
74445+}
74446+
74447+static void
74448+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
74449+{
74450+ unsigned int index =
74451+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
74452+ struct acl_role_label **curr;
74453+ struct acl_role_label *tmp, *tmp2;
74454+
74455+ curr = &polstate->acl_role_set.r_hash[index];
74456+
74457+ /* simple case, slot is empty, just set it to our role */
74458+ if (*curr == NULL) {
74459+ *curr = role;
74460+ } else {
74461+ /* example:
74462+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
74463+ 2 -> 3
74464+ */
74465+ /* first check to see if we can already be reached via this slot */
74466+ tmp = *curr;
74467+ while (tmp && tmp != role)
74468+ tmp = tmp->next;
74469+ if (tmp == role) {
74470+ /* we don't need to add ourselves to this slot's chain */
74471+ return;
74472+ }
74473+ /* we need to add ourselves to this chain, two cases */
74474+ if (role->next == NULL) {
74475+ /* simple case, append the current chain to our role */
74476+ role->next = *curr;
74477+ *curr = role;
74478+ } else {
74479+ /* 1 -> 2 -> 3 -> 4
74480+ 2 -> 3 -> 4
74481+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
74482+ */
74483+ /* trickier case: walk our role's chain until we find
74484+ the role for the start of the current slot's chain */
74485+ tmp = role;
74486+ tmp2 = *curr;
74487+ while (tmp->next && tmp->next != tmp2)
74488+ tmp = tmp->next;
74489+ if (tmp->next == tmp2) {
74490+ /* from example above, we found 3, so just
74491+ replace this slot's chain with ours */
74492+ *curr = role;
74493+ } else {
74494+ /* we didn't find a subset of our role's chain
74495+ in the current slot's chain, so append their
74496+ chain to ours, and set us as the first role in
74497+ the slot's chain
74498+
74499+ we could fold this case with the case above,
74500+ but making it explicit for clarity
74501+ */
74502+ tmp->next = tmp2;
74503+ *curr = role;
74504+ }
74505+ }
74506+ }
74507+
74508+ return;
74509+}
74510+
74511+static void
74512+insert_acl_role_label(struct acl_role_label *role)
74513+{
74514+ int i;
74515+
74516+ if (polstate->role_list == NULL) {
74517+ polstate->role_list = role;
74518+ role->prev = NULL;
74519+ } else {
74520+ role->prev = polstate->role_list;
74521+ polstate->role_list = role;
74522+ }
74523+
74524+ /* used for hash chains */
74525+ role->next = NULL;
74526+
74527+ if (role->roletype & GR_ROLE_DOMAIN) {
74528+ for (i = 0; i < role->domain_child_num; i++)
74529+ __insert_acl_role_label(role, role->domain_children[i]);
74530+ } else
74531+ __insert_acl_role_label(role, role->uidgid);
74532+}
74533+
74534+static int
74535+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
74536+{
74537+ struct name_entry **curr, *nentry;
74538+ struct inodev_entry *ientry;
74539+ unsigned int len = strlen(name);
74540+ unsigned int key = full_name_hash(name, len);
74541+ unsigned int index = key % polstate->name_set.n_size;
74542+
74543+ curr = &polstate->name_set.n_hash[index];
74544+
74545+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
74546+ curr = &((*curr)->next);
74547+
74548+ if (*curr != NULL)
74549+ return 1;
74550+
74551+ nentry = acl_alloc(sizeof (struct name_entry));
74552+ if (nentry == NULL)
74553+ return 0;
74554+ ientry = acl_alloc(sizeof (struct inodev_entry));
74555+ if (ientry == NULL)
74556+ return 0;
74557+ ientry->nentry = nentry;
74558+
74559+ nentry->key = key;
74560+ nentry->name = name;
74561+ nentry->inode = inode;
74562+ nentry->device = device;
74563+ nentry->len = len;
74564+ nentry->deleted = deleted;
74565+
74566+ nentry->prev = NULL;
74567+ curr = &polstate->name_set.n_hash[index];
74568+ if (*curr != NULL)
74569+ (*curr)->prev = nentry;
74570+ nentry->next = *curr;
74571+ *curr = nentry;
74572+
74573+ /* insert us into the table searchable by inode/dev */
74574+ __insert_inodev_entry(polstate, ientry);
74575+
74576+ return 1;
74577+}
74578+
74579+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
74580+
74581+static void *
74582+create_table(__u32 * len, int elementsize)
74583+{
74584+ unsigned int table_sizes[] = {
74585+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
74586+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
74587+ 4194301, 8388593, 16777213, 33554393, 67108859
74588+ };
74589+ void *newtable = NULL;
74590+ unsigned int pwr = 0;
74591+
74592+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
74593+ table_sizes[pwr] <= *len)
74594+ pwr++;
74595+
74596+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
74597+ return newtable;
74598+
74599+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
74600+ newtable =
74601+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
74602+ else
74603+ newtable = vmalloc(table_sizes[pwr] * elementsize);
74604+
74605+ *len = table_sizes[pwr];
74606+
74607+ return newtable;
74608+}
74609+
74610+static int
74611+init_variables(const struct gr_arg *arg, bool reload)
74612+{
74613+ struct task_struct *reaper = init_pid_ns.child_reaper;
74614+ unsigned int stacksize;
74615+
74616+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
74617+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
74618+ polstate->name_set.n_size = arg->role_db.num_objects;
74619+ polstate->inodev_set.i_size = arg->role_db.num_objects;
74620+
74621+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
74622+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
74623+ return 1;
74624+
74625+ if (!reload) {
74626+ if (!gr_init_uidset())
74627+ return 1;
74628+ }
74629+
74630+ /* set up the stack that holds allocation info */
74631+
74632+ stacksize = arg->role_db.num_pointers + 5;
74633+
74634+ if (!acl_alloc_stack_init(stacksize))
74635+ return 1;
74636+
74637+ if (!reload) {
74638+ /* grab reference for the real root dentry and vfsmount */
74639+ get_fs_root(reaper->fs, &gr_real_root);
74640+
74641+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74642+ 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);
74643+#endif
74644+
74645+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74646+ if (fakefs_obj_rw == NULL)
74647+ return 1;
74648+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
74649+
74650+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74651+ if (fakefs_obj_rwx == NULL)
74652+ return 1;
74653+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
74654+ }
74655+
74656+ polstate->subj_map_set.s_hash =
74657+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
74658+ polstate->acl_role_set.r_hash =
74659+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
74660+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
74661+ polstate->inodev_set.i_hash =
74662+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
74663+
74664+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
74665+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
74666+ return 1;
74667+
74668+ memset(polstate->subj_map_set.s_hash, 0,
74669+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
74670+ memset(polstate->acl_role_set.r_hash, 0,
74671+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
74672+ memset(polstate->name_set.n_hash, 0,
74673+ sizeof (struct name_entry *) * polstate->name_set.n_size);
74674+ memset(polstate->inodev_set.i_hash, 0,
74675+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
74676+
74677+ return 0;
74678+}
74679+
74680+/* free information not needed after startup
74681+ currently contains user->kernel pointer mappings for subjects
74682+*/
74683+
74684+static void
74685+free_init_variables(void)
74686+{
74687+ __u32 i;
74688+
74689+ if (polstate->subj_map_set.s_hash) {
74690+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
74691+ if (polstate->subj_map_set.s_hash[i]) {
74692+ kfree(polstate->subj_map_set.s_hash[i]);
74693+ polstate->subj_map_set.s_hash[i] = NULL;
74694+ }
74695+ }
74696+
74697+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
74698+ PAGE_SIZE)
74699+ kfree(polstate->subj_map_set.s_hash);
74700+ else
74701+ vfree(polstate->subj_map_set.s_hash);
74702+ }
74703+
74704+ return;
74705+}
74706+
74707+static void
74708+free_variables(bool reload)
74709+{
74710+ struct acl_subject_label *s;
74711+ struct acl_role_label *r;
74712+ struct task_struct *task, *task2;
74713+ unsigned int x;
74714+
74715+ if (!reload) {
74716+ gr_clear_learn_entries();
74717+
74718+ read_lock(&tasklist_lock);
74719+ do_each_thread(task2, task) {
74720+ task->acl_sp_role = 0;
74721+ task->acl_role_id = 0;
74722+ task->inherited = 0;
74723+ task->acl = NULL;
74724+ task->role = NULL;
74725+ } while_each_thread(task2, task);
74726+ read_unlock(&tasklist_lock);
74727+
74728+ kfree(fakefs_obj_rw);
74729+ fakefs_obj_rw = NULL;
74730+ kfree(fakefs_obj_rwx);
74731+ fakefs_obj_rwx = NULL;
74732+
74733+ /* release the reference to the real root dentry and vfsmount */
74734+ path_put(&gr_real_root);
74735+ memset(&gr_real_root, 0, sizeof(gr_real_root));
74736+ }
74737+
74738+ /* free all object hash tables */
74739+
74740+ FOR_EACH_ROLE_START(r)
74741+ if (r->subj_hash == NULL)
74742+ goto next_role;
74743+ FOR_EACH_SUBJECT_START(r, s, x)
74744+ if (s->obj_hash == NULL)
74745+ break;
74746+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74747+ kfree(s->obj_hash);
74748+ else
74749+ vfree(s->obj_hash);
74750+ FOR_EACH_SUBJECT_END(s, x)
74751+ FOR_EACH_NESTED_SUBJECT_START(r, s)
74752+ if (s->obj_hash == NULL)
74753+ break;
74754+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74755+ kfree(s->obj_hash);
74756+ else
74757+ vfree(s->obj_hash);
74758+ FOR_EACH_NESTED_SUBJECT_END(s)
74759+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
74760+ kfree(r->subj_hash);
74761+ else
74762+ vfree(r->subj_hash);
74763+ r->subj_hash = NULL;
74764+next_role:
74765+ FOR_EACH_ROLE_END(r)
74766+
74767+ acl_free_all();
74768+
74769+ if (polstate->acl_role_set.r_hash) {
74770+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
74771+ PAGE_SIZE)
74772+ kfree(polstate->acl_role_set.r_hash);
74773+ else
74774+ vfree(polstate->acl_role_set.r_hash);
74775+ }
74776+ if (polstate->name_set.n_hash) {
74777+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
74778+ PAGE_SIZE)
74779+ kfree(polstate->name_set.n_hash);
74780+ else
74781+ vfree(polstate->name_set.n_hash);
74782+ }
74783+
74784+ if (polstate->inodev_set.i_hash) {
74785+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
74786+ PAGE_SIZE)
74787+ kfree(polstate->inodev_set.i_hash);
74788+ else
74789+ vfree(polstate->inodev_set.i_hash);
74790+ }
74791+
74792+ if (!reload)
74793+ gr_free_uidset();
74794+
74795+ memset(&polstate->name_set, 0, sizeof (struct name_db));
74796+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
74797+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
74798+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
74799+
74800+ polstate->default_role = NULL;
74801+ polstate->kernel_role = NULL;
74802+ polstate->role_list = NULL;
74803+
74804+ return;
74805+}
74806+
74807+static struct acl_subject_label *
74808+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
74809+
74810+static int alloc_and_copy_string(char **name, unsigned int maxlen)
74811+{
74812+ unsigned int len = strnlen_user(*name, maxlen);
74813+ char *tmp;
74814+
74815+ if (!len || len >= maxlen)
74816+ return -EINVAL;
74817+
74818+ if ((tmp = (char *) acl_alloc(len)) == NULL)
74819+ return -ENOMEM;
74820+
74821+ if (copy_from_user(tmp, *name, len))
74822+ return -EFAULT;
74823+
74824+ tmp[len-1] = '\0';
74825+ *name = tmp;
74826+
74827+ return 0;
74828+}
74829+
74830+static int
74831+copy_user_glob(struct acl_object_label *obj)
74832+{
74833+ struct acl_object_label *g_tmp, **guser;
74834+ int error;
74835+
74836+ if (obj->globbed == NULL)
74837+ return 0;
74838+
74839+ guser = &obj->globbed;
74840+ while (*guser) {
74841+ g_tmp = (struct acl_object_label *)
74842+ acl_alloc(sizeof (struct acl_object_label));
74843+ if (g_tmp == NULL)
74844+ return -ENOMEM;
74845+
74846+ if (copy_acl_object_label(g_tmp, *guser))
74847+ return -EFAULT;
74848+
74849+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
74850+ if (error)
74851+ return error;
74852+
74853+ *guser = g_tmp;
74854+ guser = &(g_tmp->next);
74855+ }
74856+
74857+ return 0;
74858+}
74859+
74860+static int
74861+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
74862+ struct acl_role_label *role)
74863+{
74864+ struct acl_object_label *o_tmp;
74865+ int ret;
74866+
74867+ while (userp) {
74868+ if ((o_tmp = (struct acl_object_label *)
74869+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
74870+ return -ENOMEM;
74871+
74872+ if (copy_acl_object_label(o_tmp, userp))
74873+ return -EFAULT;
74874+
74875+ userp = o_tmp->prev;
74876+
74877+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
74878+ if (ret)
74879+ return ret;
74880+
74881+ insert_acl_obj_label(o_tmp, subj);
74882+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
74883+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
74884+ return -ENOMEM;
74885+
74886+ ret = copy_user_glob(o_tmp);
74887+ if (ret)
74888+ return ret;
74889+
74890+ if (o_tmp->nested) {
74891+ int already_copied;
74892+
74893+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
74894+ if (IS_ERR(o_tmp->nested))
74895+ return PTR_ERR(o_tmp->nested);
74896+
74897+ /* insert into nested subject list if we haven't copied this one yet
74898+ to prevent duplicate entries */
74899+ if (!already_copied) {
74900+ o_tmp->nested->next = role->hash->first;
74901+ role->hash->first = o_tmp->nested;
74902+ }
74903+ }
74904+ }
74905+
74906+ return 0;
74907+}
74908+
74909+static __u32
74910+count_user_subjs(struct acl_subject_label *userp)
74911+{
74912+ struct acl_subject_label s_tmp;
74913+ __u32 num = 0;
74914+
74915+ while (userp) {
74916+ if (copy_acl_subject_label(&s_tmp, userp))
74917+ break;
74918+
74919+ userp = s_tmp.prev;
74920+ }
74921+
74922+ return num;
74923+}
74924+
74925+static int
74926+copy_user_allowedips(struct acl_role_label *rolep)
74927+{
74928+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
74929+
74930+ ruserip = rolep->allowed_ips;
74931+
74932+ while (ruserip) {
74933+ rlast = rtmp;
74934+
74935+ if ((rtmp = (struct role_allowed_ip *)
74936+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
74937+ return -ENOMEM;
74938+
74939+ if (copy_role_allowed_ip(rtmp, ruserip))
74940+ return -EFAULT;
74941+
74942+ ruserip = rtmp->prev;
74943+
74944+ if (!rlast) {
74945+ rtmp->prev = NULL;
74946+ rolep->allowed_ips = rtmp;
74947+ } else {
74948+ rlast->next = rtmp;
74949+ rtmp->prev = rlast;
74950+ }
74951+
74952+ if (!ruserip)
74953+ rtmp->next = NULL;
74954+ }
74955+
74956+ return 0;
74957+}
74958+
74959+static int
74960+copy_user_transitions(struct acl_role_label *rolep)
74961+{
74962+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
74963+ int error;
74964+
74965+ rusertp = rolep->transitions;
74966+
74967+ while (rusertp) {
74968+ rlast = rtmp;
74969+
74970+ if ((rtmp = (struct role_transition *)
74971+ acl_alloc(sizeof (struct role_transition))) == NULL)
74972+ return -ENOMEM;
74973+
74974+ if (copy_role_transition(rtmp, rusertp))
74975+ return -EFAULT;
74976+
74977+ rusertp = rtmp->prev;
74978+
74979+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
74980+ if (error)
74981+ return error;
74982+
74983+ if (!rlast) {
74984+ rtmp->prev = NULL;
74985+ rolep->transitions = rtmp;
74986+ } else {
74987+ rlast->next = rtmp;
74988+ rtmp->prev = rlast;
74989+ }
74990+
74991+ if (!rusertp)
74992+ rtmp->next = NULL;
74993+ }
74994+
74995+ return 0;
74996+}
74997+
74998+static __u32 count_user_objs(const struct acl_object_label __user *userp)
74999+{
75000+ struct acl_object_label o_tmp;
75001+ __u32 num = 0;
75002+
75003+ while (userp) {
75004+ if (copy_acl_object_label(&o_tmp, userp))
75005+ break;
75006+
75007+ userp = o_tmp.prev;
75008+ num++;
75009+ }
75010+
75011+ return num;
75012+}
75013+
75014+static struct acl_subject_label *
75015+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
75016+{
75017+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
75018+ __u32 num_objs;
75019+ struct acl_ip_label **i_tmp, *i_utmp2;
75020+ struct gr_hash_struct ghash;
75021+ struct subject_map *subjmap;
75022+ unsigned int i_num;
75023+ int err;
75024+
75025+ if (already_copied != NULL)
75026+ *already_copied = 0;
75027+
75028+ s_tmp = lookup_subject_map(userp);
75029+
75030+ /* we've already copied this subject into the kernel, just return
75031+ the reference to it, and don't copy it over again
75032+ */
75033+ if (s_tmp) {
75034+ if (already_copied != NULL)
75035+ *already_copied = 1;
75036+ return(s_tmp);
75037+ }
75038+
75039+ if ((s_tmp = (struct acl_subject_label *)
75040+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
75041+ return ERR_PTR(-ENOMEM);
75042+
75043+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
75044+ if (subjmap == NULL)
75045+ return ERR_PTR(-ENOMEM);
75046+
75047+ subjmap->user = userp;
75048+ subjmap->kernel = s_tmp;
75049+ insert_subj_map_entry(subjmap);
75050+
75051+ if (copy_acl_subject_label(s_tmp, userp))
75052+ return ERR_PTR(-EFAULT);
75053+
75054+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
75055+ if (err)
75056+ return ERR_PTR(err);
75057+
75058+ if (!strcmp(s_tmp->filename, "/"))
75059+ role->root_label = s_tmp;
75060+
75061+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
75062+ return ERR_PTR(-EFAULT);
75063+
75064+ /* copy user and group transition tables */
75065+
75066+ if (s_tmp->user_trans_num) {
75067+ uid_t *uidlist;
75068+
75069+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
75070+ if (uidlist == NULL)
75071+ return ERR_PTR(-ENOMEM);
75072+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
75073+ return ERR_PTR(-EFAULT);
75074+
75075+ s_tmp->user_transitions = uidlist;
75076+ }
75077+
75078+ if (s_tmp->group_trans_num) {
75079+ gid_t *gidlist;
75080+
75081+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
75082+ if (gidlist == NULL)
75083+ return ERR_PTR(-ENOMEM);
75084+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
75085+ return ERR_PTR(-EFAULT);
75086+
75087+ s_tmp->group_transitions = gidlist;
75088+ }
75089+
75090+ /* set up object hash table */
75091+ num_objs = count_user_objs(ghash.first);
75092+
75093+ s_tmp->obj_hash_size = num_objs;
75094+ s_tmp->obj_hash =
75095+ (struct acl_object_label **)
75096+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
75097+
75098+ if (!s_tmp->obj_hash)
75099+ return ERR_PTR(-ENOMEM);
75100+
75101+ memset(s_tmp->obj_hash, 0,
75102+ s_tmp->obj_hash_size *
75103+ sizeof (struct acl_object_label *));
75104+
75105+ /* add in objects */
75106+ err = copy_user_objs(ghash.first, s_tmp, role);
75107+
75108+ if (err)
75109+ return ERR_PTR(err);
75110+
75111+ /* set pointer for parent subject */
75112+ if (s_tmp->parent_subject) {
75113+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
75114+
75115+ if (IS_ERR(s_tmp2))
75116+ return s_tmp2;
75117+
75118+ s_tmp->parent_subject = s_tmp2;
75119+ }
75120+
75121+ /* add in ip acls */
75122+
75123+ if (!s_tmp->ip_num) {
75124+ s_tmp->ips = NULL;
75125+ goto insert;
75126+ }
75127+
75128+ i_tmp =
75129+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
75130+ sizeof (struct acl_ip_label *));
75131+
75132+ if (!i_tmp)
75133+ return ERR_PTR(-ENOMEM);
75134+
75135+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
75136+ *(i_tmp + i_num) =
75137+ (struct acl_ip_label *)
75138+ acl_alloc(sizeof (struct acl_ip_label));
75139+ if (!*(i_tmp + i_num))
75140+ return ERR_PTR(-ENOMEM);
75141+
75142+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
75143+ return ERR_PTR(-EFAULT);
75144+
75145+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
75146+ return ERR_PTR(-EFAULT);
75147+
75148+ if ((*(i_tmp + i_num))->iface == NULL)
75149+ continue;
75150+
75151+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
75152+ if (err)
75153+ return ERR_PTR(err);
75154+ }
75155+
75156+ s_tmp->ips = i_tmp;
75157+
75158+insert:
75159+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
75160+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
75161+ return ERR_PTR(-ENOMEM);
75162+
75163+ return s_tmp;
75164+}
75165+
75166+static int
75167+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
75168+{
75169+ struct acl_subject_label s_pre;
75170+ struct acl_subject_label * ret;
75171+ int err;
75172+
75173+ while (userp) {
75174+ if (copy_acl_subject_label(&s_pre, userp))
75175+ return -EFAULT;
75176+
75177+ ret = do_copy_user_subj(userp, role, NULL);
75178+
75179+ err = PTR_ERR(ret);
75180+ if (IS_ERR(ret))
75181+ return err;
75182+
75183+ insert_acl_subj_label(ret, role);
75184+
75185+ userp = s_pre.prev;
75186+ }
75187+
75188+ return 0;
75189+}
75190+
75191+static int
75192+copy_user_acl(struct gr_arg *arg)
75193+{
75194+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
75195+ struct acl_subject_label *subj_list;
75196+ struct sprole_pw *sptmp;
75197+ struct gr_hash_struct *ghash;
75198+ uid_t *domainlist;
75199+ unsigned int r_num;
75200+ int err = 0;
75201+ __u16 i;
75202+ __u32 num_subjs;
75203+
75204+ /* we need a default and kernel role */
75205+ if (arg->role_db.num_roles < 2)
75206+ return -EINVAL;
75207+
75208+ /* copy special role authentication info from userspace */
75209+
75210+ polstate->num_sprole_pws = arg->num_sprole_pws;
75211+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
75212+
75213+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
75214+ return -ENOMEM;
75215+
75216+ for (i = 0; i < polstate->num_sprole_pws; i++) {
75217+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
75218+ if (!sptmp)
75219+ return -ENOMEM;
75220+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
75221+ return -EFAULT;
75222+
75223+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
75224+ if (err)
75225+ return err;
75226+
75227+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
75228+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
75229+#endif
75230+
75231+ polstate->acl_special_roles[i] = sptmp;
75232+ }
75233+
75234+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
75235+
75236+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
75237+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
75238+
75239+ if (!r_tmp)
75240+ return -ENOMEM;
75241+
75242+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
75243+ return -EFAULT;
75244+
75245+ if (copy_acl_role_label(r_tmp, r_utmp2))
75246+ return -EFAULT;
75247+
75248+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
75249+ if (err)
75250+ return err;
75251+
75252+ if (!strcmp(r_tmp->rolename, "default")
75253+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
75254+ polstate->default_role = r_tmp;
75255+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
75256+ polstate->kernel_role = r_tmp;
75257+ }
75258+
75259+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
75260+ return -ENOMEM;
75261+
75262+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
75263+ return -EFAULT;
75264+
75265+ r_tmp->hash = ghash;
75266+
75267+ num_subjs = count_user_subjs(r_tmp->hash->first);
75268+
75269+ r_tmp->subj_hash_size = num_subjs;
75270+ r_tmp->subj_hash =
75271+ (struct acl_subject_label **)
75272+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
75273+
75274+ if (!r_tmp->subj_hash)
75275+ return -ENOMEM;
75276+
75277+ err = copy_user_allowedips(r_tmp);
75278+ if (err)
75279+ return err;
75280+
75281+ /* copy domain info */
75282+ if (r_tmp->domain_children != NULL) {
75283+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
75284+ if (domainlist == NULL)
75285+ return -ENOMEM;
75286+
75287+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
75288+ return -EFAULT;
75289+
75290+ r_tmp->domain_children = domainlist;
75291+ }
75292+
75293+ err = copy_user_transitions(r_tmp);
75294+ if (err)
75295+ return err;
75296+
75297+ memset(r_tmp->subj_hash, 0,
75298+ r_tmp->subj_hash_size *
75299+ sizeof (struct acl_subject_label *));
75300+
75301+ /* acquire the list of subjects, then NULL out
75302+ the list prior to parsing the subjects for this role,
75303+ as during this parsing the list is replaced with a list
75304+ of *nested* subjects for the role
75305+ */
75306+ subj_list = r_tmp->hash->first;
75307+
75308+ /* set nested subject list to null */
75309+ r_tmp->hash->first = NULL;
75310+
75311+ err = copy_user_subjs(subj_list, r_tmp);
75312+
75313+ if (err)
75314+ return err;
75315+
75316+ insert_acl_role_label(r_tmp);
75317+ }
75318+
75319+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
75320+ return -EINVAL;
75321+
75322+ return err;
75323+}
75324+
75325+static int gracl_reload_apply_policies(void *reload)
75326+{
75327+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
75328+ struct task_struct *task, *task2;
75329+ struct acl_role_label *role, *rtmp;
75330+ struct acl_subject_label *subj;
75331+ const struct cred *cred;
75332+ int role_applied;
75333+ int ret = 0;
75334+
75335+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
75336+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
75337+
75338+ /* first make sure we'll be able to apply the new policy cleanly */
75339+ do_each_thread(task2, task) {
75340+ if (task->exec_file == NULL)
75341+ continue;
75342+ role_applied = 0;
75343+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
75344+ /* preserve special roles */
75345+ FOR_EACH_ROLE_START(role)
75346+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
75347+ rtmp = task->role;
75348+ task->role = role;
75349+ role_applied = 1;
75350+ break;
75351+ }
75352+ FOR_EACH_ROLE_END(role)
75353+ }
75354+ if (!role_applied) {
75355+ cred = __task_cred(task);
75356+ rtmp = task->role;
75357+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75358+ }
75359+ /* this handles non-nested inherited subjects, nested subjects will still
75360+ be dropped currently */
75361+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
75362+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
75363+ /* change the role back so that we've made no modifications to the policy */
75364+ task->role = rtmp;
75365+
75366+ if (subj == NULL || task->tmpacl == NULL) {
75367+ ret = -EINVAL;
75368+ goto out;
75369+ }
75370+ } while_each_thread(task2, task);
75371+
75372+ /* now actually apply the policy */
75373+
75374+ do_each_thread(task2, task) {
75375+ if (task->exec_file) {
75376+ role_applied = 0;
75377+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
75378+ /* preserve special roles */
75379+ FOR_EACH_ROLE_START(role)
75380+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
75381+ task->role = role;
75382+ role_applied = 1;
75383+ break;
75384+ }
75385+ FOR_EACH_ROLE_END(role)
75386+ }
75387+ if (!role_applied) {
75388+ cred = __task_cred(task);
75389+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75390+ }
75391+ /* this handles non-nested inherited subjects, nested subjects will still
75392+ be dropped currently */
75393+ if (!reload_state->oldmode && task->inherited)
75394+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
75395+ else {
75396+ /* looked up and tagged to the task previously */
75397+ subj = task->tmpacl;
75398+ }
75399+ /* subj will be non-null */
75400+ __gr_apply_subject_to_task(polstate, task, subj);
75401+ if (reload_state->oldmode) {
75402+ task->acl_role_id = 0;
75403+ task->acl_sp_role = 0;
75404+ task->inherited = 0;
75405+ }
75406+ } else {
75407+ // it's a kernel process
75408+ task->role = polstate->kernel_role;
75409+ task->acl = polstate->kernel_role->root_label;
75410+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75411+ task->acl->mode &= ~GR_PROCFIND;
75412+#endif
75413+ }
75414+ } while_each_thread(task2, task);
75415+
75416+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
75417+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
75418+
75419+out:
75420+
75421+ return ret;
75422+}
75423+
75424+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
75425+{
75426+ struct gr_reload_state new_reload_state = { };
75427+ int err;
75428+
75429+ new_reload_state.oldpolicy_ptr = polstate;
75430+ new_reload_state.oldalloc_ptr = current_alloc_state;
75431+ new_reload_state.oldmode = oldmode;
75432+
75433+ current_alloc_state = &new_reload_state.newalloc;
75434+ polstate = &new_reload_state.newpolicy;
75435+
75436+ /* everything relevant is now saved off, copy in the new policy */
75437+ if (init_variables(args, true)) {
75438+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75439+ err = -ENOMEM;
75440+ goto error;
75441+ }
75442+
75443+ err = copy_user_acl(args);
75444+ free_init_variables();
75445+ if (err)
75446+ goto error;
75447+ /* the new policy is copied in, with the old policy available via saved_state
75448+ first go through applying roles, making sure to preserve special roles
75449+ then apply new subjects, making sure to preserve inherited and nested subjects,
75450+ though currently only inherited subjects will be preserved
75451+ */
75452+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
75453+ if (err)
75454+ goto error;
75455+
75456+ /* we've now applied the new policy, so restore the old policy state to free it */
75457+ polstate = &new_reload_state.oldpolicy;
75458+ current_alloc_state = &new_reload_state.oldalloc;
75459+ free_variables(true);
75460+
75461+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
75462+ to running_polstate/current_alloc_state inside stop_machine
75463+ */
75464+ err = 0;
75465+ goto out;
75466+error:
75467+ /* on error of loading the new policy, we'll just keep the previous
75468+ policy set around
75469+ */
75470+ free_variables(true);
75471+
75472+ /* doesn't affect runtime, but maintains consistent state */
75473+out:
75474+ polstate = new_reload_state.oldpolicy_ptr;
75475+ current_alloc_state = new_reload_state.oldalloc_ptr;
75476+
75477+ return err;
75478+}
75479+
75480+static int
75481+gracl_init(struct gr_arg *args)
75482+{
75483+ int error = 0;
75484+
75485+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
75486+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
75487+
75488+ if (init_variables(args, false)) {
75489+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75490+ error = -ENOMEM;
75491+ goto out;
75492+ }
75493+
75494+ error = copy_user_acl(args);
75495+ free_init_variables();
75496+ if (error)
75497+ goto out;
75498+
75499+ error = gr_set_acls(0);
75500+ if (error)
75501+ goto out;
75502+
75503+ gr_enable_rbac_system();
75504+
75505+ return 0;
75506+
75507+out:
75508+ free_variables(false);
75509+ return error;
75510+}
75511+
75512+static int
75513+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
75514+ unsigned char **sum)
75515+{
75516+ struct acl_role_label *r;
75517+ struct role_allowed_ip *ipp;
75518+ struct role_transition *trans;
75519+ unsigned int i;
75520+ int found = 0;
75521+ u32 curr_ip = current->signal->curr_ip;
75522+
75523+ current->signal->saved_ip = curr_ip;
75524+
75525+ /* check transition table */
75526+
75527+ for (trans = current->role->transitions; trans; trans = trans->next) {
75528+ if (!strcmp(rolename, trans->rolename)) {
75529+ found = 1;
75530+ break;
75531+ }
75532+ }
75533+
75534+ if (!found)
75535+ return 0;
75536+
75537+ /* handle special roles that do not require authentication
75538+ and check ip */
75539+
75540+ FOR_EACH_ROLE_START(r)
75541+ if (!strcmp(rolename, r->rolename) &&
75542+ (r->roletype & GR_ROLE_SPECIAL)) {
75543+ found = 0;
75544+ if (r->allowed_ips != NULL) {
75545+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
75546+ if ((ntohl(curr_ip) & ipp->netmask) ==
75547+ (ntohl(ipp->addr) & ipp->netmask))
75548+ found = 1;
75549+ }
75550+ } else
75551+ found = 2;
75552+ if (!found)
75553+ return 0;
75554+
75555+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
75556+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
75557+ *salt = NULL;
75558+ *sum = NULL;
75559+ return 1;
75560+ }
75561+ }
75562+ FOR_EACH_ROLE_END(r)
75563+
75564+ for (i = 0; i < polstate->num_sprole_pws; i++) {
75565+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
75566+ *salt = polstate->acl_special_roles[i]->salt;
75567+ *sum = polstate->acl_special_roles[i]->sum;
75568+ return 1;
75569+ }
75570+ }
75571+
75572+ return 0;
75573+}
75574+
75575+int gr_check_secure_terminal(struct task_struct *task)
75576+{
75577+ struct task_struct *p, *p2, *p3;
75578+ struct files_struct *files;
75579+ struct fdtable *fdt;
75580+ struct file *our_file = NULL, *file;
75581+ int i;
75582+
75583+ if (task->signal->tty == NULL)
75584+ return 1;
75585+
75586+ files = get_files_struct(task);
75587+ if (files != NULL) {
75588+ rcu_read_lock();
75589+ fdt = files_fdtable(files);
75590+ for (i=0; i < fdt->max_fds; i++) {
75591+ file = fcheck_files(files, i);
75592+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
75593+ get_file(file);
75594+ our_file = file;
75595+ }
75596+ }
75597+ rcu_read_unlock();
75598+ put_files_struct(files);
75599+ }
75600+
75601+ if (our_file == NULL)
75602+ return 1;
75603+
75604+ read_lock(&tasklist_lock);
75605+ do_each_thread(p2, p) {
75606+ files = get_files_struct(p);
75607+ if (files == NULL ||
75608+ (p->signal && p->signal->tty == task->signal->tty)) {
75609+ if (files != NULL)
75610+ put_files_struct(files);
75611+ continue;
75612+ }
75613+ rcu_read_lock();
75614+ fdt = files_fdtable(files);
75615+ for (i=0; i < fdt->max_fds; i++) {
75616+ file = fcheck_files(files, i);
75617+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
75618+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
75619+ p3 = task;
75620+ while (task_pid_nr(p3) > 0) {
75621+ if (p3 == p)
75622+ break;
75623+ p3 = p3->real_parent;
75624+ }
75625+ if (p3 == p)
75626+ break;
75627+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
75628+ gr_handle_alertkill(p);
75629+ rcu_read_unlock();
75630+ put_files_struct(files);
75631+ read_unlock(&tasklist_lock);
75632+ fput(our_file);
75633+ return 0;
75634+ }
75635+ }
75636+ rcu_read_unlock();
75637+ put_files_struct(files);
75638+ } while_each_thread(p2, p);
75639+ read_unlock(&tasklist_lock);
75640+
75641+ fput(our_file);
75642+ return 1;
75643+}
75644+
75645+ssize_t
75646+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
75647+{
75648+ struct gr_arg_wrapper uwrap;
75649+ unsigned char *sprole_salt = NULL;
75650+ unsigned char *sprole_sum = NULL;
75651+ int error = 0;
75652+ int error2 = 0;
75653+ size_t req_count = 0;
75654+ unsigned char oldmode = 0;
75655+
75656+ mutex_lock(&gr_dev_mutex);
75657+
75658+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
75659+ error = -EPERM;
75660+ goto out;
75661+ }
75662+
75663+#ifdef CONFIG_COMPAT
75664+ pax_open_kernel();
75665+ if (is_compat_task()) {
75666+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
75667+ copy_gr_arg = &copy_gr_arg_compat;
75668+ copy_acl_object_label = &copy_acl_object_label_compat;
75669+ copy_acl_subject_label = &copy_acl_subject_label_compat;
75670+ copy_acl_role_label = &copy_acl_role_label_compat;
75671+ copy_acl_ip_label = &copy_acl_ip_label_compat;
75672+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
75673+ copy_role_transition = &copy_role_transition_compat;
75674+ copy_sprole_pw = &copy_sprole_pw_compat;
75675+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
75676+ copy_pointer_from_array = &copy_pointer_from_array_compat;
75677+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
75678+ } else {
75679+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
75680+ copy_gr_arg = &copy_gr_arg_normal;
75681+ copy_acl_object_label = &copy_acl_object_label_normal;
75682+ copy_acl_subject_label = &copy_acl_subject_label_normal;
75683+ copy_acl_role_label = &copy_acl_role_label_normal;
75684+ copy_acl_ip_label = &copy_acl_ip_label_normal;
75685+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
75686+ copy_role_transition = &copy_role_transition_normal;
75687+ copy_sprole_pw = &copy_sprole_pw_normal;
75688+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
75689+ copy_pointer_from_array = &copy_pointer_from_array_normal;
75690+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
75691+ }
75692+ pax_close_kernel();
75693+#endif
75694+
75695+ req_count = get_gr_arg_wrapper_size();
75696+
75697+ if (count != req_count) {
75698+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
75699+ error = -EINVAL;
75700+ goto out;
75701+ }
75702+
75703+
75704+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
75705+ gr_auth_expires = 0;
75706+ gr_auth_attempts = 0;
75707+ }
75708+
75709+ error = copy_gr_arg_wrapper(buf, &uwrap);
75710+ if (error)
75711+ goto out;
75712+
75713+ error = copy_gr_arg(uwrap.arg, gr_usermode);
75714+ if (error)
75715+ goto out;
75716+
75717+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75718+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75719+ time_after(gr_auth_expires, get_seconds())) {
75720+ error = -EBUSY;
75721+ goto out;
75722+ }
75723+
75724+ /* if non-root trying to do anything other than use a special role,
75725+ do not attempt authentication, do not count towards authentication
75726+ locking
75727+ */
75728+
75729+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
75730+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75731+ gr_is_global_nonroot(current_uid())) {
75732+ error = -EPERM;
75733+ goto out;
75734+ }
75735+
75736+ /* ensure pw and special role name are null terminated */
75737+
75738+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
75739+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
75740+
75741+ /* Okay.
75742+ * We have our enough of the argument structure..(we have yet
75743+ * to copy_from_user the tables themselves) . Copy the tables
75744+ * only if we need them, i.e. for loading operations. */
75745+
75746+ switch (gr_usermode->mode) {
75747+ case GR_STATUS:
75748+ if (gr_acl_is_enabled()) {
75749+ error = 1;
75750+ if (!gr_check_secure_terminal(current))
75751+ error = 3;
75752+ } else
75753+ error = 2;
75754+ goto out;
75755+ case GR_SHUTDOWN:
75756+ if (gr_acl_is_enabled() && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75757+ stop_machine(gr_rbac_disable, NULL, NULL);
75758+ free_variables(false);
75759+ memset(gr_usermode, 0, sizeof(struct gr_arg));
75760+ memset(gr_system_salt, 0, GR_SALT_LEN);
75761+ memset(gr_system_sum, 0, GR_SHA_LEN);
75762+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
75763+ } else if (gr_acl_is_enabled()) {
75764+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
75765+ error = -EPERM;
75766+ } else {
75767+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
75768+ error = -EAGAIN;
75769+ }
75770+ break;
75771+ case GR_ENABLE:
75772+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(gr_usermode)))
75773+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
75774+ else {
75775+ if (gr_acl_is_enabled())
75776+ error = -EAGAIN;
75777+ else
75778+ error = error2;
75779+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
75780+ }
75781+ break;
75782+ case GR_OLDRELOAD:
75783+ oldmode = 1;
75784+ case GR_RELOAD:
75785+ if (!gr_acl_is_enabled()) {
75786+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
75787+ error = -EAGAIN;
75788+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75789+ error2 = gracl_reload(gr_usermode, oldmode);
75790+ if (!error2)
75791+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
75792+ else {
75793+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75794+ error = error2;
75795+ }
75796+ } else {
75797+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75798+ error = -EPERM;
75799+ }
75800+ break;
75801+ case GR_SEGVMOD:
75802+ if (unlikely(!gr_acl_is_enabled())) {
75803+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
75804+ error = -EAGAIN;
75805+ break;
75806+ }
75807+
75808+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75809+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
75810+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
75811+ struct acl_subject_label *segvacl;
75812+ segvacl =
75813+ lookup_acl_subj_label(gr_usermode->segv_inode,
75814+ gr_usermode->segv_device,
75815+ current->role);
75816+ if (segvacl) {
75817+ segvacl->crashes = 0;
75818+ segvacl->expires = 0;
75819+ }
75820+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
75821+ gr_remove_uid(gr_usermode->segv_uid);
75822+ }
75823+ } else {
75824+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
75825+ error = -EPERM;
75826+ }
75827+ break;
75828+ case GR_SPROLE:
75829+ case GR_SPROLEPAM:
75830+ if (unlikely(!gr_acl_is_enabled())) {
75831+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
75832+ error = -EAGAIN;
75833+ break;
75834+ }
75835+
75836+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
75837+ current->role->expires = 0;
75838+ current->role->auth_attempts = 0;
75839+ }
75840+
75841+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75842+ time_after(current->role->expires, get_seconds())) {
75843+ error = -EBUSY;
75844+ goto out;
75845+ }
75846+
75847+ if (lookup_special_role_auth
75848+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
75849+ && ((!sprole_salt && !sprole_sum)
75850+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
75851+ char *p = "";
75852+ assign_special_role(gr_usermode->sp_role);
75853+ read_lock(&tasklist_lock);
75854+ if (current->real_parent)
75855+ p = current->real_parent->role->rolename;
75856+ read_unlock(&tasklist_lock);
75857+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
75858+ p, acl_sp_role_value);
75859+ } else {
75860+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
75861+ error = -EPERM;
75862+ if(!(current->role->auth_attempts++))
75863+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75864+
75865+ goto out;
75866+ }
75867+ break;
75868+ case GR_UNSPROLE:
75869+ if (unlikely(!gr_acl_is_enabled())) {
75870+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
75871+ error = -EAGAIN;
75872+ break;
75873+ }
75874+
75875+ if (current->role->roletype & GR_ROLE_SPECIAL) {
75876+ char *p = "";
75877+ int i = 0;
75878+
75879+ read_lock(&tasklist_lock);
75880+ if (current->real_parent) {
75881+ p = current->real_parent->role->rolename;
75882+ i = current->real_parent->acl_role_id;
75883+ }
75884+ read_unlock(&tasklist_lock);
75885+
75886+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
75887+ gr_set_acls(1);
75888+ } else {
75889+ error = -EPERM;
75890+ goto out;
75891+ }
75892+ break;
75893+ default:
75894+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
75895+ error = -EINVAL;
75896+ break;
75897+ }
75898+
75899+ if (error != -EPERM)
75900+ goto out;
75901+
75902+ if(!(gr_auth_attempts++))
75903+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75904+
75905+ out:
75906+ mutex_unlock(&gr_dev_mutex);
75907+
75908+ if (!error)
75909+ error = req_count;
75910+
75911+ return error;
75912+}
75913+
75914+int
75915+gr_set_acls(const int type)
75916+{
75917+ struct task_struct *task, *task2;
75918+ struct acl_role_label *role = current->role;
75919+ struct acl_subject_label *subj;
75920+ __u16 acl_role_id = current->acl_role_id;
75921+ const struct cred *cred;
75922+ int ret;
75923+
75924+ rcu_read_lock();
75925+ read_lock(&tasklist_lock);
75926+ read_lock(&grsec_exec_file_lock);
75927+ do_each_thread(task2, task) {
75928+ /* check to see if we're called from the exit handler,
75929+ if so, only replace ACLs that have inherited the admin
75930+ ACL */
75931+
75932+ if (type && (task->role != role ||
75933+ task->acl_role_id != acl_role_id))
75934+ continue;
75935+
75936+ task->acl_role_id = 0;
75937+ task->acl_sp_role = 0;
75938+ task->inherited = 0;
75939+
75940+ if (task->exec_file) {
75941+ cred = __task_cred(task);
75942+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75943+ subj = __gr_get_subject_for_task(polstate, task, NULL);
75944+ if (subj == NULL) {
75945+ ret = -EINVAL;
75946+ read_unlock(&grsec_exec_file_lock);
75947+ read_unlock(&tasklist_lock);
75948+ rcu_read_unlock();
75949+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
75950+ return ret;
75951+ }
75952+ __gr_apply_subject_to_task(polstate, task, subj);
75953+ } else {
75954+ // it's a kernel process
75955+ task->role = polstate->kernel_role;
75956+ task->acl = polstate->kernel_role->root_label;
75957+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75958+ task->acl->mode &= ~GR_PROCFIND;
75959+#endif
75960+ }
75961+ } while_each_thread(task2, task);
75962+ read_unlock(&grsec_exec_file_lock);
75963+ read_unlock(&tasklist_lock);
75964+ rcu_read_unlock();
75965+
75966+ return 0;
75967+}
75968diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
75969new file mode 100644
75970index 0000000..39645c9
75971--- /dev/null
75972+++ b/grsecurity/gracl_res.c
75973@@ -0,0 +1,68 @@
75974+#include <linux/kernel.h>
75975+#include <linux/sched.h>
75976+#include <linux/gracl.h>
75977+#include <linux/grinternal.h>
75978+
75979+static const char *restab_log[] = {
75980+ [RLIMIT_CPU] = "RLIMIT_CPU",
75981+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
75982+ [RLIMIT_DATA] = "RLIMIT_DATA",
75983+ [RLIMIT_STACK] = "RLIMIT_STACK",
75984+ [RLIMIT_CORE] = "RLIMIT_CORE",
75985+ [RLIMIT_RSS] = "RLIMIT_RSS",
75986+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
75987+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
75988+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
75989+ [RLIMIT_AS] = "RLIMIT_AS",
75990+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
75991+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
75992+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
75993+ [RLIMIT_NICE] = "RLIMIT_NICE",
75994+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
75995+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
75996+ [GR_CRASH_RES] = "RLIMIT_CRASH"
75997+};
75998+
75999+void
76000+gr_log_resource(const struct task_struct *task,
76001+ const int res, const unsigned long wanted, const int gt)
76002+{
76003+ const struct cred *cred;
76004+ unsigned long rlim;
76005+
76006+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
76007+ return;
76008+
76009+ // not yet supported resource
76010+ if (unlikely(!restab_log[res]))
76011+ return;
76012+
76013+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
76014+ rlim = task_rlimit_max(task, res);
76015+ else
76016+ rlim = task_rlimit(task, res);
76017+
76018+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
76019+ return;
76020+
76021+ rcu_read_lock();
76022+ cred = __task_cred(task);
76023+
76024+ if (res == RLIMIT_NPROC &&
76025+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
76026+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
76027+ goto out_rcu_unlock;
76028+ else if (res == RLIMIT_MEMLOCK &&
76029+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
76030+ goto out_rcu_unlock;
76031+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
76032+ goto out_rcu_unlock;
76033+ rcu_read_unlock();
76034+
76035+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
76036+
76037+ return;
76038+out_rcu_unlock:
76039+ rcu_read_unlock();
76040+ return;
76041+}
76042diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
76043new file mode 100644
76044index 0000000..2040e61
76045--- /dev/null
76046+++ b/grsecurity/gracl_segv.c
76047@@ -0,0 +1,313 @@
76048+#include <linux/kernel.h>
76049+#include <linux/mm.h>
76050+#include <asm/uaccess.h>
76051+#include <asm/errno.h>
76052+#include <asm/mman.h>
76053+#include <net/sock.h>
76054+#include <linux/file.h>
76055+#include <linux/fs.h>
76056+#include <linux/net.h>
76057+#include <linux/in.h>
76058+#include <linux/slab.h>
76059+#include <linux/types.h>
76060+#include <linux/sched.h>
76061+#include <linux/timer.h>
76062+#include <linux/gracl.h>
76063+#include <linux/grsecurity.h>
76064+#include <linux/grinternal.h>
76065+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
76066+#include <linux/magic.h>
76067+#include <linux/pagemap.h>
76068+#include "../fs/btrfs/async-thread.h"
76069+#include "../fs/btrfs/ctree.h"
76070+#include "../fs/btrfs/btrfs_inode.h"
76071+#endif
76072+
76073+static struct crash_uid *uid_set;
76074+static unsigned short uid_used;
76075+static DEFINE_SPINLOCK(gr_uid_lock);
76076+extern rwlock_t gr_inode_lock;
76077+extern struct acl_subject_label *
76078+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
76079+ struct acl_role_label *role);
76080+
76081+static inline dev_t __get_dev(const struct dentry *dentry)
76082+{
76083+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
76084+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
76085+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
76086+ else
76087+#endif
76088+ return dentry->d_sb->s_dev;
76089+}
76090+
76091+int
76092+gr_init_uidset(void)
76093+{
76094+ uid_set =
76095+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
76096+ uid_used = 0;
76097+
76098+ return uid_set ? 1 : 0;
76099+}
76100+
76101+void
76102+gr_free_uidset(void)
76103+{
76104+ if (uid_set) {
76105+ struct crash_uid *tmpset;
76106+ spin_lock(&gr_uid_lock);
76107+ tmpset = uid_set;
76108+ uid_set = NULL;
76109+ uid_used = 0;
76110+ spin_unlock(&gr_uid_lock);
76111+ if (tmpset)
76112+ kfree(tmpset);
76113+ }
76114+
76115+ return;
76116+}
76117+
76118+int
76119+gr_find_uid(const uid_t uid)
76120+{
76121+ struct crash_uid *tmp = uid_set;
76122+ uid_t buid;
76123+ int low = 0, high = uid_used - 1, mid;
76124+
76125+ while (high >= low) {
76126+ mid = (low + high) >> 1;
76127+ buid = tmp[mid].uid;
76128+ if (buid == uid)
76129+ return mid;
76130+ if (buid > uid)
76131+ high = mid - 1;
76132+ if (buid < uid)
76133+ low = mid + 1;
76134+ }
76135+
76136+ return -1;
76137+}
76138+
76139+static __inline__ void
76140+gr_insertsort(void)
76141+{
76142+ unsigned short i, j;
76143+ struct crash_uid index;
76144+
76145+ for (i = 1; i < uid_used; i++) {
76146+ index = uid_set[i];
76147+ j = i;
76148+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
76149+ uid_set[j] = uid_set[j - 1];
76150+ j--;
76151+ }
76152+ uid_set[j] = index;
76153+ }
76154+
76155+ return;
76156+}
76157+
76158+static __inline__ void
76159+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
76160+{
76161+ int loc;
76162+ uid_t uid = GR_GLOBAL_UID(kuid);
76163+
76164+ if (uid_used == GR_UIDTABLE_MAX)
76165+ return;
76166+
76167+ loc = gr_find_uid(uid);
76168+
76169+ if (loc >= 0) {
76170+ uid_set[loc].expires = expires;
76171+ return;
76172+ }
76173+
76174+ uid_set[uid_used].uid = uid;
76175+ uid_set[uid_used].expires = expires;
76176+ uid_used++;
76177+
76178+ gr_insertsort();
76179+
76180+ return;
76181+}
76182+
76183+void
76184+gr_remove_uid(const unsigned short loc)
76185+{
76186+ unsigned short i;
76187+
76188+ for (i = loc + 1; i < uid_used; i++)
76189+ uid_set[i - 1] = uid_set[i];
76190+
76191+ uid_used--;
76192+
76193+ return;
76194+}
76195+
76196+int
76197+gr_check_crash_uid(const kuid_t kuid)
76198+{
76199+ int loc;
76200+ int ret = 0;
76201+ uid_t uid;
76202+
76203+ if (unlikely(!gr_acl_is_enabled()))
76204+ return 0;
76205+
76206+ uid = GR_GLOBAL_UID(kuid);
76207+
76208+ spin_lock(&gr_uid_lock);
76209+ loc = gr_find_uid(uid);
76210+
76211+ if (loc < 0)
76212+ goto out_unlock;
76213+
76214+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
76215+ gr_remove_uid(loc);
76216+ else
76217+ ret = 1;
76218+
76219+out_unlock:
76220+ spin_unlock(&gr_uid_lock);
76221+ return ret;
76222+}
76223+
76224+static __inline__ int
76225+proc_is_setxid(const struct cred *cred)
76226+{
76227+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
76228+ !uid_eq(cred->uid, cred->fsuid))
76229+ return 1;
76230+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
76231+ !gid_eq(cred->gid, cred->fsgid))
76232+ return 1;
76233+
76234+ return 0;
76235+}
76236+
76237+extern int gr_fake_force_sig(int sig, struct task_struct *t);
76238+
76239+void
76240+gr_handle_crash(struct task_struct *task, const int sig)
76241+{
76242+ struct acl_subject_label *curr;
76243+ struct task_struct *tsk, *tsk2;
76244+ const struct cred *cred;
76245+ const struct cred *cred2;
76246+
76247+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
76248+ return;
76249+
76250+ if (unlikely(!gr_acl_is_enabled()))
76251+ return;
76252+
76253+ curr = task->acl;
76254+
76255+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
76256+ return;
76257+
76258+ if (time_before_eq(curr->expires, get_seconds())) {
76259+ curr->expires = 0;
76260+ curr->crashes = 0;
76261+ }
76262+
76263+ curr->crashes++;
76264+
76265+ if (!curr->expires)
76266+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
76267+
76268+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
76269+ time_after(curr->expires, get_seconds())) {
76270+ rcu_read_lock();
76271+ cred = __task_cred(task);
76272+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
76273+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
76274+ spin_lock(&gr_uid_lock);
76275+ gr_insert_uid(cred->uid, curr->expires);
76276+ spin_unlock(&gr_uid_lock);
76277+ curr->expires = 0;
76278+ curr->crashes = 0;
76279+ read_lock(&tasklist_lock);
76280+ do_each_thread(tsk2, tsk) {
76281+ cred2 = __task_cred(tsk);
76282+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
76283+ gr_fake_force_sig(SIGKILL, tsk);
76284+ } while_each_thread(tsk2, tsk);
76285+ read_unlock(&tasklist_lock);
76286+ } else {
76287+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
76288+ read_lock(&tasklist_lock);
76289+ read_lock(&grsec_exec_file_lock);
76290+ do_each_thread(tsk2, tsk) {
76291+ if (likely(tsk != task)) {
76292+ // if this thread has the same subject as the one that triggered
76293+ // RES_CRASH and it's the same binary, kill it
76294+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
76295+ gr_fake_force_sig(SIGKILL, tsk);
76296+ }
76297+ } while_each_thread(tsk2, tsk);
76298+ read_unlock(&grsec_exec_file_lock);
76299+ read_unlock(&tasklist_lock);
76300+ }
76301+ rcu_read_unlock();
76302+ }
76303+
76304+ return;
76305+}
76306+
76307+int
76308+gr_check_crash_exec(const struct file *filp)
76309+{
76310+ struct acl_subject_label *curr;
76311+
76312+ if (unlikely(!gr_acl_is_enabled()))
76313+ return 0;
76314+
76315+ read_lock(&gr_inode_lock);
76316+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
76317+ __get_dev(filp->f_path.dentry),
76318+ current->role);
76319+ read_unlock(&gr_inode_lock);
76320+
76321+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
76322+ (!curr->crashes && !curr->expires))
76323+ return 0;
76324+
76325+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
76326+ time_after(curr->expires, get_seconds()))
76327+ return 1;
76328+ else if (time_before_eq(curr->expires, get_seconds())) {
76329+ curr->crashes = 0;
76330+ curr->expires = 0;
76331+ }
76332+
76333+ return 0;
76334+}
76335+
76336+void
76337+gr_handle_alertkill(struct task_struct *task)
76338+{
76339+ struct acl_subject_label *curracl;
76340+ __u32 curr_ip;
76341+ struct task_struct *p, *p2;
76342+
76343+ if (unlikely(!gr_acl_is_enabled()))
76344+ return;
76345+
76346+ curracl = task->acl;
76347+ curr_ip = task->signal->curr_ip;
76348+
76349+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
76350+ read_lock(&tasklist_lock);
76351+ do_each_thread(p2, p) {
76352+ if (p->signal->curr_ip == curr_ip)
76353+ gr_fake_force_sig(SIGKILL, p);
76354+ } while_each_thread(p2, p);
76355+ read_unlock(&tasklist_lock);
76356+ } else if (curracl->mode & GR_KILLPROC)
76357+ gr_fake_force_sig(SIGKILL, task);
76358+
76359+ return;
76360+}
76361diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
76362new file mode 100644
76363index 0000000..6b0c9cc
76364--- /dev/null
76365+++ b/grsecurity/gracl_shm.c
76366@@ -0,0 +1,40 @@
76367+#include <linux/kernel.h>
76368+#include <linux/mm.h>
76369+#include <linux/sched.h>
76370+#include <linux/file.h>
76371+#include <linux/ipc.h>
76372+#include <linux/gracl.h>
76373+#include <linux/grsecurity.h>
76374+#include <linux/grinternal.h>
76375+
76376+int
76377+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76378+ const u64 shm_createtime, const kuid_t cuid, const int shmid)
76379+{
76380+ struct task_struct *task;
76381+
76382+ if (!gr_acl_is_enabled())
76383+ return 1;
76384+
76385+ rcu_read_lock();
76386+ read_lock(&tasklist_lock);
76387+
76388+ task = find_task_by_vpid(shm_cprid);
76389+
76390+ if (unlikely(!task))
76391+ task = find_task_by_vpid(shm_lapid);
76392+
76393+ if (unlikely(task && (time_before_eq64(task->start_time, shm_createtime) ||
76394+ (task_pid_nr(task) == shm_lapid)) &&
76395+ (task->acl->mode & GR_PROTSHM) &&
76396+ (task->acl != current->acl))) {
76397+ read_unlock(&tasklist_lock);
76398+ rcu_read_unlock();
76399+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
76400+ return 0;
76401+ }
76402+ read_unlock(&tasklist_lock);
76403+ rcu_read_unlock();
76404+
76405+ return 1;
76406+}
76407diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
76408new file mode 100644
76409index 0000000..bc0be01
76410--- /dev/null
76411+++ b/grsecurity/grsec_chdir.c
76412@@ -0,0 +1,19 @@
76413+#include <linux/kernel.h>
76414+#include <linux/sched.h>
76415+#include <linux/fs.h>
76416+#include <linux/file.h>
76417+#include <linux/grsecurity.h>
76418+#include <linux/grinternal.h>
76419+
76420+void
76421+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
76422+{
76423+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76424+ if ((grsec_enable_chdir && grsec_enable_group &&
76425+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
76426+ !grsec_enable_group)) {
76427+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
76428+ }
76429+#endif
76430+ return;
76431+}
76432diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
76433new file mode 100644
76434index 0000000..6d99cec
76435--- /dev/null
76436+++ b/grsecurity/grsec_chroot.c
76437@@ -0,0 +1,385 @@
76438+#include <linux/kernel.h>
76439+#include <linux/module.h>
76440+#include <linux/sched.h>
76441+#include <linux/file.h>
76442+#include <linux/fs.h>
76443+#include <linux/mount.h>
76444+#include <linux/types.h>
76445+#include "../fs/mount.h"
76446+#include <linux/grsecurity.h>
76447+#include <linux/grinternal.h>
76448+
76449+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76450+int gr_init_ran;
76451+#endif
76452+
76453+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
76454+{
76455+#ifdef CONFIG_GRKERNSEC
76456+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
76457+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
76458+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76459+ && gr_init_ran
76460+#endif
76461+ )
76462+ task->gr_is_chrooted = 1;
76463+ else {
76464+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76465+ if (task_pid_nr(task) == 1 && !gr_init_ran)
76466+ gr_init_ran = 1;
76467+#endif
76468+ task->gr_is_chrooted = 0;
76469+ }
76470+
76471+ task->gr_chroot_dentry = path->dentry;
76472+#endif
76473+ return;
76474+}
76475+
76476+void gr_clear_chroot_entries(struct task_struct *task)
76477+{
76478+#ifdef CONFIG_GRKERNSEC
76479+ task->gr_is_chrooted = 0;
76480+ task->gr_chroot_dentry = NULL;
76481+#endif
76482+ return;
76483+}
76484+
76485+int
76486+gr_handle_chroot_unix(const pid_t pid)
76487+{
76488+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76489+ struct task_struct *p;
76490+
76491+ if (unlikely(!grsec_enable_chroot_unix))
76492+ return 1;
76493+
76494+ if (likely(!proc_is_chrooted(current)))
76495+ return 1;
76496+
76497+ rcu_read_lock();
76498+ read_lock(&tasklist_lock);
76499+ p = find_task_by_vpid_unrestricted(pid);
76500+ if (unlikely(p && !have_same_root(current, p))) {
76501+ read_unlock(&tasklist_lock);
76502+ rcu_read_unlock();
76503+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
76504+ return 0;
76505+ }
76506+ read_unlock(&tasklist_lock);
76507+ rcu_read_unlock();
76508+#endif
76509+ return 1;
76510+}
76511+
76512+int
76513+gr_handle_chroot_nice(void)
76514+{
76515+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76516+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
76517+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
76518+ return -EPERM;
76519+ }
76520+#endif
76521+ return 0;
76522+}
76523+
76524+int
76525+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
76526+{
76527+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76528+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
76529+ && proc_is_chrooted(current)) {
76530+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
76531+ return -EACCES;
76532+ }
76533+#endif
76534+ return 0;
76535+}
76536+
76537+int
76538+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
76539+{
76540+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76541+ struct task_struct *p;
76542+ int ret = 0;
76543+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
76544+ return ret;
76545+
76546+ read_lock(&tasklist_lock);
76547+ do_each_pid_task(pid, type, p) {
76548+ if (!have_same_root(current, p)) {
76549+ ret = 1;
76550+ goto out;
76551+ }
76552+ } while_each_pid_task(pid, type, p);
76553+out:
76554+ read_unlock(&tasklist_lock);
76555+ return ret;
76556+#endif
76557+ return 0;
76558+}
76559+
76560+int
76561+gr_pid_is_chrooted(struct task_struct *p)
76562+{
76563+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76564+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
76565+ return 0;
76566+
76567+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
76568+ !have_same_root(current, p)) {
76569+ return 1;
76570+ }
76571+#endif
76572+ return 0;
76573+}
76574+
76575+EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
76576+
76577+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
76578+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
76579+{
76580+ struct path path, currentroot;
76581+ int ret = 0;
76582+
76583+ path.dentry = (struct dentry *)u_dentry;
76584+ path.mnt = (struct vfsmount *)u_mnt;
76585+ get_fs_root(current->fs, &currentroot);
76586+ if (path_is_under(&path, &currentroot))
76587+ ret = 1;
76588+ path_put(&currentroot);
76589+
76590+ return ret;
76591+}
76592+#endif
76593+
76594+int
76595+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
76596+{
76597+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76598+ if (!grsec_enable_chroot_fchdir)
76599+ return 1;
76600+
76601+ if (!proc_is_chrooted(current))
76602+ return 1;
76603+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
76604+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
76605+ return 0;
76606+ }
76607+#endif
76608+ return 1;
76609+}
76610+
76611+int
76612+gr_chroot_fhandle(void)
76613+{
76614+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76615+ if (!grsec_enable_chroot_fchdir)
76616+ return 1;
76617+
76618+ if (!proc_is_chrooted(current))
76619+ return 1;
76620+ else {
76621+ gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
76622+ return 0;
76623+ }
76624+#endif
76625+ return 1;
76626+}
76627+
76628+int
76629+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76630+ const u64 shm_createtime)
76631+{
76632+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76633+ struct task_struct *p;
76634+
76635+ if (unlikely(!grsec_enable_chroot_shmat))
76636+ return 1;
76637+
76638+ if (likely(!proc_is_chrooted(current)))
76639+ return 1;
76640+
76641+ rcu_read_lock();
76642+ read_lock(&tasklist_lock);
76643+
76644+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
76645+ if (time_before_eq64(p->start_time, shm_createtime)) {
76646+ if (have_same_root(current, p)) {
76647+ goto allow;
76648+ } else {
76649+ read_unlock(&tasklist_lock);
76650+ rcu_read_unlock();
76651+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76652+ return 0;
76653+ }
76654+ }
76655+ /* creator exited, pid reuse, fall through to next check */
76656+ }
76657+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
76658+ if (unlikely(!have_same_root(current, p))) {
76659+ read_unlock(&tasklist_lock);
76660+ rcu_read_unlock();
76661+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76662+ return 0;
76663+ }
76664+ }
76665+
76666+allow:
76667+ read_unlock(&tasklist_lock);
76668+ rcu_read_unlock();
76669+#endif
76670+ return 1;
76671+}
76672+
76673+void
76674+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
76675+{
76676+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76677+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
76678+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
76679+#endif
76680+ return;
76681+}
76682+
76683+int
76684+gr_handle_chroot_mknod(const struct dentry *dentry,
76685+ const struct vfsmount *mnt, const int mode)
76686+{
76687+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76688+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
76689+ proc_is_chrooted(current)) {
76690+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
76691+ return -EPERM;
76692+ }
76693+#endif
76694+ return 0;
76695+}
76696+
76697+int
76698+gr_handle_chroot_mount(const struct dentry *dentry,
76699+ const struct vfsmount *mnt, const char *dev_name)
76700+{
76701+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76702+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
76703+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
76704+ return -EPERM;
76705+ }
76706+#endif
76707+ return 0;
76708+}
76709+
76710+int
76711+gr_handle_chroot_pivot(void)
76712+{
76713+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76714+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
76715+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
76716+ return -EPERM;
76717+ }
76718+#endif
76719+ return 0;
76720+}
76721+
76722+int
76723+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
76724+{
76725+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76726+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
76727+ !gr_is_outside_chroot(dentry, mnt)) {
76728+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
76729+ return -EPERM;
76730+ }
76731+#endif
76732+ return 0;
76733+}
76734+
76735+extern const char *captab_log[];
76736+extern int captab_log_entries;
76737+
76738+int
76739+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
76740+{
76741+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76742+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76743+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76744+ if (cap_raised(chroot_caps, cap)) {
76745+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
76746+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
76747+ }
76748+ return 0;
76749+ }
76750+ }
76751+#endif
76752+ return 1;
76753+}
76754+
76755+int
76756+gr_chroot_is_capable(const int cap)
76757+{
76758+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76759+ return gr_task_chroot_is_capable(current, current_cred(), cap);
76760+#endif
76761+ return 1;
76762+}
76763+
76764+int
76765+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
76766+{
76767+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76768+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76769+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76770+ if (cap_raised(chroot_caps, cap)) {
76771+ return 0;
76772+ }
76773+ }
76774+#endif
76775+ return 1;
76776+}
76777+
76778+int
76779+gr_chroot_is_capable_nolog(const int cap)
76780+{
76781+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76782+ return gr_task_chroot_is_capable_nolog(current, cap);
76783+#endif
76784+ return 1;
76785+}
76786+
76787+int
76788+gr_handle_chroot_sysctl(const int op)
76789+{
76790+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76791+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
76792+ proc_is_chrooted(current))
76793+ return -EACCES;
76794+#endif
76795+ return 0;
76796+}
76797+
76798+void
76799+gr_handle_chroot_chdir(const struct path *path)
76800+{
76801+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76802+ if (grsec_enable_chroot_chdir)
76803+ set_fs_pwd(current->fs, path);
76804+#endif
76805+ return;
76806+}
76807+
76808+int
76809+gr_handle_chroot_chmod(const struct dentry *dentry,
76810+ const struct vfsmount *mnt, const int mode)
76811+{
76812+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76813+ /* allow chmod +s on directories, but not files */
76814+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
76815+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
76816+ proc_is_chrooted(current)) {
76817+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
76818+ return -EPERM;
76819+ }
76820+#endif
76821+ return 0;
76822+}
76823diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
76824new file mode 100644
76825index 0000000..0f9ac91
76826--- /dev/null
76827+++ b/grsecurity/grsec_disabled.c
76828@@ -0,0 +1,440 @@
76829+#include <linux/kernel.h>
76830+#include <linux/module.h>
76831+#include <linux/sched.h>
76832+#include <linux/file.h>
76833+#include <linux/fs.h>
76834+#include <linux/kdev_t.h>
76835+#include <linux/net.h>
76836+#include <linux/in.h>
76837+#include <linux/ip.h>
76838+#include <linux/skbuff.h>
76839+#include <linux/sysctl.h>
76840+
76841+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76842+void
76843+pax_set_initial_flags(struct linux_binprm *bprm)
76844+{
76845+ return;
76846+}
76847+#endif
76848+
76849+#ifdef CONFIG_SYSCTL
76850+__u32
76851+gr_handle_sysctl(const struct ctl_table * table, const int op)
76852+{
76853+ return 0;
76854+}
76855+#endif
76856+
76857+#ifdef CONFIG_TASKSTATS
76858+int gr_is_taskstats_denied(int pid)
76859+{
76860+ return 0;
76861+}
76862+#endif
76863+
76864+int
76865+gr_acl_is_enabled(void)
76866+{
76867+ return 0;
76868+}
76869+
76870+int
76871+gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
76872+{
76873+ return 0;
76874+}
76875+
76876+void
76877+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
76878+{
76879+ return;
76880+}
76881+
76882+int
76883+gr_handle_rawio(const struct inode *inode)
76884+{
76885+ return 0;
76886+}
76887+
76888+void
76889+gr_acl_handle_psacct(struct task_struct *task, const long code)
76890+{
76891+ return;
76892+}
76893+
76894+int
76895+gr_handle_ptrace(struct task_struct *task, const long request)
76896+{
76897+ return 0;
76898+}
76899+
76900+int
76901+gr_handle_proc_ptrace(struct task_struct *task)
76902+{
76903+ return 0;
76904+}
76905+
76906+int
76907+gr_set_acls(const int type)
76908+{
76909+ return 0;
76910+}
76911+
76912+int
76913+gr_check_hidden_task(const struct task_struct *tsk)
76914+{
76915+ return 0;
76916+}
76917+
76918+int
76919+gr_check_protected_task(const struct task_struct *task)
76920+{
76921+ return 0;
76922+}
76923+
76924+int
76925+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
76926+{
76927+ return 0;
76928+}
76929+
76930+void
76931+gr_copy_label(struct task_struct *tsk)
76932+{
76933+ return;
76934+}
76935+
76936+void
76937+gr_set_pax_flags(struct task_struct *task)
76938+{
76939+ return;
76940+}
76941+
76942+int
76943+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
76944+ const int unsafe_share)
76945+{
76946+ return 0;
76947+}
76948+
76949+void
76950+gr_handle_delete(const ino_t ino, const dev_t dev)
76951+{
76952+ return;
76953+}
76954+
76955+void
76956+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
76957+{
76958+ return;
76959+}
76960+
76961+void
76962+gr_handle_crash(struct task_struct *task, const int sig)
76963+{
76964+ return;
76965+}
76966+
76967+int
76968+gr_check_crash_exec(const struct file *filp)
76969+{
76970+ return 0;
76971+}
76972+
76973+int
76974+gr_check_crash_uid(const kuid_t uid)
76975+{
76976+ return 0;
76977+}
76978+
76979+void
76980+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
76981+ struct dentry *old_dentry,
76982+ struct dentry *new_dentry,
76983+ struct vfsmount *mnt, const __u8 replace, unsigned int flags)
76984+{
76985+ return;
76986+}
76987+
76988+int
76989+gr_search_socket(const int family, const int type, const int protocol)
76990+{
76991+ return 1;
76992+}
76993+
76994+int
76995+gr_search_connectbind(const int mode, const struct socket *sock,
76996+ const struct sockaddr_in *addr)
76997+{
76998+ return 0;
76999+}
77000+
77001+void
77002+gr_handle_alertkill(struct task_struct *task)
77003+{
77004+ return;
77005+}
77006+
77007+__u32
77008+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
77009+{
77010+ return 1;
77011+}
77012+
77013+__u32
77014+gr_acl_handle_hidden_file(const struct dentry * dentry,
77015+ const struct vfsmount * mnt)
77016+{
77017+ return 1;
77018+}
77019+
77020+__u32
77021+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
77022+ int acc_mode)
77023+{
77024+ return 1;
77025+}
77026+
77027+__u32
77028+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
77029+{
77030+ return 1;
77031+}
77032+
77033+__u32
77034+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
77035+{
77036+ return 1;
77037+}
77038+
77039+int
77040+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
77041+ unsigned int *vm_flags)
77042+{
77043+ return 1;
77044+}
77045+
77046+__u32
77047+gr_acl_handle_truncate(const struct dentry * dentry,
77048+ const struct vfsmount * mnt)
77049+{
77050+ return 1;
77051+}
77052+
77053+__u32
77054+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
77055+{
77056+ return 1;
77057+}
77058+
77059+__u32
77060+gr_acl_handle_access(const struct dentry * dentry,
77061+ const struct vfsmount * mnt, const int fmode)
77062+{
77063+ return 1;
77064+}
77065+
77066+__u32
77067+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
77068+ umode_t *mode)
77069+{
77070+ return 1;
77071+}
77072+
77073+__u32
77074+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
77075+{
77076+ return 1;
77077+}
77078+
77079+__u32
77080+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
77081+{
77082+ return 1;
77083+}
77084+
77085+__u32
77086+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
77087+{
77088+ return 1;
77089+}
77090+
77091+void
77092+grsecurity_init(void)
77093+{
77094+ return;
77095+}
77096+
77097+umode_t gr_acl_umask(void)
77098+{
77099+ return 0;
77100+}
77101+
77102+__u32
77103+gr_acl_handle_mknod(const struct dentry * new_dentry,
77104+ const struct dentry * parent_dentry,
77105+ const struct vfsmount * parent_mnt,
77106+ const int mode)
77107+{
77108+ return 1;
77109+}
77110+
77111+__u32
77112+gr_acl_handle_mkdir(const struct dentry * new_dentry,
77113+ const struct dentry * parent_dentry,
77114+ const struct vfsmount * parent_mnt)
77115+{
77116+ return 1;
77117+}
77118+
77119+__u32
77120+gr_acl_handle_symlink(const struct dentry * new_dentry,
77121+ const struct dentry * parent_dentry,
77122+ const struct vfsmount * parent_mnt, const struct filename *from)
77123+{
77124+ return 1;
77125+}
77126+
77127+__u32
77128+gr_acl_handle_link(const struct dentry * new_dentry,
77129+ const struct dentry * parent_dentry,
77130+ const struct vfsmount * parent_mnt,
77131+ const struct dentry * old_dentry,
77132+ const struct vfsmount * old_mnt, const struct filename *to)
77133+{
77134+ return 1;
77135+}
77136+
77137+int
77138+gr_acl_handle_rename(const struct dentry *new_dentry,
77139+ const struct dentry *parent_dentry,
77140+ const struct vfsmount *parent_mnt,
77141+ const struct dentry *old_dentry,
77142+ const struct inode *old_parent_inode,
77143+ const struct vfsmount *old_mnt, const struct filename *newname,
77144+ unsigned int flags)
77145+{
77146+ return 0;
77147+}
77148+
77149+int
77150+gr_acl_handle_filldir(const struct file *file, const char *name,
77151+ const int namelen, const ino_t ino)
77152+{
77153+ return 1;
77154+}
77155+
77156+int
77157+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
77158+ const u64 shm_createtime, const kuid_t cuid, const int shmid)
77159+{
77160+ return 1;
77161+}
77162+
77163+int
77164+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
77165+{
77166+ return 0;
77167+}
77168+
77169+int
77170+gr_search_accept(const struct socket *sock)
77171+{
77172+ return 0;
77173+}
77174+
77175+int
77176+gr_search_listen(const struct socket *sock)
77177+{
77178+ return 0;
77179+}
77180+
77181+int
77182+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
77183+{
77184+ return 0;
77185+}
77186+
77187+__u32
77188+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
77189+{
77190+ return 1;
77191+}
77192+
77193+__u32
77194+gr_acl_handle_creat(const struct dentry * dentry,
77195+ const struct dentry * p_dentry,
77196+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
77197+ const int imode)
77198+{
77199+ return 1;
77200+}
77201+
77202+void
77203+gr_acl_handle_exit(void)
77204+{
77205+ return;
77206+}
77207+
77208+int
77209+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
77210+{
77211+ return 1;
77212+}
77213+
77214+void
77215+gr_set_role_label(const kuid_t uid, const kgid_t gid)
77216+{
77217+ return;
77218+}
77219+
77220+int
77221+gr_acl_handle_procpidmem(const struct task_struct *task)
77222+{
77223+ return 0;
77224+}
77225+
77226+int
77227+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
77228+{
77229+ return 0;
77230+}
77231+
77232+int
77233+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
77234+{
77235+ return 0;
77236+}
77237+
77238+int
77239+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
77240+{
77241+ return 0;
77242+}
77243+
77244+int
77245+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
77246+{
77247+ return 0;
77248+}
77249+
77250+int gr_acl_enable_at_secure(void)
77251+{
77252+ return 0;
77253+}
77254+
77255+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
77256+{
77257+ return dentry->d_sb->s_dev;
77258+}
77259+
77260+void gr_put_exec_file(struct task_struct *task)
77261+{
77262+ return;
77263+}
77264+
77265+#ifdef CONFIG_SECURITY
77266+EXPORT_SYMBOL_GPL(gr_check_user_change);
77267+EXPORT_SYMBOL_GPL(gr_check_group_change);
77268+#endif
77269diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
77270new file mode 100644
77271index 0000000..14638ff
77272--- /dev/null
77273+++ b/grsecurity/grsec_exec.c
77274@@ -0,0 +1,188 @@
77275+#include <linux/kernel.h>
77276+#include <linux/sched.h>
77277+#include <linux/file.h>
77278+#include <linux/binfmts.h>
77279+#include <linux/fs.h>
77280+#include <linux/types.h>
77281+#include <linux/grdefs.h>
77282+#include <linux/grsecurity.h>
77283+#include <linux/grinternal.h>
77284+#include <linux/capability.h>
77285+#include <linux/module.h>
77286+#include <linux/compat.h>
77287+
77288+#include <asm/uaccess.h>
77289+
77290+#ifdef CONFIG_GRKERNSEC_EXECLOG
77291+static char gr_exec_arg_buf[132];
77292+static DEFINE_MUTEX(gr_exec_arg_mutex);
77293+#endif
77294+
77295+struct user_arg_ptr {
77296+#ifdef CONFIG_COMPAT
77297+ bool is_compat;
77298+#endif
77299+ union {
77300+ const char __user *const __user *native;
77301+#ifdef CONFIG_COMPAT
77302+ const compat_uptr_t __user *compat;
77303+#endif
77304+ } ptr;
77305+};
77306+
77307+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
77308+
77309+void
77310+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
77311+{
77312+#ifdef CONFIG_GRKERNSEC_EXECLOG
77313+ char *grarg = gr_exec_arg_buf;
77314+ unsigned int i, x, execlen = 0;
77315+ char c;
77316+
77317+ if (!((grsec_enable_execlog && grsec_enable_group &&
77318+ in_group_p(grsec_audit_gid))
77319+ || (grsec_enable_execlog && !grsec_enable_group)))
77320+ return;
77321+
77322+ mutex_lock(&gr_exec_arg_mutex);
77323+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
77324+
77325+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
77326+ const char __user *p;
77327+ unsigned int len;
77328+
77329+ p = get_user_arg_ptr(argv, i);
77330+ if (IS_ERR(p))
77331+ goto log;
77332+
77333+ len = strnlen_user(p, 128 - execlen);
77334+ if (len > 128 - execlen)
77335+ len = 128 - execlen;
77336+ else if (len > 0)
77337+ len--;
77338+ if (copy_from_user(grarg + execlen, p, len))
77339+ goto log;
77340+
77341+ /* rewrite unprintable characters */
77342+ for (x = 0; x < len; x++) {
77343+ c = *(grarg + execlen + x);
77344+ if (c < 32 || c > 126)
77345+ *(grarg + execlen + x) = ' ';
77346+ }
77347+
77348+ execlen += len;
77349+ *(grarg + execlen) = ' ';
77350+ *(grarg + execlen + 1) = '\0';
77351+ execlen++;
77352+ }
77353+
77354+ log:
77355+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
77356+ bprm->file->f_path.mnt, grarg);
77357+ mutex_unlock(&gr_exec_arg_mutex);
77358+#endif
77359+ return;
77360+}
77361+
77362+#ifdef CONFIG_GRKERNSEC
77363+extern int gr_acl_is_capable(const int cap);
77364+extern int gr_acl_is_capable_nolog(const int cap);
77365+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77366+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
77367+extern int gr_chroot_is_capable(const int cap);
77368+extern int gr_chroot_is_capable_nolog(const int cap);
77369+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
77370+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
77371+#endif
77372+
77373+const char *captab_log[] = {
77374+ "CAP_CHOWN",
77375+ "CAP_DAC_OVERRIDE",
77376+ "CAP_DAC_READ_SEARCH",
77377+ "CAP_FOWNER",
77378+ "CAP_FSETID",
77379+ "CAP_KILL",
77380+ "CAP_SETGID",
77381+ "CAP_SETUID",
77382+ "CAP_SETPCAP",
77383+ "CAP_LINUX_IMMUTABLE",
77384+ "CAP_NET_BIND_SERVICE",
77385+ "CAP_NET_BROADCAST",
77386+ "CAP_NET_ADMIN",
77387+ "CAP_NET_RAW",
77388+ "CAP_IPC_LOCK",
77389+ "CAP_IPC_OWNER",
77390+ "CAP_SYS_MODULE",
77391+ "CAP_SYS_RAWIO",
77392+ "CAP_SYS_CHROOT",
77393+ "CAP_SYS_PTRACE",
77394+ "CAP_SYS_PACCT",
77395+ "CAP_SYS_ADMIN",
77396+ "CAP_SYS_BOOT",
77397+ "CAP_SYS_NICE",
77398+ "CAP_SYS_RESOURCE",
77399+ "CAP_SYS_TIME",
77400+ "CAP_SYS_TTY_CONFIG",
77401+ "CAP_MKNOD",
77402+ "CAP_LEASE",
77403+ "CAP_AUDIT_WRITE",
77404+ "CAP_AUDIT_CONTROL",
77405+ "CAP_SETFCAP",
77406+ "CAP_MAC_OVERRIDE",
77407+ "CAP_MAC_ADMIN",
77408+ "CAP_SYSLOG",
77409+ "CAP_WAKE_ALARM",
77410+ "CAP_BLOCK_SUSPEND"
77411+};
77412+
77413+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
77414+
77415+int gr_is_capable(const int cap)
77416+{
77417+#ifdef CONFIG_GRKERNSEC
77418+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
77419+ return 1;
77420+ return 0;
77421+#else
77422+ return 1;
77423+#endif
77424+}
77425+
77426+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
77427+{
77428+#ifdef CONFIG_GRKERNSEC
77429+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
77430+ return 1;
77431+ return 0;
77432+#else
77433+ return 1;
77434+#endif
77435+}
77436+
77437+int gr_is_capable_nolog(const int cap)
77438+{
77439+#ifdef CONFIG_GRKERNSEC
77440+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
77441+ return 1;
77442+ return 0;
77443+#else
77444+ return 1;
77445+#endif
77446+}
77447+
77448+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
77449+{
77450+#ifdef CONFIG_GRKERNSEC
77451+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
77452+ return 1;
77453+ return 0;
77454+#else
77455+ return 1;
77456+#endif
77457+}
77458+
77459+EXPORT_SYMBOL_GPL(gr_is_capable);
77460+EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
77461+EXPORT_SYMBOL_GPL(gr_task_is_capable);
77462+EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
77463diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
77464new file mode 100644
77465index 0000000..06cc6ea
77466--- /dev/null
77467+++ b/grsecurity/grsec_fifo.c
77468@@ -0,0 +1,24 @@
77469+#include <linux/kernel.h>
77470+#include <linux/sched.h>
77471+#include <linux/fs.h>
77472+#include <linux/file.h>
77473+#include <linux/grinternal.h>
77474+
77475+int
77476+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
77477+ const struct dentry *dir, const int flag, const int acc_mode)
77478+{
77479+#ifdef CONFIG_GRKERNSEC_FIFO
77480+ const struct cred *cred = current_cred();
77481+
77482+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
77483+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
77484+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
77485+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
77486+ if (!inode_permission(dentry->d_inode, acc_mode))
77487+ 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));
77488+ return -EACCES;
77489+ }
77490+#endif
77491+ return 0;
77492+}
77493diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
77494new file mode 100644
77495index 0000000..8ca18bf
77496--- /dev/null
77497+++ b/grsecurity/grsec_fork.c
77498@@ -0,0 +1,23 @@
77499+#include <linux/kernel.h>
77500+#include <linux/sched.h>
77501+#include <linux/grsecurity.h>
77502+#include <linux/grinternal.h>
77503+#include <linux/errno.h>
77504+
77505+void
77506+gr_log_forkfail(const int retval)
77507+{
77508+#ifdef CONFIG_GRKERNSEC_FORKFAIL
77509+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
77510+ switch (retval) {
77511+ case -EAGAIN:
77512+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
77513+ break;
77514+ case -ENOMEM:
77515+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
77516+ break;
77517+ }
77518+ }
77519+#endif
77520+ return;
77521+}
77522diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
77523new file mode 100644
77524index 0000000..b7cb191
77525--- /dev/null
77526+++ b/grsecurity/grsec_init.c
77527@@ -0,0 +1,286 @@
77528+#include <linux/kernel.h>
77529+#include <linux/sched.h>
77530+#include <linux/mm.h>
77531+#include <linux/gracl.h>
77532+#include <linux/slab.h>
77533+#include <linux/vmalloc.h>
77534+#include <linux/percpu.h>
77535+#include <linux/module.h>
77536+
77537+int grsec_enable_ptrace_readexec;
77538+int grsec_enable_setxid;
77539+int grsec_enable_symlinkown;
77540+kgid_t grsec_symlinkown_gid;
77541+int grsec_enable_brute;
77542+int grsec_enable_link;
77543+int grsec_enable_dmesg;
77544+int grsec_enable_harden_ptrace;
77545+int grsec_enable_harden_ipc;
77546+int grsec_enable_fifo;
77547+int grsec_enable_execlog;
77548+int grsec_enable_signal;
77549+int grsec_enable_forkfail;
77550+int grsec_enable_audit_ptrace;
77551+int grsec_enable_time;
77552+int grsec_enable_group;
77553+kgid_t grsec_audit_gid;
77554+int grsec_enable_chdir;
77555+int grsec_enable_mount;
77556+int grsec_enable_rofs;
77557+int grsec_deny_new_usb;
77558+int grsec_enable_chroot_findtask;
77559+int grsec_enable_chroot_mount;
77560+int grsec_enable_chroot_shmat;
77561+int grsec_enable_chroot_fchdir;
77562+int grsec_enable_chroot_double;
77563+int grsec_enable_chroot_pivot;
77564+int grsec_enable_chroot_chdir;
77565+int grsec_enable_chroot_chmod;
77566+int grsec_enable_chroot_mknod;
77567+int grsec_enable_chroot_nice;
77568+int grsec_enable_chroot_execlog;
77569+int grsec_enable_chroot_caps;
77570+int grsec_enable_chroot_sysctl;
77571+int grsec_enable_chroot_unix;
77572+int grsec_enable_tpe;
77573+kgid_t grsec_tpe_gid;
77574+int grsec_enable_blackhole;
77575+#ifdef CONFIG_IPV6_MODULE
77576+EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
77577+#endif
77578+int grsec_lastack_retries;
77579+int grsec_enable_tpe_all;
77580+int grsec_enable_tpe_invert;
77581+int grsec_enable_socket_all;
77582+kgid_t grsec_socket_all_gid;
77583+int grsec_enable_socket_client;
77584+kgid_t grsec_socket_client_gid;
77585+int grsec_enable_socket_server;
77586+kgid_t grsec_socket_server_gid;
77587+int grsec_resource_logging;
77588+int grsec_disable_privio;
77589+int grsec_enable_log_rwxmaps;
77590+int grsec_lock;
77591+
77592+DEFINE_SPINLOCK(grsec_alert_lock);
77593+unsigned long grsec_alert_wtime = 0;
77594+unsigned long grsec_alert_fyet = 0;
77595+
77596+DEFINE_SPINLOCK(grsec_audit_lock);
77597+
77598+DEFINE_RWLOCK(grsec_exec_file_lock);
77599+
77600+char *gr_shared_page[4];
77601+
77602+char *gr_alert_log_fmt;
77603+char *gr_audit_log_fmt;
77604+char *gr_alert_log_buf;
77605+char *gr_audit_log_buf;
77606+
77607+extern struct gr_arg *gr_usermode;
77608+extern unsigned char *gr_system_salt;
77609+extern unsigned char *gr_system_sum;
77610+
77611+void __init
77612+grsecurity_init(void)
77613+{
77614+ int j;
77615+ /* create the per-cpu shared pages */
77616+
77617+#ifdef CONFIG_X86
77618+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
77619+#endif
77620+
77621+ for (j = 0; j < 4; j++) {
77622+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
77623+ if (gr_shared_page[j] == NULL) {
77624+ panic("Unable to allocate grsecurity shared page");
77625+ return;
77626+ }
77627+ }
77628+
77629+ /* allocate log buffers */
77630+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
77631+ if (!gr_alert_log_fmt) {
77632+ panic("Unable to allocate grsecurity alert log format buffer");
77633+ return;
77634+ }
77635+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
77636+ if (!gr_audit_log_fmt) {
77637+ panic("Unable to allocate grsecurity audit log format buffer");
77638+ return;
77639+ }
77640+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77641+ if (!gr_alert_log_buf) {
77642+ panic("Unable to allocate grsecurity alert log buffer");
77643+ return;
77644+ }
77645+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77646+ if (!gr_audit_log_buf) {
77647+ panic("Unable to allocate grsecurity audit log buffer");
77648+ return;
77649+ }
77650+
77651+ /* allocate memory for authentication structure */
77652+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
77653+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
77654+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
77655+
77656+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
77657+ panic("Unable to allocate grsecurity authentication structure");
77658+ return;
77659+ }
77660+
77661+#ifdef CONFIG_GRKERNSEC_IO
77662+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
77663+ grsec_disable_privio = 1;
77664+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77665+ grsec_disable_privio = 1;
77666+#else
77667+ grsec_disable_privio = 0;
77668+#endif
77669+#endif
77670+
77671+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
77672+ /* for backward compatibility, tpe_invert always defaults to on if
77673+ enabled in the kernel
77674+ */
77675+ grsec_enable_tpe_invert = 1;
77676+#endif
77677+
77678+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77679+#ifndef CONFIG_GRKERNSEC_SYSCTL
77680+ grsec_lock = 1;
77681+#endif
77682+
77683+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77684+ grsec_enable_log_rwxmaps = 1;
77685+#endif
77686+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
77687+ grsec_enable_group = 1;
77688+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
77689+#endif
77690+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
77691+ grsec_enable_ptrace_readexec = 1;
77692+#endif
77693+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
77694+ grsec_enable_chdir = 1;
77695+#endif
77696+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
77697+ grsec_enable_harden_ptrace = 1;
77698+#endif
77699+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77700+ grsec_enable_harden_ipc = 1;
77701+#endif
77702+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77703+ grsec_enable_mount = 1;
77704+#endif
77705+#ifdef CONFIG_GRKERNSEC_LINK
77706+ grsec_enable_link = 1;
77707+#endif
77708+#ifdef CONFIG_GRKERNSEC_BRUTE
77709+ grsec_enable_brute = 1;
77710+#endif
77711+#ifdef CONFIG_GRKERNSEC_DMESG
77712+ grsec_enable_dmesg = 1;
77713+#endif
77714+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77715+ grsec_enable_blackhole = 1;
77716+ grsec_lastack_retries = 4;
77717+#endif
77718+#ifdef CONFIG_GRKERNSEC_FIFO
77719+ grsec_enable_fifo = 1;
77720+#endif
77721+#ifdef CONFIG_GRKERNSEC_EXECLOG
77722+ grsec_enable_execlog = 1;
77723+#endif
77724+#ifdef CONFIG_GRKERNSEC_SETXID
77725+ grsec_enable_setxid = 1;
77726+#endif
77727+#ifdef CONFIG_GRKERNSEC_SIGNAL
77728+ grsec_enable_signal = 1;
77729+#endif
77730+#ifdef CONFIG_GRKERNSEC_FORKFAIL
77731+ grsec_enable_forkfail = 1;
77732+#endif
77733+#ifdef CONFIG_GRKERNSEC_TIME
77734+ grsec_enable_time = 1;
77735+#endif
77736+#ifdef CONFIG_GRKERNSEC_RESLOG
77737+ grsec_resource_logging = 1;
77738+#endif
77739+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77740+ grsec_enable_chroot_findtask = 1;
77741+#endif
77742+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
77743+ grsec_enable_chroot_unix = 1;
77744+#endif
77745+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
77746+ grsec_enable_chroot_mount = 1;
77747+#endif
77748+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
77749+ grsec_enable_chroot_fchdir = 1;
77750+#endif
77751+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
77752+ grsec_enable_chroot_shmat = 1;
77753+#endif
77754+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
77755+ grsec_enable_audit_ptrace = 1;
77756+#endif
77757+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
77758+ grsec_enable_chroot_double = 1;
77759+#endif
77760+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
77761+ grsec_enable_chroot_pivot = 1;
77762+#endif
77763+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
77764+ grsec_enable_chroot_chdir = 1;
77765+#endif
77766+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
77767+ grsec_enable_chroot_chmod = 1;
77768+#endif
77769+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
77770+ grsec_enable_chroot_mknod = 1;
77771+#endif
77772+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
77773+ grsec_enable_chroot_nice = 1;
77774+#endif
77775+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
77776+ grsec_enable_chroot_execlog = 1;
77777+#endif
77778+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77779+ grsec_enable_chroot_caps = 1;
77780+#endif
77781+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
77782+ grsec_enable_chroot_sysctl = 1;
77783+#endif
77784+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77785+ grsec_enable_symlinkown = 1;
77786+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
77787+#endif
77788+#ifdef CONFIG_GRKERNSEC_TPE
77789+ grsec_enable_tpe = 1;
77790+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
77791+#ifdef CONFIG_GRKERNSEC_TPE_ALL
77792+ grsec_enable_tpe_all = 1;
77793+#endif
77794+#endif
77795+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
77796+ grsec_enable_socket_all = 1;
77797+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
77798+#endif
77799+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
77800+ grsec_enable_socket_client = 1;
77801+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
77802+#endif
77803+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
77804+ grsec_enable_socket_server = 1;
77805+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
77806+#endif
77807+#endif
77808+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
77809+ grsec_deny_new_usb = 1;
77810+#endif
77811+
77812+ return;
77813+}
77814diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
77815new file mode 100644
77816index 0000000..1773300
77817--- /dev/null
77818+++ b/grsecurity/grsec_ipc.c
77819@@ -0,0 +1,48 @@
77820+#include <linux/kernel.h>
77821+#include <linux/mm.h>
77822+#include <linux/sched.h>
77823+#include <linux/file.h>
77824+#include <linux/ipc.h>
77825+#include <linux/ipc_namespace.h>
77826+#include <linux/grsecurity.h>
77827+#include <linux/grinternal.h>
77828+
77829+int
77830+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
77831+{
77832+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77833+ int write;
77834+ int orig_granted_mode;
77835+ kuid_t euid;
77836+ kgid_t egid;
77837+
77838+ if (!grsec_enable_harden_ipc)
77839+ return 1;
77840+
77841+ euid = current_euid();
77842+ egid = current_egid();
77843+
77844+ write = requested_mode & 00002;
77845+ orig_granted_mode = ipcp->mode;
77846+
77847+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
77848+ orig_granted_mode >>= 6;
77849+ else {
77850+ /* if likely wrong permissions, lock to user */
77851+ if (orig_granted_mode & 0007)
77852+ orig_granted_mode = 0;
77853+ /* otherwise do a egid-only check */
77854+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
77855+ orig_granted_mode >>= 3;
77856+ /* otherwise, no access */
77857+ else
77858+ orig_granted_mode = 0;
77859+ }
77860+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
77861+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
77862+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
77863+ return 0;
77864+ }
77865+#endif
77866+ return 1;
77867+}
77868diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
77869new file mode 100644
77870index 0000000..5e05e20
77871--- /dev/null
77872+++ b/grsecurity/grsec_link.c
77873@@ -0,0 +1,58 @@
77874+#include <linux/kernel.h>
77875+#include <linux/sched.h>
77876+#include <linux/fs.h>
77877+#include <linux/file.h>
77878+#include <linux/grinternal.h>
77879+
77880+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
77881+{
77882+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77883+ const struct inode *link_inode = link->dentry->d_inode;
77884+
77885+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
77886+ /* ignore root-owned links, e.g. /proc/self */
77887+ gr_is_global_nonroot(link_inode->i_uid) && target &&
77888+ !uid_eq(link_inode->i_uid, target->i_uid)) {
77889+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
77890+ return 1;
77891+ }
77892+#endif
77893+ return 0;
77894+}
77895+
77896+int
77897+gr_handle_follow_link(const struct inode *parent,
77898+ const struct inode *inode,
77899+ const struct dentry *dentry, const struct vfsmount *mnt)
77900+{
77901+#ifdef CONFIG_GRKERNSEC_LINK
77902+ const struct cred *cred = current_cred();
77903+
77904+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
77905+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
77906+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
77907+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
77908+ return -EACCES;
77909+ }
77910+#endif
77911+ return 0;
77912+}
77913+
77914+int
77915+gr_handle_hardlink(const struct dentry *dentry,
77916+ const struct vfsmount *mnt,
77917+ struct inode *inode, const int mode, const struct filename *to)
77918+{
77919+#ifdef CONFIG_GRKERNSEC_LINK
77920+ const struct cred *cred = current_cred();
77921+
77922+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
77923+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
77924+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
77925+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
77926+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
77927+ return -EPERM;
77928+ }
77929+#endif
77930+ return 0;
77931+}
77932diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
77933new file mode 100644
77934index 0000000..dbe0a6b
77935--- /dev/null
77936+++ b/grsecurity/grsec_log.c
77937@@ -0,0 +1,341 @@
77938+#include <linux/kernel.h>
77939+#include <linux/sched.h>
77940+#include <linux/file.h>
77941+#include <linux/tty.h>
77942+#include <linux/fs.h>
77943+#include <linux/mm.h>
77944+#include <linux/grinternal.h>
77945+
77946+#ifdef CONFIG_TREE_PREEMPT_RCU
77947+#define DISABLE_PREEMPT() preempt_disable()
77948+#define ENABLE_PREEMPT() preempt_enable()
77949+#else
77950+#define DISABLE_PREEMPT()
77951+#define ENABLE_PREEMPT()
77952+#endif
77953+
77954+#define BEGIN_LOCKS(x) \
77955+ DISABLE_PREEMPT(); \
77956+ rcu_read_lock(); \
77957+ read_lock(&tasklist_lock); \
77958+ read_lock(&grsec_exec_file_lock); \
77959+ if (x != GR_DO_AUDIT) \
77960+ spin_lock(&grsec_alert_lock); \
77961+ else \
77962+ spin_lock(&grsec_audit_lock)
77963+
77964+#define END_LOCKS(x) \
77965+ if (x != GR_DO_AUDIT) \
77966+ spin_unlock(&grsec_alert_lock); \
77967+ else \
77968+ spin_unlock(&grsec_audit_lock); \
77969+ read_unlock(&grsec_exec_file_lock); \
77970+ read_unlock(&tasklist_lock); \
77971+ rcu_read_unlock(); \
77972+ ENABLE_PREEMPT(); \
77973+ if (x == GR_DONT_AUDIT) \
77974+ gr_handle_alertkill(current)
77975+
77976+enum {
77977+ FLOODING,
77978+ NO_FLOODING
77979+};
77980+
77981+extern char *gr_alert_log_fmt;
77982+extern char *gr_audit_log_fmt;
77983+extern char *gr_alert_log_buf;
77984+extern char *gr_audit_log_buf;
77985+
77986+static int gr_log_start(int audit)
77987+{
77988+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
77989+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
77990+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77991+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
77992+ unsigned long curr_secs = get_seconds();
77993+
77994+ if (audit == GR_DO_AUDIT)
77995+ goto set_fmt;
77996+
77997+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
77998+ grsec_alert_wtime = curr_secs;
77999+ grsec_alert_fyet = 0;
78000+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
78001+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
78002+ grsec_alert_fyet++;
78003+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
78004+ grsec_alert_wtime = curr_secs;
78005+ grsec_alert_fyet++;
78006+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
78007+ return FLOODING;
78008+ }
78009+ else return FLOODING;
78010+
78011+set_fmt:
78012+#endif
78013+ memset(buf, 0, PAGE_SIZE);
78014+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
78015+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
78016+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
78017+ } else if (current->signal->curr_ip) {
78018+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
78019+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
78020+ } else if (gr_acl_is_enabled()) {
78021+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
78022+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
78023+ } else {
78024+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
78025+ strcpy(buf, fmt);
78026+ }
78027+
78028+ return NO_FLOODING;
78029+}
78030+
78031+static void gr_log_middle(int audit, const char *msg, va_list ap)
78032+ __attribute__ ((format (printf, 2, 0)));
78033+
78034+static void gr_log_middle(int audit, const char *msg, va_list ap)
78035+{
78036+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
78037+ unsigned int len = strlen(buf);
78038+
78039+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
78040+
78041+ return;
78042+}
78043+
78044+static void gr_log_middle_varargs(int audit, const char *msg, ...)
78045+ __attribute__ ((format (printf, 2, 3)));
78046+
78047+static void gr_log_middle_varargs(int audit, const char *msg, ...)
78048+{
78049+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
78050+ unsigned int len = strlen(buf);
78051+ va_list ap;
78052+
78053+ va_start(ap, msg);
78054+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
78055+ va_end(ap);
78056+
78057+ return;
78058+}
78059+
78060+static void gr_log_end(int audit, int append_default)
78061+{
78062+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
78063+ if (append_default) {
78064+ struct task_struct *task = current;
78065+ struct task_struct *parent = task->real_parent;
78066+ const struct cred *cred = __task_cred(task);
78067+ const struct cred *pcred = __task_cred(parent);
78068+ unsigned int len = strlen(buf);
78069+
78070+ 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));
78071+ }
78072+
78073+ printk("%s\n", buf);
78074+
78075+ return;
78076+}
78077+
78078+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
78079+{
78080+ int logtype;
78081+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
78082+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
78083+ void *voidptr = NULL;
78084+ int num1 = 0, num2 = 0;
78085+ unsigned long ulong1 = 0, ulong2 = 0;
78086+ struct dentry *dentry = NULL;
78087+ struct vfsmount *mnt = NULL;
78088+ struct file *file = NULL;
78089+ struct task_struct *task = NULL;
78090+ struct vm_area_struct *vma = NULL;
78091+ const struct cred *cred, *pcred;
78092+ va_list ap;
78093+
78094+ BEGIN_LOCKS(audit);
78095+ logtype = gr_log_start(audit);
78096+ if (logtype == FLOODING) {
78097+ END_LOCKS(audit);
78098+ return;
78099+ }
78100+ va_start(ap, argtypes);
78101+ switch (argtypes) {
78102+ case GR_TTYSNIFF:
78103+ task = va_arg(ap, struct task_struct *);
78104+ 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));
78105+ break;
78106+ case GR_SYSCTL_HIDDEN:
78107+ str1 = va_arg(ap, char *);
78108+ gr_log_middle_varargs(audit, msg, result, str1);
78109+ break;
78110+ case GR_RBAC:
78111+ dentry = va_arg(ap, struct dentry *);
78112+ mnt = va_arg(ap, struct vfsmount *);
78113+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
78114+ break;
78115+ case GR_RBAC_STR:
78116+ dentry = va_arg(ap, struct dentry *);
78117+ mnt = va_arg(ap, struct vfsmount *);
78118+ str1 = va_arg(ap, char *);
78119+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
78120+ break;
78121+ case GR_STR_RBAC:
78122+ str1 = va_arg(ap, char *);
78123+ dentry = va_arg(ap, struct dentry *);
78124+ mnt = va_arg(ap, struct vfsmount *);
78125+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
78126+ break;
78127+ case GR_RBAC_MODE2:
78128+ dentry = va_arg(ap, struct dentry *);
78129+ mnt = va_arg(ap, struct vfsmount *);
78130+ str1 = va_arg(ap, char *);
78131+ str2 = va_arg(ap, char *);
78132+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
78133+ break;
78134+ case GR_RBAC_MODE3:
78135+ dentry = va_arg(ap, struct dentry *);
78136+ mnt = va_arg(ap, struct vfsmount *);
78137+ str1 = va_arg(ap, char *);
78138+ str2 = va_arg(ap, char *);
78139+ str3 = va_arg(ap, char *);
78140+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
78141+ break;
78142+ case GR_FILENAME:
78143+ dentry = va_arg(ap, struct dentry *);
78144+ mnt = va_arg(ap, struct vfsmount *);
78145+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
78146+ break;
78147+ case GR_STR_FILENAME:
78148+ str1 = va_arg(ap, char *);
78149+ dentry = va_arg(ap, struct dentry *);
78150+ mnt = va_arg(ap, struct vfsmount *);
78151+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
78152+ break;
78153+ case GR_FILENAME_STR:
78154+ dentry = va_arg(ap, struct dentry *);
78155+ mnt = va_arg(ap, struct vfsmount *);
78156+ str1 = va_arg(ap, char *);
78157+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
78158+ break;
78159+ case GR_FILENAME_TWO_INT:
78160+ dentry = va_arg(ap, struct dentry *);
78161+ mnt = va_arg(ap, struct vfsmount *);
78162+ num1 = va_arg(ap, int);
78163+ num2 = va_arg(ap, int);
78164+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
78165+ break;
78166+ case GR_FILENAME_TWO_INT_STR:
78167+ dentry = va_arg(ap, struct dentry *);
78168+ mnt = va_arg(ap, struct vfsmount *);
78169+ num1 = va_arg(ap, int);
78170+ num2 = va_arg(ap, int);
78171+ str1 = va_arg(ap, char *);
78172+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
78173+ break;
78174+ case GR_TEXTREL:
78175+ file = va_arg(ap, struct file *);
78176+ ulong1 = va_arg(ap, unsigned long);
78177+ ulong2 = va_arg(ap, unsigned long);
78178+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
78179+ break;
78180+ case GR_PTRACE:
78181+ task = va_arg(ap, struct task_struct *);
78182+ 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));
78183+ break;
78184+ case GR_RESOURCE:
78185+ task = va_arg(ap, struct task_struct *);
78186+ cred = __task_cred(task);
78187+ pcred = __task_cred(task->real_parent);
78188+ ulong1 = va_arg(ap, unsigned long);
78189+ str1 = va_arg(ap, char *);
78190+ ulong2 = va_arg(ap, unsigned long);
78191+ 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));
78192+ break;
78193+ case GR_CAP:
78194+ task = va_arg(ap, struct task_struct *);
78195+ cred = __task_cred(task);
78196+ pcred = __task_cred(task->real_parent);
78197+ str1 = va_arg(ap, char *);
78198+ 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));
78199+ break;
78200+ case GR_SIG:
78201+ str1 = va_arg(ap, char *);
78202+ voidptr = va_arg(ap, void *);
78203+ gr_log_middle_varargs(audit, msg, str1, voidptr);
78204+ break;
78205+ case GR_SIG2:
78206+ task = va_arg(ap, struct task_struct *);
78207+ cred = __task_cred(task);
78208+ pcred = __task_cred(task->real_parent);
78209+ num1 = va_arg(ap, int);
78210+ 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));
78211+ break;
78212+ case GR_CRASH1:
78213+ task = va_arg(ap, struct task_struct *);
78214+ cred = __task_cred(task);
78215+ pcred = __task_cred(task->real_parent);
78216+ ulong1 = va_arg(ap, unsigned long);
78217+ 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);
78218+ break;
78219+ case GR_CRASH2:
78220+ task = va_arg(ap, struct task_struct *);
78221+ cred = __task_cred(task);
78222+ pcred = __task_cred(task->real_parent);
78223+ ulong1 = va_arg(ap, unsigned long);
78224+ 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);
78225+ break;
78226+ case GR_RWXMAP:
78227+ file = va_arg(ap, struct file *);
78228+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
78229+ break;
78230+ case GR_RWXMAPVMA:
78231+ vma = va_arg(ap, struct vm_area_struct *);
78232+ if (vma->vm_file)
78233+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
78234+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
78235+ str1 = "<stack>";
78236+ else if (vma->vm_start <= current->mm->brk &&
78237+ vma->vm_end >= current->mm->start_brk)
78238+ str1 = "<heap>";
78239+ else
78240+ str1 = "<anonymous mapping>";
78241+ gr_log_middle_varargs(audit, msg, str1);
78242+ break;
78243+ case GR_PSACCT:
78244+ {
78245+ unsigned int wday, cday;
78246+ __u8 whr, chr;
78247+ __u8 wmin, cmin;
78248+ __u8 wsec, csec;
78249+ char cur_tty[64] = { 0 };
78250+ char parent_tty[64] = { 0 };
78251+
78252+ task = va_arg(ap, struct task_struct *);
78253+ wday = va_arg(ap, unsigned int);
78254+ cday = va_arg(ap, unsigned int);
78255+ whr = va_arg(ap, int);
78256+ chr = va_arg(ap, int);
78257+ wmin = va_arg(ap, int);
78258+ cmin = va_arg(ap, int);
78259+ wsec = va_arg(ap, int);
78260+ csec = va_arg(ap, int);
78261+ ulong1 = va_arg(ap, unsigned long);
78262+ cred = __task_cred(task);
78263+ pcred = __task_cred(task->real_parent);
78264+
78265+ 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));
78266+ }
78267+ break;
78268+ default:
78269+ gr_log_middle(audit, msg, ap);
78270+ }
78271+ va_end(ap);
78272+ // these don't need DEFAULTSECARGS printed on the end
78273+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
78274+ gr_log_end(audit, 0);
78275+ else
78276+ gr_log_end(audit, 1);
78277+ END_LOCKS(audit);
78278+}
78279diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
78280new file mode 100644
78281index 0000000..0e39d8c
78282--- /dev/null
78283+++ b/grsecurity/grsec_mem.c
78284@@ -0,0 +1,48 @@
78285+#include <linux/kernel.h>
78286+#include <linux/sched.h>
78287+#include <linux/mm.h>
78288+#include <linux/mman.h>
78289+#include <linux/module.h>
78290+#include <linux/grinternal.h>
78291+
78292+void gr_handle_msr_write(void)
78293+{
78294+ gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
78295+ return;
78296+}
78297+EXPORT_SYMBOL_GPL(gr_handle_msr_write);
78298+
78299+void
78300+gr_handle_ioperm(void)
78301+{
78302+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
78303+ return;
78304+}
78305+
78306+void
78307+gr_handle_iopl(void)
78308+{
78309+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
78310+ return;
78311+}
78312+
78313+void
78314+gr_handle_mem_readwrite(u64 from, u64 to)
78315+{
78316+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
78317+ return;
78318+}
78319+
78320+void
78321+gr_handle_vm86(void)
78322+{
78323+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
78324+ return;
78325+}
78326+
78327+void
78328+gr_log_badprocpid(const char *entry)
78329+{
78330+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
78331+ return;
78332+}
78333diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
78334new file mode 100644
78335index 0000000..cd9e124
78336--- /dev/null
78337+++ b/grsecurity/grsec_mount.c
78338@@ -0,0 +1,65 @@
78339+#include <linux/kernel.h>
78340+#include <linux/sched.h>
78341+#include <linux/mount.h>
78342+#include <linux/major.h>
78343+#include <linux/grsecurity.h>
78344+#include <linux/grinternal.h>
78345+
78346+void
78347+gr_log_remount(const char *devname, const int retval)
78348+{
78349+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78350+ if (grsec_enable_mount && (retval >= 0))
78351+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
78352+#endif
78353+ return;
78354+}
78355+
78356+void
78357+gr_log_unmount(const char *devname, const int retval)
78358+{
78359+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78360+ if (grsec_enable_mount && (retval >= 0))
78361+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
78362+#endif
78363+ return;
78364+}
78365+
78366+void
78367+gr_log_mount(const char *from, const char *to, const int retval)
78368+{
78369+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
78370+ if (grsec_enable_mount && (retval >= 0))
78371+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
78372+#endif
78373+ return;
78374+}
78375+
78376+int
78377+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
78378+{
78379+#ifdef CONFIG_GRKERNSEC_ROFS
78380+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
78381+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
78382+ return -EPERM;
78383+ } else
78384+ return 0;
78385+#endif
78386+ return 0;
78387+}
78388+
78389+int
78390+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
78391+{
78392+#ifdef CONFIG_GRKERNSEC_ROFS
78393+ struct inode *inode = dentry->d_inode;
78394+
78395+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
78396+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
78397+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
78398+ return -EPERM;
78399+ } else
78400+ return 0;
78401+#endif
78402+ return 0;
78403+}
78404diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
78405new file mode 100644
78406index 0000000..6ee9d50
78407--- /dev/null
78408+++ b/grsecurity/grsec_pax.c
78409@@ -0,0 +1,45 @@
78410+#include <linux/kernel.h>
78411+#include <linux/sched.h>
78412+#include <linux/mm.h>
78413+#include <linux/file.h>
78414+#include <linux/grinternal.h>
78415+#include <linux/grsecurity.h>
78416+
78417+void
78418+gr_log_textrel(struct vm_area_struct * vma)
78419+{
78420+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78421+ if (grsec_enable_log_rwxmaps)
78422+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
78423+#endif
78424+ return;
78425+}
78426+
78427+void gr_log_ptgnustack(struct file *file)
78428+{
78429+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78430+ if (grsec_enable_log_rwxmaps)
78431+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
78432+#endif
78433+ return;
78434+}
78435+
78436+void
78437+gr_log_rwxmmap(struct file *file)
78438+{
78439+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78440+ if (grsec_enable_log_rwxmaps)
78441+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
78442+#endif
78443+ return;
78444+}
78445+
78446+void
78447+gr_log_rwxmprotect(struct vm_area_struct *vma)
78448+{
78449+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78450+ if (grsec_enable_log_rwxmaps)
78451+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
78452+#endif
78453+ return;
78454+}
78455diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
78456new file mode 100644
78457index 0000000..2005a3a
78458--- /dev/null
78459+++ b/grsecurity/grsec_proc.c
78460@@ -0,0 +1,20 @@
78461+#include <linux/kernel.h>
78462+#include <linux/sched.h>
78463+#include <linux/grsecurity.h>
78464+#include <linux/grinternal.h>
78465+
78466+int gr_proc_is_restricted(void)
78467+{
78468+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78469+ const struct cred *cred = current_cred();
78470+#endif
78471+
78472+#ifdef CONFIG_GRKERNSEC_PROC_USER
78473+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
78474+ return -EACCES;
78475+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78476+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
78477+ return -EACCES;
78478+#endif
78479+ return 0;
78480+}
78481diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
78482new file mode 100644
78483index 0000000..f7f29aa
78484--- /dev/null
78485+++ b/grsecurity/grsec_ptrace.c
78486@@ -0,0 +1,30 @@
78487+#include <linux/kernel.h>
78488+#include <linux/sched.h>
78489+#include <linux/grinternal.h>
78490+#include <linux/security.h>
78491+
78492+void
78493+gr_audit_ptrace(struct task_struct *task)
78494+{
78495+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
78496+ if (grsec_enable_audit_ptrace)
78497+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
78498+#endif
78499+ return;
78500+}
78501+
78502+int
78503+gr_ptrace_readexec(struct file *file, int unsafe_flags)
78504+{
78505+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78506+ const struct dentry *dentry = file->f_path.dentry;
78507+ const struct vfsmount *mnt = file->f_path.mnt;
78508+
78509+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
78510+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
78511+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
78512+ return -EACCES;
78513+ }
78514+#endif
78515+ return 0;
78516+}
78517diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
78518new file mode 100644
78519index 0000000..3860c7e
78520--- /dev/null
78521+++ b/grsecurity/grsec_sig.c
78522@@ -0,0 +1,236 @@
78523+#include <linux/kernel.h>
78524+#include <linux/sched.h>
78525+#include <linux/fs.h>
78526+#include <linux/delay.h>
78527+#include <linux/grsecurity.h>
78528+#include <linux/grinternal.h>
78529+#include <linux/hardirq.h>
78530+
78531+char *signames[] = {
78532+ [SIGSEGV] = "Segmentation fault",
78533+ [SIGILL] = "Illegal instruction",
78534+ [SIGABRT] = "Abort",
78535+ [SIGBUS] = "Invalid alignment/Bus error"
78536+};
78537+
78538+void
78539+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
78540+{
78541+#ifdef CONFIG_GRKERNSEC_SIGNAL
78542+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
78543+ (sig == SIGABRT) || (sig == SIGBUS))) {
78544+ if (task_pid_nr(t) == task_pid_nr(current)) {
78545+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
78546+ } else {
78547+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
78548+ }
78549+ }
78550+#endif
78551+ return;
78552+}
78553+
78554+int
78555+gr_handle_signal(const struct task_struct *p, const int sig)
78556+{
78557+#ifdef CONFIG_GRKERNSEC
78558+ /* ignore the 0 signal for protected task checks */
78559+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
78560+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
78561+ return -EPERM;
78562+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
78563+ return -EPERM;
78564+ }
78565+#endif
78566+ return 0;
78567+}
78568+
78569+#ifdef CONFIG_GRKERNSEC
78570+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
78571+
78572+int gr_fake_force_sig(int sig, struct task_struct *t)
78573+{
78574+ unsigned long int flags;
78575+ int ret, blocked, ignored;
78576+ struct k_sigaction *action;
78577+
78578+ spin_lock_irqsave(&t->sighand->siglock, flags);
78579+ action = &t->sighand->action[sig-1];
78580+ ignored = action->sa.sa_handler == SIG_IGN;
78581+ blocked = sigismember(&t->blocked, sig);
78582+ if (blocked || ignored) {
78583+ action->sa.sa_handler = SIG_DFL;
78584+ if (blocked) {
78585+ sigdelset(&t->blocked, sig);
78586+ recalc_sigpending_and_wake(t);
78587+ }
78588+ }
78589+ if (action->sa.sa_handler == SIG_DFL)
78590+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
78591+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
78592+
78593+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
78594+
78595+ return ret;
78596+}
78597+#endif
78598+
78599+#define GR_USER_BAN_TIME (15 * 60)
78600+#define GR_DAEMON_BRUTE_TIME (30 * 60)
78601+
78602+void gr_handle_brute_attach(int dumpable)
78603+{
78604+#ifdef CONFIG_GRKERNSEC_BRUTE
78605+ struct task_struct *p = current;
78606+ kuid_t uid = GLOBAL_ROOT_UID;
78607+ int daemon = 0;
78608+
78609+ if (!grsec_enable_brute)
78610+ return;
78611+
78612+ rcu_read_lock();
78613+ read_lock(&tasklist_lock);
78614+ read_lock(&grsec_exec_file_lock);
78615+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
78616+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
78617+ p->real_parent->brute = 1;
78618+ daemon = 1;
78619+ } else {
78620+ const struct cred *cred = __task_cred(p), *cred2;
78621+ struct task_struct *tsk, *tsk2;
78622+
78623+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
78624+ struct user_struct *user;
78625+
78626+ uid = cred->uid;
78627+
78628+ /* this is put upon execution past expiration */
78629+ user = find_user(uid);
78630+ if (user == NULL)
78631+ goto unlock;
78632+ user->suid_banned = 1;
78633+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
78634+ if (user->suid_ban_expires == ~0UL)
78635+ user->suid_ban_expires--;
78636+
78637+ /* only kill other threads of the same binary, from the same user */
78638+ do_each_thread(tsk2, tsk) {
78639+ cred2 = __task_cred(tsk);
78640+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
78641+ gr_fake_force_sig(SIGKILL, tsk);
78642+ } while_each_thread(tsk2, tsk);
78643+ }
78644+ }
78645+unlock:
78646+ read_unlock(&grsec_exec_file_lock);
78647+ read_unlock(&tasklist_lock);
78648+ rcu_read_unlock();
78649+
78650+ if (gr_is_global_nonroot(uid))
78651+ 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);
78652+ else if (daemon)
78653+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
78654+
78655+#endif
78656+ return;
78657+}
78658+
78659+void gr_handle_brute_check(void)
78660+{
78661+#ifdef CONFIG_GRKERNSEC_BRUTE
78662+ struct task_struct *p = current;
78663+
78664+ if (unlikely(p->brute)) {
78665+ if (!grsec_enable_brute)
78666+ p->brute = 0;
78667+ else if (time_before(get_seconds(), p->brute_expires))
78668+ msleep(30 * 1000);
78669+ }
78670+#endif
78671+ return;
78672+}
78673+
78674+void gr_handle_kernel_exploit(void)
78675+{
78676+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78677+ const struct cred *cred;
78678+ struct task_struct *tsk, *tsk2;
78679+ struct user_struct *user;
78680+ kuid_t uid;
78681+
78682+ if (in_irq() || in_serving_softirq() || in_nmi())
78683+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
78684+
78685+ uid = current_uid();
78686+
78687+ if (gr_is_global_root(uid))
78688+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
78689+ else {
78690+ /* kill all the processes of this user, hold a reference
78691+ to their creds struct, and prevent them from creating
78692+ another process until system reset
78693+ */
78694+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
78695+ GR_GLOBAL_UID(uid));
78696+ /* we intentionally leak this ref */
78697+ user = get_uid(current->cred->user);
78698+ if (user)
78699+ user->kernel_banned = 1;
78700+
78701+ /* kill all processes of this user */
78702+ read_lock(&tasklist_lock);
78703+ do_each_thread(tsk2, tsk) {
78704+ cred = __task_cred(tsk);
78705+ if (uid_eq(cred->uid, uid))
78706+ gr_fake_force_sig(SIGKILL, tsk);
78707+ } while_each_thread(tsk2, tsk);
78708+ read_unlock(&tasklist_lock);
78709+ }
78710+#endif
78711+}
78712+
78713+#ifdef CONFIG_GRKERNSEC_BRUTE
78714+static bool suid_ban_expired(struct user_struct *user)
78715+{
78716+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
78717+ user->suid_banned = 0;
78718+ user->suid_ban_expires = 0;
78719+ free_uid(user);
78720+ return true;
78721+ }
78722+
78723+ return false;
78724+}
78725+#endif
78726+
78727+int gr_process_kernel_exec_ban(void)
78728+{
78729+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78730+ if (unlikely(current->cred->user->kernel_banned))
78731+ return -EPERM;
78732+#endif
78733+ return 0;
78734+}
78735+
78736+int gr_process_kernel_setuid_ban(struct user_struct *user)
78737+{
78738+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78739+ if (unlikely(user->kernel_banned))
78740+ gr_fake_force_sig(SIGKILL, current);
78741+#endif
78742+ return 0;
78743+}
78744+
78745+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
78746+{
78747+#ifdef CONFIG_GRKERNSEC_BRUTE
78748+ struct user_struct *user = current->cred->user;
78749+ if (unlikely(user->suid_banned)) {
78750+ if (suid_ban_expired(user))
78751+ return 0;
78752+ /* disallow execution of suid binaries only */
78753+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
78754+ return -EPERM;
78755+ }
78756+#endif
78757+ return 0;
78758+}
78759diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
78760new file mode 100644
78761index 0000000..e3650b6
78762--- /dev/null
78763+++ b/grsecurity/grsec_sock.c
78764@@ -0,0 +1,244 @@
78765+#include <linux/kernel.h>
78766+#include <linux/module.h>
78767+#include <linux/sched.h>
78768+#include <linux/file.h>
78769+#include <linux/net.h>
78770+#include <linux/in.h>
78771+#include <linux/ip.h>
78772+#include <net/sock.h>
78773+#include <net/inet_sock.h>
78774+#include <linux/grsecurity.h>
78775+#include <linux/grinternal.h>
78776+#include <linux/gracl.h>
78777+
78778+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
78779+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
78780+
78781+EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
78782+EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
78783+
78784+#ifdef CONFIG_UNIX_MODULE
78785+EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
78786+EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
78787+EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
78788+EXPORT_SYMBOL_GPL(gr_handle_create);
78789+#endif
78790+
78791+#ifdef CONFIG_GRKERNSEC
78792+#define gr_conn_table_size 32749
78793+struct conn_table_entry {
78794+ struct conn_table_entry *next;
78795+ struct signal_struct *sig;
78796+};
78797+
78798+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
78799+DEFINE_SPINLOCK(gr_conn_table_lock);
78800+
78801+extern const char * gr_socktype_to_name(unsigned char type);
78802+extern const char * gr_proto_to_name(unsigned char proto);
78803+extern const char * gr_sockfamily_to_name(unsigned char family);
78804+
78805+static __inline__ int
78806+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
78807+{
78808+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
78809+}
78810+
78811+static __inline__ int
78812+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
78813+ __u16 sport, __u16 dport)
78814+{
78815+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
78816+ sig->gr_sport == sport && sig->gr_dport == dport))
78817+ return 1;
78818+ else
78819+ return 0;
78820+}
78821+
78822+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
78823+{
78824+ struct conn_table_entry **match;
78825+ unsigned int index;
78826+
78827+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78828+ sig->gr_sport, sig->gr_dport,
78829+ gr_conn_table_size);
78830+
78831+ newent->sig = sig;
78832+
78833+ match = &gr_conn_table[index];
78834+ newent->next = *match;
78835+ *match = newent;
78836+
78837+ return;
78838+}
78839+
78840+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
78841+{
78842+ struct conn_table_entry *match, *last = NULL;
78843+ unsigned int index;
78844+
78845+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78846+ sig->gr_sport, sig->gr_dport,
78847+ gr_conn_table_size);
78848+
78849+ match = gr_conn_table[index];
78850+ while (match && !conn_match(match->sig,
78851+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
78852+ sig->gr_dport)) {
78853+ last = match;
78854+ match = match->next;
78855+ }
78856+
78857+ if (match) {
78858+ if (last)
78859+ last->next = match->next;
78860+ else
78861+ gr_conn_table[index] = NULL;
78862+ kfree(match);
78863+ }
78864+
78865+ return;
78866+}
78867+
78868+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
78869+ __u16 sport, __u16 dport)
78870+{
78871+ struct conn_table_entry *match;
78872+ unsigned int index;
78873+
78874+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
78875+
78876+ match = gr_conn_table[index];
78877+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
78878+ match = match->next;
78879+
78880+ if (match)
78881+ return match->sig;
78882+ else
78883+ return NULL;
78884+}
78885+
78886+#endif
78887+
78888+void gr_update_task_in_ip_table(const struct inet_sock *inet)
78889+{
78890+#ifdef CONFIG_GRKERNSEC
78891+ struct signal_struct *sig = current->signal;
78892+ struct conn_table_entry *newent;
78893+
78894+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
78895+ if (newent == NULL)
78896+ return;
78897+ /* no bh lock needed since we are called with bh disabled */
78898+ spin_lock(&gr_conn_table_lock);
78899+ gr_del_task_from_ip_table_nolock(sig);
78900+ sig->gr_saddr = inet->inet_rcv_saddr;
78901+ sig->gr_daddr = inet->inet_daddr;
78902+ sig->gr_sport = inet->inet_sport;
78903+ sig->gr_dport = inet->inet_dport;
78904+ gr_add_to_task_ip_table_nolock(sig, newent);
78905+ spin_unlock(&gr_conn_table_lock);
78906+#endif
78907+ return;
78908+}
78909+
78910+void gr_del_task_from_ip_table(struct task_struct *task)
78911+{
78912+#ifdef CONFIG_GRKERNSEC
78913+ spin_lock_bh(&gr_conn_table_lock);
78914+ gr_del_task_from_ip_table_nolock(task->signal);
78915+ spin_unlock_bh(&gr_conn_table_lock);
78916+#endif
78917+ return;
78918+}
78919+
78920+void
78921+gr_attach_curr_ip(const struct sock *sk)
78922+{
78923+#ifdef CONFIG_GRKERNSEC
78924+ struct signal_struct *p, *set;
78925+ const struct inet_sock *inet = inet_sk(sk);
78926+
78927+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
78928+ return;
78929+
78930+ set = current->signal;
78931+
78932+ spin_lock_bh(&gr_conn_table_lock);
78933+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
78934+ inet->inet_dport, inet->inet_sport);
78935+ if (unlikely(p != NULL)) {
78936+ set->curr_ip = p->curr_ip;
78937+ set->used_accept = 1;
78938+ gr_del_task_from_ip_table_nolock(p);
78939+ spin_unlock_bh(&gr_conn_table_lock);
78940+ return;
78941+ }
78942+ spin_unlock_bh(&gr_conn_table_lock);
78943+
78944+ set->curr_ip = inet->inet_daddr;
78945+ set->used_accept = 1;
78946+#endif
78947+ return;
78948+}
78949+
78950+int
78951+gr_handle_sock_all(const int family, const int type, const int protocol)
78952+{
78953+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78954+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
78955+ (family != AF_UNIX)) {
78956+ if (family == AF_INET)
78957+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
78958+ else
78959+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
78960+ return -EACCES;
78961+ }
78962+#endif
78963+ return 0;
78964+}
78965+
78966+int
78967+gr_handle_sock_server(const struct sockaddr *sck)
78968+{
78969+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78970+ if (grsec_enable_socket_server &&
78971+ in_group_p(grsec_socket_server_gid) &&
78972+ sck && (sck->sa_family != AF_UNIX) &&
78973+ (sck->sa_family != AF_LOCAL)) {
78974+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78975+ return -EACCES;
78976+ }
78977+#endif
78978+ return 0;
78979+}
78980+
78981+int
78982+gr_handle_sock_server_other(const struct sock *sck)
78983+{
78984+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78985+ if (grsec_enable_socket_server &&
78986+ in_group_p(grsec_socket_server_gid) &&
78987+ sck && (sck->sk_family != AF_UNIX) &&
78988+ (sck->sk_family != AF_LOCAL)) {
78989+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78990+ return -EACCES;
78991+ }
78992+#endif
78993+ return 0;
78994+}
78995+
78996+int
78997+gr_handle_sock_client(const struct sockaddr *sck)
78998+{
78999+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
79000+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
79001+ sck && (sck->sa_family != AF_UNIX) &&
79002+ (sck->sa_family != AF_LOCAL)) {
79003+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
79004+ return -EACCES;
79005+ }
79006+#endif
79007+ return 0;
79008+}
79009diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
79010new file mode 100644
79011index 0000000..8159888
79012--- /dev/null
79013+++ b/grsecurity/grsec_sysctl.c
79014@@ -0,0 +1,479 @@
79015+#include <linux/kernel.h>
79016+#include <linux/sched.h>
79017+#include <linux/sysctl.h>
79018+#include <linux/grsecurity.h>
79019+#include <linux/grinternal.h>
79020+
79021+int
79022+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
79023+{
79024+#ifdef CONFIG_GRKERNSEC_SYSCTL
79025+ if (dirname == NULL || name == NULL)
79026+ return 0;
79027+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
79028+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
79029+ return -EACCES;
79030+ }
79031+#endif
79032+ return 0;
79033+}
79034+
79035+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
79036+static int __maybe_unused __read_only one = 1;
79037+#endif
79038+
79039+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
79040+ defined(CONFIG_GRKERNSEC_DENYUSB)
79041+struct ctl_table grsecurity_table[] = {
79042+#ifdef CONFIG_GRKERNSEC_SYSCTL
79043+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
79044+#ifdef CONFIG_GRKERNSEC_IO
79045+ {
79046+ .procname = "disable_priv_io",
79047+ .data = &grsec_disable_privio,
79048+ .maxlen = sizeof(int),
79049+ .mode = 0600,
79050+ .proc_handler = &proc_dointvec,
79051+ },
79052+#endif
79053+#endif
79054+#ifdef CONFIG_GRKERNSEC_LINK
79055+ {
79056+ .procname = "linking_restrictions",
79057+ .data = &grsec_enable_link,
79058+ .maxlen = sizeof(int),
79059+ .mode = 0600,
79060+ .proc_handler = &proc_dointvec,
79061+ },
79062+#endif
79063+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
79064+ {
79065+ .procname = "enforce_symlinksifowner",
79066+ .data = &grsec_enable_symlinkown,
79067+ .maxlen = sizeof(int),
79068+ .mode = 0600,
79069+ .proc_handler = &proc_dointvec,
79070+ },
79071+ {
79072+ .procname = "symlinkown_gid",
79073+ .data = &grsec_symlinkown_gid,
79074+ .maxlen = sizeof(int),
79075+ .mode = 0600,
79076+ .proc_handler = &proc_dointvec,
79077+ },
79078+#endif
79079+#ifdef CONFIG_GRKERNSEC_BRUTE
79080+ {
79081+ .procname = "deter_bruteforce",
79082+ .data = &grsec_enable_brute,
79083+ .maxlen = sizeof(int),
79084+ .mode = 0600,
79085+ .proc_handler = &proc_dointvec,
79086+ },
79087+#endif
79088+#ifdef CONFIG_GRKERNSEC_FIFO
79089+ {
79090+ .procname = "fifo_restrictions",
79091+ .data = &grsec_enable_fifo,
79092+ .maxlen = sizeof(int),
79093+ .mode = 0600,
79094+ .proc_handler = &proc_dointvec,
79095+ },
79096+#endif
79097+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
79098+ {
79099+ .procname = "ptrace_readexec",
79100+ .data = &grsec_enable_ptrace_readexec,
79101+ .maxlen = sizeof(int),
79102+ .mode = 0600,
79103+ .proc_handler = &proc_dointvec,
79104+ },
79105+#endif
79106+#ifdef CONFIG_GRKERNSEC_SETXID
79107+ {
79108+ .procname = "consistent_setxid",
79109+ .data = &grsec_enable_setxid,
79110+ .maxlen = sizeof(int),
79111+ .mode = 0600,
79112+ .proc_handler = &proc_dointvec,
79113+ },
79114+#endif
79115+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79116+ {
79117+ .procname = "ip_blackhole",
79118+ .data = &grsec_enable_blackhole,
79119+ .maxlen = sizeof(int),
79120+ .mode = 0600,
79121+ .proc_handler = &proc_dointvec,
79122+ },
79123+ {
79124+ .procname = "lastack_retries",
79125+ .data = &grsec_lastack_retries,
79126+ .maxlen = sizeof(int),
79127+ .mode = 0600,
79128+ .proc_handler = &proc_dointvec,
79129+ },
79130+#endif
79131+#ifdef CONFIG_GRKERNSEC_EXECLOG
79132+ {
79133+ .procname = "exec_logging",
79134+ .data = &grsec_enable_execlog,
79135+ .maxlen = sizeof(int),
79136+ .mode = 0600,
79137+ .proc_handler = &proc_dointvec,
79138+ },
79139+#endif
79140+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
79141+ {
79142+ .procname = "rwxmap_logging",
79143+ .data = &grsec_enable_log_rwxmaps,
79144+ .maxlen = sizeof(int),
79145+ .mode = 0600,
79146+ .proc_handler = &proc_dointvec,
79147+ },
79148+#endif
79149+#ifdef CONFIG_GRKERNSEC_SIGNAL
79150+ {
79151+ .procname = "signal_logging",
79152+ .data = &grsec_enable_signal,
79153+ .maxlen = sizeof(int),
79154+ .mode = 0600,
79155+ .proc_handler = &proc_dointvec,
79156+ },
79157+#endif
79158+#ifdef CONFIG_GRKERNSEC_FORKFAIL
79159+ {
79160+ .procname = "forkfail_logging",
79161+ .data = &grsec_enable_forkfail,
79162+ .maxlen = sizeof(int),
79163+ .mode = 0600,
79164+ .proc_handler = &proc_dointvec,
79165+ },
79166+#endif
79167+#ifdef CONFIG_GRKERNSEC_TIME
79168+ {
79169+ .procname = "timechange_logging",
79170+ .data = &grsec_enable_time,
79171+ .maxlen = sizeof(int),
79172+ .mode = 0600,
79173+ .proc_handler = &proc_dointvec,
79174+ },
79175+#endif
79176+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
79177+ {
79178+ .procname = "chroot_deny_shmat",
79179+ .data = &grsec_enable_chroot_shmat,
79180+ .maxlen = sizeof(int),
79181+ .mode = 0600,
79182+ .proc_handler = &proc_dointvec,
79183+ },
79184+#endif
79185+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
79186+ {
79187+ .procname = "chroot_deny_unix",
79188+ .data = &grsec_enable_chroot_unix,
79189+ .maxlen = sizeof(int),
79190+ .mode = 0600,
79191+ .proc_handler = &proc_dointvec,
79192+ },
79193+#endif
79194+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
79195+ {
79196+ .procname = "chroot_deny_mount",
79197+ .data = &grsec_enable_chroot_mount,
79198+ .maxlen = sizeof(int),
79199+ .mode = 0600,
79200+ .proc_handler = &proc_dointvec,
79201+ },
79202+#endif
79203+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
79204+ {
79205+ .procname = "chroot_deny_fchdir",
79206+ .data = &grsec_enable_chroot_fchdir,
79207+ .maxlen = sizeof(int),
79208+ .mode = 0600,
79209+ .proc_handler = &proc_dointvec,
79210+ },
79211+#endif
79212+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
79213+ {
79214+ .procname = "chroot_deny_chroot",
79215+ .data = &grsec_enable_chroot_double,
79216+ .maxlen = sizeof(int),
79217+ .mode = 0600,
79218+ .proc_handler = &proc_dointvec,
79219+ },
79220+#endif
79221+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
79222+ {
79223+ .procname = "chroot_deny_pivot",
79224+ .data = &grsec_enable_chroot_pivot,
79225+ .maxlen = sizeof(int),
79226+ .mode = 0600,
79227+ .proc_handler = &proc_dointvec,
79228+ },
79229+#endif
79230+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
79231+ {
79232+ .procname = "chroot_enforce_chdir",
79233+ .data = &grsec_enable_chroot_chdir,
79234+ .maxlen = sizeof(int),
79235+ .mode = 0600,
79236+ .proc_handler = &proc_dointvec,
79237+ },
79238+#endif
79239+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
79240+ {
79241+ .procname = "chroot_deny_chmod",
79242+ .data = &grsec_enable_chroot_chmod,
79243+ .maxlen = sizeof(int),
79244+ .mode = 0600,
79245+ .proc_handler = &proc_dointvec,
79246+ },
79247+#endif
79248+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
79249+ {
79250+ .procname = "chroot_deny_mknod",
79251+ .data = &grsec_enable_chroot_mknod,
79252+ .maxlen = sizeof(int),
79253+ .mode = 0600,
79254+ .proc_handler = &proc_dointvec,
79255+ },
79256+#endif
79257+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
79258+ {
79259+ .procname = "chroot_restrict_nice",
79260+ .data = &grsec_enable_chroot_nice,
79261+ .maxlen = sizeof(int),
79262+ .mode = 0600,
79263+ .proc_handler = &proc_dointvec,
79264+ },
79265+#endif
79266+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
79267+ {
79268+ .procname = "chroot_execlog",
79269+ .data = &grsec_enable_chroot_execlog,
79270+ .maxlen = sizeof(int),
79271+ .mode = 0600,
79272+ .proc_handler = &proc_dointvec,
79273+ },
79274+#endif
79275+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
79276+ {
79277+ .procname = "chroot_caps",
79278+ .data = &grsec_enable_chroot_caps,
79279+ .maxlen = sizeof(int),
79280+ .mode = 0600,
79281+ .proc_handler = &proc_dointvec,
79282+ },
79283+#endif
79284+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
79285+ {
79286+ .procname = "chroot_deny_sysctl",
79287+ .data = &grsec_enable_chroot_sysctl,
79288+ .maxlen = sizeof(int),
79289+ .mode = 0600,
79290+ .proc_handler = &proc_dointvec,
79291+ },
79292+#endif
79293+#ifdef CONFIG_GRKERNSEC_TPE
79294+ {
79295+ .procname = "tpe",
79296+ .data = &grsec_enable_tpe,
79297+ .maxlen = sizeof(int),
79298+ .mode = 0600,
79299+ .proc_handler = &proc_dointvec,
79300+ },
79301+ {
79302+ .procname = "tpe_gid",
79303+ .data = &grsec_tpe_gid,
79304+ .maxlen = sizeof(int),
79305+ .mode = 0600,
79306+ .proc_handler = &proc_dointvec,
79307+ },
79308+#endif
79309+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79310+ {
79311+ .procname = "tpe_invert",
79312+ .data = &grsec_enable_tpe_invert,
79313+ .maxlen = sizeof(int),
79314+ .mode = 0600,
79315+ .proc_handler = &proc_dointvec,
79316+ },
79317+#endif
79318+#ifdef CONFIG_GRKERNSEC_TPE_ALL
79319+ {
79320+ .procname = "tpe_restrict_all",
79321+ .data = &grsec_enable_tpe_all,
79322+ .maxlen = sizeof(int),
79323+ .mode = 0600,
79324+ .proc_handler = &proc_dointvec,
79325+ },
79326+#endif
79327+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
79328+ {
79329+ .procname = "socket_all",
79330+ .data = &grsec_enable_socket_all,
79331+ .maxlen = sizeof(int),
79332+ .mode = 0600,
79333+ .proc_handler = &proc_dointvec,
79334+ },
79335+ {
79336+ .procname = "socket_all_gid",
79337+ .data = &grsec_socket_all_gid,
79338+ .maxlen = sizeof(int),
79339+ .mode = 0600,
79340+ .proc_handler = &proc_dointvec,
79341+ },
79342+#endif
79343+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
79344+ {
79345+ .procname = "socket_client",
79346+ .data = &grsec_enable_socket_client,
79347+ .maxlen = sizeof(int),
79348+ .mode = 0600,
79349+ .proc_handler = &proc_dointvec,
79350+ },
79351+ {
79352+ .procname = "socket_client_gid",
79353+ .data = &grsec_socket_client_gid,
79354+ .maxlen = sizeof(int),
79355+ .mode = 0600,
79356+ .proc_handler = &proc_dointvec,
79357+ },
79358+#endif
79359+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
79360+ {
79361+ .procname = "socket_server",
79362+ .data = &grsec_enable_socket_server,
79363+ .maxlen = sizeof(int),
79364+ .mode = 0600,
79365+ .proc_handler = &proc_dointvec,
79366+ },
79367+ {
79368+ .procname = "socket_server_gid",
79369+ .data = &grsec_socket_server_gid,
79370+ .maxlen = sizeof(int),
79371+ .mode = 0600,
79372+ .proc_handler = &proc_dointvec,
79373+ },
79374+#endif
79375+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
79376+ {
79377+ .procname = "audit_group",
79378+ .data = &grsec_enable_group,
79379+ .maxlen = sizeof(int),
79380+ .mode = 0600,
79381+ .proc_handler = &proc_dointvec,
79382+ },
79383+ {
79384+ .procname = "audit_gid",
79385+ .data = &grsec_audit_gid,
79386+ .maxlen = sizeof(int),
79387+ .mode = 0600,
79388+ .proc_handler = &proc_dointvec,
79389+ },
79390+#endif
79391+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
79392+ {
79393+ .procname = "audit_chdir",
79394+ .data = &grsec_enable_chdir,
79395+ .maxlen = sizeof(int),
79396+ .mode = 0600,
79397+ .proc_handler = &proc_dointvec,
79398+ },
79399+#endif
79400+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
79401+ {
79402+ .procname = "audit_mount",
79403+ .data = &grsec_enable_mount,
79404+ .maxlen = sizeof(int),
79405+ .mode = 0600,
79406+ .proc_handler = &proc_dointvec,
79407+ },
79408+#endif
79409+#ifdef CONFIG_GRKERNSEC_DMESG
79410+ {
79411+ .procname = "dmesg",
79412+ .data = &grsec_enable_dmesg,
79413+ .maxlen = sizeof(int),
79414+ .mode = 0600,
79415+ .proc_handler = &proc_dointvec,
79416+ },
79417+#endif
79418+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79419+ {
79420+ .procname = "chroot_findtask",
79421+ .data = &grsec_enable_chroot_findtask,
79422+ .maxlen = sizeof(int),
79423+ .mode = 0600,
79424+ .proc_handler = &proc_dointvec,
79425+ },
79426+#endif
79427+#ifdef CONFIG_GRKERNSEC_RESLOG
79428+ {
79429+ .procname = "resource_logging",
79430+ .data = &grsec_resource_logging,
79431+ .maxlen = sizeof(int),
79432+ .mode = 0600,
79433+ .proc_handler = &proc_dointvec,
79434+ },
79435+#endif
79436+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
79437+ {
79438+ .procname = "audit_ptrace",
79439+ .data = &grsec_enable_audit_ptrace,
79440+ .maxlen = sizeof(int),
79441+ .mode = 0600,
79442+ .proc_handler = &proc_dointvec,
79443+ },
79444+#endif
79445+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
79446+ {
79447+ .procname = "harden_ptrace",
79448+ .data = &grsec_enable_harden_ptrace,
79449+ .maxlen = sizeof(int),
79450+ .mode = 0600,
79451+ .proc_handler = &proc_dointvec,
79452+ },
79453+#endif
79454+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
79455+ {
79456+ .procname = "harden_ipc",
79457+ .data = &grsec_enable_harden_ipc,
79458+ .maxlen = sizeof(int),
79459+ .mode = 0600,
79460+ .proc_handler = &proc_dointvec,
79461+ },
79462+#endif
79463+ {
79464+ .procname = "grsec_lock",
79465+ .data = &grsec_lock,
79466+ .maxlen = sizeof(int),
79467+ .mode = 0600,
79468+ .proc_handler = &proc_dointvec,
79469+ },
79470+#endif
79471+#ifdef CONFIG_GRKERNSEC_ROFS
79472+ {
79473+ .procname = "romount_protect",
79474+ .data = &grsec_enable_rofs,
79475+ .maxlen = sizeof(int),
79476+ .mode = 0600,
79477+ .proc_handler = &proc_dointvec_minmax,
79478+ .extra1 = &one,
79479+ .extra2 = &one,
79480+ },
79481+#endif
79482+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
79483+ {
79484+ .procname = "deny_new_usb",
79485+ .data = &grsec_deny_new_usb,
79486+ .maxlen = sizeof(int),
79487+ .mode = 0600,
79488+ .proc_handler = &proc_dointvec,
79489+ },
79490+#endif
79491+ { }
79492+};
79493+#endif
79494diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
79495new file mode 100644
79496index 0000000..61b514e
79497--- /dev/null
79498+++ b/grsecurity/grsec_time.c
79499@@ -0,0 +1,16 @@
79500+#include <linux/kernel.h>
79501+#include <linux/sched.h>
79502+#include <linux/grinternal.h>
79503+#include <linux/module.h>
79504+
79505+void
79506+gr_log_timechange(void)
79507+{
79508+#ifdef CONFIG_GRKERNSEC_TIME
79509+ if (grsec_enable_time)
79510+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
79511+#endif
79512+ return;
79513+}
79514+
79515+EXPORT_SYMBOL_GPL(gr_log_timechange);
79516diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
79517new file mode 100644
79518index 0000000..d1953de
79519--- /dev/null
79520+++ b/grsecurity/grsec_tpe.c
79521@@ -0,0 +1,78 @@
79522+#include <linux/kernel.h>
79523+#include <linux/sched.h>
79524+#include <linux/file.h>
79525+#include <linux/fs.h>
79526+#include <linux/grinternal.h>
79527+
79528+extern int gr_acl_tpe_check(void);
79529+
79530+int
79531+gr_tpe_allow(const struct file *file)
79532+{
79533+#ifdef CONFIG_GRKERNSEC
79534+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
79535+ struct inode *file_inode = file->f_path.dentry->d_inode;
79536+ const struct cred *cred = current_cred();
79537+ char *msg = NULL;
79538+ char *msg2 = NULL;
79539+
79540+ // never restrict root
79541+ if (gr_is_global_root(cred->uid))
79542+ return 1;
79543+
79544+ if (grsec_enable_tpe) {
79545+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79546+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
79547+ msg = "not being in trusted group";
79548+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
79549+ msg = "being in untrusted group";
79550+#else
79551+ if (in_group_p(grsec_tpe_gid))
79552+ msg = "being in untrusted group";
79553+#endif
79554+ }
79555+ if (!msg && gr_acl_tpe_check())
79556+ msg = "being in untrusted role";
79557+
79558+ // not in any affected group/role
79559+ if (!msg)
79560+ goto next_check;
79561+
79562+ if (gr_is_global_nonroot(inode->i_uid))
79563+ msg2 = "file in non-root-owned directory";
79564+ else if (inode->i_mode & S_IWOTH)
79565+ msg2 = "file in world-writable directory";
79566+ else if (inode->i_mode & S_IWGRP)
79567+ msg2 = "file in group-writable directory";
79568+ else if (file_inode->i_mode & S_IWOTH)
79569+ msg2 = "file is world-writable";
79570+
79571+ if (msg && msg2) {
79572+ char fullmsg[70] = {0};
79573+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
79574+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
79575+ return 0;
79576+ }
79577+ msg = NULL;
79578+next_check:
79579+#ifdef CONFIG_GRKERNSEC_TPE_ALL
79580+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
79581+ return 1;
79582+
79583+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
79584+ msg = "directory not owned by user";
79585+ else if (inode->i_mode & S_IWOTH)
79586+ msg = "file in world-writable directory";
79587+ else if (inode->i_mode & S_IWGRP)
79588+ msg = "file in group-writable directory";
79589+ else if (file_inode->i_mode & S_IWOTH)
79590+ msg = "file is world-writable";
79591+
79592+ if (msg) {
79593+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
79594+ return 0;
79595+ }
79596+#endif
79597+#endif
79598+ return 1;
79599+}
79600diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
79601new file mode 100644
79602index 0000000..ae02d8e
79603--- /dev/null
79604+++ b/grsecurity/grsec_usb.c
79605@@ -0,0 +1,15 @@
79606+#include <linux/kernel.h>
79607+#include <linux/grinternal.h>
79608+#include <linux/module.h>
79609+
79610+int gr_handle_new_usb(void)
79611+{
79612+#ifdef CONFIG_GRKERNSEC_DENYUSB
79613+ if (grsec_deny_new_usb) {
79614+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
79615+ return 1;
79616+ }
79617+#endif
79618+ return 0;
79619+}
79620+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
79621diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
79622new file mode 100644
79623index 0000000..158b330
79624--- /dev/null
79625+++ b/grsecurity/grsum.c
79626@@ -0,0 +1,64 @@
79627+#include <linux/err.h>
79628+#include <linux/kernel.h>
79629+#include <linux/sched.h>
79630+#include <linux/mm.h>
79631+#include <linux/scatterlist.h>
79632+#include <linux/crypto.h>
79633+#include <linux/gracl.h>
79634+
79635+
79636+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
79637+#error "crypto and sha256 must be built into the kernel"
79638+#endif
79639+
79640+int
79641+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
79642+{
79643+ struct crypto_hash *tfm;
79644+ struct hash_desc desc;
79645+ struct scatterlist sg[2];
79646+ unsigned char temp_sum[GR_SHA_LEN] __attribute__((aligned(__alignof__(unsigned long))));
79647+ unsigned long *tmpsumptr = (unsigned long *)temp_sum;
79648+ unsigned long *sumptr = (unsigned long *)sum;
79649+ int cryptres;
79650+ int retval = 1;
79651+ volatile int mismatched = 0;
79652+ volatile int dummy = 0;
79653+ unsigned int i;
79654+
79655+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
79656+ if (IS_ERR(tfm)) {
79657+ /* should never happen, since sha256 should be built in */
79658+ memset(entry->pw, 0, GR_PW_LEN);
79659+ return 1;
79660+ }
79661+
79662+ sg_init_table(sg, 2);
79663+ sg_set_buf(&sg[0], salt, GR_SALT_LEN);
79664+ sg_set_buf(&sg[1], entry->pw, strlen(entry->pw));
79665+
79666+ desc.tfm = tfm;
79667+ desc.flags = 0;
79668+
79669+ cryptres = crypto_hash_digest(&desc, sg, GR_SALT_LEN + strlen(entry->pw),
79670+ temp_sum);
79671+
79672+ memset(entry->pw, 0, GR_PW_LEN);
79673+
79674+ if (cryptres)
79675+ goto out;
79676+
79677+ for (i = 0; i < GR_SHA_LEN/sizeof(tmpsumptr[0]); i++)
79678+ if (sumptr[i] != tmpsumptr[i])
79679+ mismatched = 1;
79680+ else
79681+ dummy = 1; // waste a cycle
79682+
79683+ if (!mismatched)
79684+ retval = dummy - 1;
79685+
79686+out:
79687+ crypto_free_hash(tfm);
79688+
79689+ return retval;
79690+}
79691diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
79692index 77ff547..181834f 100644
79693--- a/include/asm-generic/4level-fixup.h
79694+++ b/include/asm-generic/4level-fixup.h
79695@@ -13,8 +13,10 @@
79696 #define pmd_alloc(mm, pud, address) \
79697 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
79698 NULL: pmd_offset(pud, address))
79699+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
79700
79701 #define pud_alloc(mm, pgd, address) (pgd)
79702+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
79703 #define pud_offset(pgd, start) (pgd)
79704 #define pud_none(pud) 0
79705 #define pud_bad(pud) 0
79706diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
79707index b7babf0..1e4b4f1 100644
79708--- a/include/asm-generic/atomic-long.h
79709+++ b/include/asm-generic/atomic-long.h
79710@@ -22,6 +22,12 @@
79711
79712 typedef atomic64_t atomic_long_t;
79713
79714+#ifdef CONFIG_PAX_REFCOUNT
79715+typedef atomic64_unchecked_t atomic_long_unchecked_t;
79716+#else
79717+typedef atomic64_t atomic_long_unchecked_t;
79718+#endif
79719+
79720 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
79721
79722 static inline long atomic_long_read(atomic_long_t *l)
79723@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79724 return (long)atomic64_read(v);
79725 }
79726
79727+#ifdef CONFIG_PAX_REFCOUNT
79728+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79729+{
79730+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79731+
79732+ return (long)atomic64_read_unchecked(v);
79733+}
79734+#endif
79735+
79736 static inline void atomic_long_set(atomic_long_t *l, long i)
79737 {
79738 atomic64_t *v = (atomic64_t *)l;
79739@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79740 atomic64_set(v, i);
79741 }
79742
79743+#ifdef CONFIG_PAX_REFCOUNT
79744+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79745+{
79746+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79747+
79748+ atomic64_set_unchecked(v, i);
79749+}
79750+#endif
79751+
79752 static inline void atomic_long_inc(atomic_long_t *l)
79753 {
79754 atomic64_t *v = (atomic64_t *)l;
79755@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79756 atomic64_inc(v);
79757 }
79758
79759+#ifdef CONFIG_PAX_REFCOUNT
79760+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79761+{
79762+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79763+
79764+ atomic64_inc_unchecked(v);
79765+}
79766+#endif
79767+
79768 static inline void atomic_long_dec(atomic_long_t *l)
79769 {
79770 atomic64_t *v = (atomic64_t *)l;
79771@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79772 atomic64_dec(v);
79773 }
79774
79775+#ifdef CONFIG_PAX_REFCOUNT
79776+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79777+{
79778+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79779+
79780+ atomic64_dec_unchecked(v);
79781+}
79782+#endif
79783+
79784 static inline void atomic_long_add(long i, atomic_long_t *l)
79785 {
79786 atomic64_t *v = (atomic64_t *)l;
79787@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79788 atomic64_add(i, v);
79789 }
79790
79791+#ifdef CONFIG_PAX_REFCOUNT
79792+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79793+{
79794+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79795+
79796+ atomic64_add_unchecked(i, v);
79797+}
79798+#endif
79799+
79800 static inline void atomic_long_sub(long i, atomic_long_t *l)
79801 {
79802 atomic64_t *v = (atomic64_t *)l;
79803@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79804 atomic64_sub(i, v);
79805 }
79806
79807+#ifdef CONFIG_PAX_REFCOUNT
79808+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79809+{
79810+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79811+
79812+ atomic64_sub_unchecked(i, v);
79813+}
79814+#endif
79815+
79816 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79817 {
79818 atomic64_t *v = (atomic64_t *)l;
79819@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79820 return atomic64_add_negative(i, v);
79821 }
79822
79823-static inline long atomic_long_add_return(long i, atomic_long_t *l)
79824+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79825 {
79826 atomic64_t *v = (atomic64_t *)l;
79827
79828 return (long)atomic64_add_return(i, v);
79829 }
79830
79831+#ifdef CONFIG_PAX_REFCOUNT
79832+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79833+{
79834+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79835+
79836+ return (long)atomic64_add_return_unchecked(i, v);
79837+}
79838+#endif
79839+
79840 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79841 {
79842 atomic64_t *v = (atomic64_t *)l;
79843@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79844 return (long)atomic64_inc_return(v);
79845 }
79846
79847+#ifdef CONFIG_PAX_REFCOUNT
79848+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79849+{
79850+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79851+
79852+ return (long)atomic64_inc_return_unchecked(v);
79853+}
79854+#endif
79855+
79856 static inline long atomic_long_dec_return(atomic_long_t *l)
79857 {
79858 atomic64_t *v = (atomic64_t *)l;
79859@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79860
79861 typedef atomic_t atomic_long_t;
79862
79863+#ifdef CONFIG_PAX_REFCOUNT
79864+typedef atomic_unchecked_t atomic_long_unchecked_t;
79865+#else
79866+typedef atomic_t atomic_long_unchecked_t;
79867+#endif
79868+
79869 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
79870 static inline long atomic_long_read(atomic_long_t *l)
79871 {
79872@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79873 return (long)atomic_read(v);
79874 }
79875
79876+#ifdef CONFIG_PAX_REFCOUNT
79877+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79878+{
79879+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79880+
79881+ return (long)atomic_read_unchecked(v);
79882+}
79883+#endif
79884+
79885 static inline void atomic_long_set(atomic_long_t *l, long i)
79886 {
79887 atomic_t *v = (atomic_t *)l;
79888@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79889 atomic_set(v, i);
79890 }
79891
79892+#ifdef CONFIG_PAX_REFCOUNT
79893+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79894+{
79895+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79896+
79897+ atomic_set_unchecked(v, i);
79898+}
79899+#endif
79900+
79901 static inline void atomic_long_inc(atomic_long_t *l)
79902 {
79903 atomic_t *v = (atomic_t *)l;
79904@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79905 atomic_inc(v);
79906 }
79907
79908+#ifdef CONFIG_PAX_REFCOUNT
79909+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79910+{
79911+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79912+
79913+ atomic_inc_unchecked(v);
79914+}
79915+#endif
79916+
79917 static inline void atomic_long_dec(atomic_long_t *l)
79918 {
79919 atomic_t *v = (atomic_t *)l;
79920@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79921 atomic_dec(v);
79922 }
79923
79924+#ifdef CONFIG_PAX_REFCOUNT
79925+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79926+{
79927+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79928+
79929+ atomic_dec_unchecked(v);
79930+}
79931+#endif
79932+
79933 static inline void atomic_long_add(long i, atomic_long_t *l)
79934 {
79935 atomic_t *v = (atomic_t *)l;
79936@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79937 atomic_add(i, v);
79938 }
79939
79940+#ifdef CONFIG_PAX_REFCOUNT
79941+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79942+{
79943+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79944+
79945+ atomic_add_unchecked(i, v);
79946+}
79947+#endif
79948+
79949 static inline void atomic_long_sub(long i, atomic_long_t *l)
79950 {
79951 atomic_t *v = (atomic_t *)l;
79952@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79953 atomic_sub(i, v);
79954 }
79955
79956+#ifdef CONFIG_PAX_REFCOUNT
79957+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79958+{
79959+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79960+
79961+ atomic_sub_unchecked(i, v);
79962+}
79963+#endif
79964+
79965 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79966 {
79967 atomic_t *v = (atomic_t *)l;
79968@@ -211,13 +349,23 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79969 return atomic_add_negative(i, v);
79970 }
79971
79972-static inline long atomic_long_add_return(long i, atomic_long_t *l)
79973+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79974 {
79975 atomic_t *v = (atomic_t *)l;
79976
79977 return (long)atomic_add_return(i, v);
79978 }
79979
79980+#ifdef CONFIG_PAX_REFCOUNT
79981+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79982+{
79983+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79984+
79985+ return (long)atomic_add_return_unchecked(i, v);
79986+}
79987+
79988+#endif
79989+
79990 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79991 {
79992 atomic_t *v = (atomic_t *)l;
79993@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79994 return (long)atomic_inc_return(v);
79995 }
79996
79997+#ifdef CONFIG_PAX_REFCOUNT
79998+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79999+{
80000+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
80001+
80002+ return (long)atomic_inc_return_unchecked(v);
80003+}
80004+#endif
80005+
80006 static inline long atomic_long_dec_return(atomic_long_t *l)
80007 {
80008 atomic_t *v = (atomic_t *)l;
80009@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
80010
80011 #endif /* BITS_PER_LONG == 64 */
80012
80013+#ifdef CONFIG_PAX_REFCOUNT
80014+static inline void pax_refcount_needs_these_functions(void)
80015+{
80016+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
80017+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
80018+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
80019+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
80020+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
80021+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
80022+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
80023+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
80024+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
80025+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
80026+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
80027+#ifdef CONFIG_X86
80028+ atomic_clear_mask_unchecked(0, NULL);
80029+ atomic_set_mask_unchecked(0, NULL);
80030+#endif
80031+
80032+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
80033+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
80034+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
80035+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
80036+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
80037+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
80038+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
80039+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
80040+}
80041+#else
80042+#define atomic_read_unchecked(v) atomic_read(v)
80043+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
80044+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
80045+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
80046+#define atomic_inc_unchecked(v) atomic_inc(v)
80047+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
80048+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
80049+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
80050+#define atomic_dec_unchecked(v) atomic_dec(v)
80051+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
80052+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
80053+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
80054+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
80055+
80056+#define atomic_long_read_unchecked(v) atomic_long_read(v)
80057+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
80058+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
80059+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
80060+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
80061+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
80062+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
80063+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
80064+#endif
80065+
80066 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
80067diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
80068index 9c79e76..9f7827d 100644
80069--- a/include/asm-generic/atomic.h
80070+++ b/include/asm-generic/atomic.h
80071@@ -154,7 +154,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
80072 * Atomically clears the bits set in @mask from @v
80073 */
80074 #ifndef atomic_clear_mask
80075-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
80076+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
80077 {
80078 unsigned long flags;
80079
80080diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
80081index b18ce4f..2ee2843 100644
80082--- a/include/asm-generic/atomic64.h
80083+++ b/include/asm-generic/atomic64.h
80084@@ -16,6 +16,8 @@ typedef struct {
80085 long long counter;
80086 } atomic64_t;
80087
80088+typedef atomic64_t atomic64_unchecked_t;
80089+
80090 #define ATOMIC64_INIT(i) { (i) }
80091
80092 extern long long atomic64_read(const atomic64_t *v);
80093@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
80094 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
80095 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
80096
80097+#define atomic64_read_unchecked(v) atomic64_read(v)
80098+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
80099+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
80100+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
80101+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
80102+#define atomic64_inc_unchecked(v) atomic64_inc(v)
80103+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
80104+#define atomic64_dec_unchecked(v) atomic64_dec(v)
80105+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
80106+
80107 #endif /* _ASM_GENERIC_ATOMIC64_H */
80108diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
80109index 1402fa8..025a736 100644
80110--- a/include/asm-generic/barrier.h
80111+++ b/include/asm-generic/barrier.h
80112@@ -74,7 +74,7 @@
80113 do { \
80114 compiletime_assert_atomic_type(*p); \
80115 smp_mb(); \
80116- ACCESS_ONCE(*p) = (v); \
80117+ ACCESS_ONCE_RW(*p) = (v); \
80118 } while (0)
80119
80120 #define smp_load_acquire(p) \
80121diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
80122index a60a7cc..0fe12f2 100644
80123--- a/include/asm-generic/bitops/__fls.h
80124+++ b/include/asm-generic/bitops/__fls.h
80125@@ -9,7 +9,7 @@
80126 *
80127 * Undefined if no set bit exists, so code should check against 0 first.
80128 */
80129-static __always_inline unsigned long __fls(unsigned long word)
80130+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
80131 {
80132 int num = BITS_PER_LONG - 1;
80133
80134diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
80135index 0576d1f..dad6c71 100644
80136--- a/include/asm-generic/bitops/fls.h
80137+++ b/include/asm-generic/bitops/fls.h
80138@@ -9,7 +9,7 @@
80139 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
80140 */
80141
80142-static __always_inline int fls(int x)
80143+static __always_inline int __intentional_overflow(-1) fls(int x)
80144 {
80145 int r = 32;
80146
80147diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
80148index b097cf8..3d40e14 100644
80149--- a/include/asm-generic/bitops/fls64.h
80150+++ b/include/asm-generic/bitops/fls64.h
80151@@ -15,7 +15,7 @@
80152 * at position 64.
80153 */
80154 #if BITS_PER_LONG == 32
80155-static __always_inline int fls64(__u64 x)
80156+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
80157 {
80158 __u32 h = x >> 32;
80159 if (h)
80160@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
80161 return fls(x);
80162 }
80163 #elif BITS_PER_LONG == 64
80164-static __always_inline int fls64(__u64 x)
80165+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
80166 {
80167 if (x == 0)
80168 return 0;
80169diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
80170index 1bfcfe5..e04c5c9 100644
80171--- a/include/asm-generic/cache.h
80172+++ b/include/asm-generic/cache.h
80173@@ -6,7 +6,7 @@
80174 * cache lines need to provide their own cache.h.
80175 */
80176
80177-#define L1_CACHE_SHIFT 5
80178-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
80179+#define L1_CACHE_SHIFT 5UL
80180+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
80181
80182 #endif /* __ASM_GENERIC_CACHE_H */
80183diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
80184index 0d68a1e..b74a761 100644
80185--- a/include/asm-generic/emergency-restart.h
80186+++ b/include/asm-generic/emergency-restart.h
80187@@ -1,7 +1,7 @@
80188 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
80189 #define _ASM_GENERIC_EMERGENCY_RESTART_H
80190
80191-static inline void machine_emergency_restart(void)
80192+static inline __noreturn void machine_emergency_restart(void)
80193 {
80194 machine_restart(NULL);
80195 }
80196diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
80197index 975e1cc..0b8a083 100644
80198--- a/include/asm-generic/io.h
80199+++ b/include/asm-generic/io.h
80200@@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
80201 * These are pretty trivial
80202 */
80203 #ifndef virt_to_phys
80204-static inline unsigned long virt_to_phys(volatile void *address)
80205+static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
80206 {
80207 return __pa((unsigned long)address);
80208 }
80209diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
80210index 90f99c7..00ce236 100644
80211--- a/include/asm-generic/kmap_types.h
80212+++ b/include/asm-generic/kmap_types.h
80213@@ -2,9 +2,9 @@
80214 #define _ASM_GENERIC_KMAP_TYPES_H
80215
80216 #ifdef __WITH_KM_FENCE
80217-# define KM_TYPE_NR 41
80218+# define KM_TYPE_NR 42
80219 #else
80220-# define KM_TYPE_NR 20
80221+# define KM_TYPE_NR 21
80222 #endif
80223
80224 #endif
80225diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
80226index 9ceb03b..62b0b8f 100644
80227--- a/include/asm-generic/local.h
80228+++ b/include/asm-generic/local.h
80229@@ -23,24 +23,37 @@ typedef struct
80230 atomic_long_t a;
80231 } local_t;
80232
80233+typedef struct {
80234+ atomic_long_unchecked_t a;
80235+} local_unchecked_t;
80236+
80237 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
80238
80239 #define local_read(l) atomic_long_read(&(l)->a)
80240+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
80241 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
80242+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
80243 #define local_inc(l) atomic_long_inc(&(l)->a)
80244+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
80245 #define local_dec(l) atomic_long_dec(&(l)->a)
80246+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
80247 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
80248+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
80249 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
80250+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
80251
80252 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
80253 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
80254 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
80255 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
80256 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
80257+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
80258 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
80259 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
80260+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
80261
80262 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
80263+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
80264 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
80265 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
80266 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
80267diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
80268index 725612b..9cc513a 100644
80269--- a/include/asm-generic/pgtable-nopmd.h
80270+++ b/include/asm-generic/pgtable-nopmd.h
80271@@ -1,14 +1,19 @@
80272 #ifndef _PGTABLE_NOPMD_H
80273 #define _PGTABLE_NOPMD_H
80274
80275-#ifndef __ASSEMBLY__
80276-
80277 #include <asm-generic/pgtable-nopud.h>
80278
80279-struct mm_struct;
80280-
80281 #define __PAGETABLE_PMD_FOLDED
80282
80283+#define PMD_SHIFT PUD_SHIFT
80284+#define PTRS_PER_PMD 1
80285+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
80286+#define PMD_MASK (~(PMD_SIZE-1))
80287+
80288+#ifndef __ASSEMBLY__
80289+
80290+struct mm_struct;
80291+
80292 /*
80293 * Having the pmd type consist of a pud gets the size right, and allows
80294 * us to conceptually access the pud entry that this pmd is folded into
80295@@ -16,11 +21,6 @@ struct mm_struct;
80296 */
80297 typedef struct { pud_t pud; } pmd_t;
80298
80299-#define PMD_SHIFT PUD_SHIFT
80300-#define PTRS_PER_PMD 1
80301-#define PMD_SIZE (1UL << PMD_SHIFT)
80302-#define PMD_MASK (~(PMD_SIZE-1))
80303-
80304 /*
80305 * The "pud_xxx()" functions here are trivial for a folded two-level
80306 * setup: the pmd is never bad, and a pmd always exists (as it's folded
80307diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
80308index 810431d..0ec4804f 100644
80309--- a/include/asm-generic/pgtable-nopud.h
80310+++ b/include/asm-generic/pgtable-nopud.h
80311@@ -1,10 +1,15 @@
80312 #ifndef _PGTABLE_NOPUD_H
80313 #define _PGTABLE_NOPUD_H
80314
80315-#ifndef __ASSEMBLY__
80316-
80317 #define __PAGETABLE_PUD_FOLDED
80318
80319+#define PUD_SHIFT PGDIR_SHIFT
80320+#define PTRS_PER_PUD 1
80321+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
80322+#define PUD_MASK (~(PUD_SIZE-1))
80323+
80324+#ifndef __ASSEMBLY__
80325+
80326 /*
80327 * Having the pud type consist of a pgd gets the size right, and allows
80328 * us to conceptually access the pgd entry that this pud is folded into
80329@@ -12,11 +17,6 @@
80330 */
80331 typedef struct { pgd_t pgd; } pud_t;
80332
80333-#define PUD_SHIFT PGDIR_SHIFT
80334-#define PTRS_PER_PUD 1
80335-#define PUD_SIZE (1UL << PUD_SHIFT)
80336-#define PUD_MASK (~(PUD_SIZE-1))
80337-
80338 /*
80339 * The "pgd_xxx()" functions here are trivial for a folded two-level
80340 * setup: the pud is never bad, and a pud always exists (as it's folded
80341@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
80342 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
80343
80344 #define pgd_populate(mm, pgd, pud) do { } while (0)
80345+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
80346 /*
80347 * (puds are folded into pgds so this doesn't get actually called,
80348 * but the define is needed for a generic inline function.)
80349diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
80350index 53b2acc..f4568e7 100644
80351--- a/include/asm-generic/pgtable.h
80352+++ b/include/asm-generic/pgtable.h
80353@@ -819,6 +819,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
80354 }
80355 #endif /* CONFIG_NUMA_BALANCING */
80356
80357+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
80358+#ifdef CONFIG_PAX_KERNEXEC
80359+#error KERNEXEC requires pax_open_kernel
80360+#else
80361+static inline unsigned long pax_open_kernel(void) { return 0; }
80362+#endif
80363+#endif
80364+
80365+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
80366+#ifdef CONFIG_PAX_KERNEXEC
80367+#error KERNEXEC requires pax_close_kernel
80368+#else
80369+static inline unsigned long pax_close_kernel(void) { return 0; }
80370+#endif
80371+#endif
80372+
80373 #endif /* CONFIG_MMU */
80374
80375 #endif /* !__ASSEMBLY__ */
80376diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
80377index 72d8803..cb9749c 100644
80378--- a/include/asm-generic/uaccess.h
80379+++ b/include/asm-generic/uaccess.h
80380@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
80381 return __clear_user(to, n);
80382 }
80383
80384+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
80385+#ifdef CONFIG_PAX_MEMORY_UDEREF
80386+#error UDEREF requires pax_open_userland
80387+#else
80388+static inline unsigned long pax_open_userland(void) { return 0; }
80389+#endif
80390+#endif
80391+
80392+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
80393+#ifdef CONFIG_PAX_MEMORY_UDEREF
80394+#error UDEREF requires pax_close_userland
80395+#else
80396+static inline unsigned long pax_close_userland(void) { return 0; }
80397+#endif
80398+#endif
80399+
80400 #endif /* __ASM_GENERIC_UACCESS_H */
80401diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
80402index 5ba0360..e85c934 100644
80403--- a/include/asm-generic/vmlinux.lds.h
80404+++ b/include/asm-generic/vmlinux.lds.h
80405@@ -231,6 +231,7 @@
80406 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
80407 VMLINUX_SYMBOL(__start_rodata) = .; \
80408 *(.rodata) *(.rodata.*) \
80409+ *(.data..read_only) \
80410 *(__vermagic) /* Kernel version magic */ \
80411 . = ALIGN(8); \
80412 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
80413@@ -722,17 +723,18 @@
80414 * section in the linker script will go there too. @phdr should have
80415 * a leading colon.
80416 *
80417- * Note that this macros defines __per_cpu_load as an absolute symbol.
80418+ * Note that this macros defines per_cpu_load as an absolute symbol.
80419 * If there is no need to put the percpu section at a predetermined
80420 * address, use PERCPU_SECTION.
80421 */
80422 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
80423- VMLINUX_SYMBOL(__per_cpu_load) = .; \
80424- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
80425+ per_cpu_load = .; \
80426+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
80427 - LOAD_OFFSET) { \
80428+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
80429 PERCPU_INPUT(cacheline) \
80430 } phdr \
80431- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
80432+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
80433
80434 /**
80435 * PERCPU_SECTION - define output section for percpu area, simple version
80436diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
80437index 623a59c..1e79ab9 100644
80438--- a/include/crypto/algapi.h
80439+++ b/include/crypto/algapi.h
80440@@ -34,7 +34,7 @@ struct crypto_type {
80441 unsigned int maskclear;
80442 unsigned int maskset;
80443 unsigned int tfmsize;
80444-};
80445+} __do_const;
80446
80447 struct crypto_instance {
80448 struct crypto_alg alg;
80449diff --git a/include/drm/drmP.h b/include/drm/drmP.h
80450index 1968907..7d9ed9f 100644
80451--- a/include/drm/drmP.h
80452+++ b/include/drm/drmP.h
80453@@ -68,6 +68,7 @@
80454 #include <linux/workqueue.h>
80455 #include <linux/poll.h>
80456 #include <asm/pgalloc.h>
80457+#include <asm/local.h>
80458 #include <drm/drm.h>
80459 #include <drm/drm_sarea.h>
80460 #include <drm/drm_vma_manager.h>
80461@@ -260,10 +261,12 @@ do { \
80462 * \param cmd command.
80463 * \param arg argument.
80464 */
80465-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
80466+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
80467+ struct drm_file *file_priv);
80468+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
80469 struct drm_file *file_priv);
80470
80471-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80472+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
80473 unsigned long arg);
80474
80475 #define DRM_IOCTL_NR(n) _IOC_NR(n)
80476@@ -279,10 +282,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80477 struct drm_ioctl_desc {
80478 unsigned int cmd;
80479 int flags;
80480- drm_ioctl_t *func;
80481+ drm_ioctl_t func;
80482 unsigned int cmd_drv;
80483 const char *name;
80484-};
80485+} __do_const;
80486
80487 /**
80488 * Creates a driver or general drm_ioctl_desc array entry for the given
80489@@ -946,7 +949,8 @@ struct drm_info_list {
80490 int (*show)(struct seq_file*, void*); /** show callback */
80491 u32 driver_features; /**< Required driver features for this entry */
80492 void *data;
80493-};
80494+} __do_const;
80495+typedef struct drm_info_list __no_const drm_info_list_no_const;
80496
80497 /**
80498 * debugfs node structure. This structure represents a debugfs file.
80499@@ -1030,7 +1034,7 @@ struct drm_device {
80500
80501 /** \name Usage Counters */
80502 /*@{ */
80503- int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80504+ local_t open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80505 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
80506 int buf_use; /**< Buffers in use -- cannot alloc */
80507 atomic_t buf_alloc; /**< Buffer allocation in progress */
80508diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
80509index a3d75fe..6802f9c 100644
80510--- a/include/drm/drm_crtc_helper.h
80511+++ b/include/drm/drm_crtc_helper.h
80512@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
80513 struct drm_connector *connector);
80514 /* disable encoder when not in use - more explicit than dpms off */
80515 void (*disable)(struct drm_encoder *encoder);
80516-};
80517+} __no_const;
80518
80519 /**
80520 * drm_connector_helper_funcs - helper operations for connectors
80521diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
80522index a70d456..6ea07cd 100644
80523--- a/include/drm/i915_pciids.h
80524+++ b/include/drm/i915_pciids.h
80525@@ -37,7 +37,7 @@
80526 */
80527 #define INTEL_VGA_DEVICE(id, info) { \
80528 0x8086, id, \
80529- ~0, ~0, \
80530+ PCI_ANY_ID, PCI_ANY_ID, \
80531 0x030000, 0xff0000, \
80532 (unsigned long) info }
80533
80534diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
80535index 72dcbe8..8db58d7 100644
80536--- a/include/drm/ttm/ttm_memory.h
80537+++ b/include/drm/ttm/ttm_memory.h
80538@@ -48,7 +48,7 @@
80539
80540 struct ttm_mem_shrink {
80541 int (*do_shrink) (struct ttm_mem_shrink *);
80542-};
80543+} __no_const;
80544
80545 /**
80546 * struct ttm_mem_global - Global memory accounting structure.
80547diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
80548index 49a8284..9643967 100644
80549--- a/include/drm/ttm/ttm_page_alloc.h
80550+++ b/include/drm/ttm/ttm_page_alloc.h
80551@@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
80552 */
80553 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
80554
80555+struct device;
80556 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80557 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80558
80559diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
80560index 4b840e8..155d235 100644
80561--- a/include/keys/asymmetric-subtype.h
80562+++ b/include/keys/asymmetric-subtype.h
80563@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
80564 /* Verify the signature on a key of this subtype (optional) */
80565 int (*verify_signature)(const struct key *key,
80566 const struct public_key_signature *sig);
80567-};
80568+} __do_const;
80569
80570 /**
80571 * asymmetric_key_subtype - Get the subtype from an asymmetric key
80572diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
80573index c1da539..1dcec55 100644
80574--- a/include/linux/atmdev.h
80575+++ b/include/linux/atmdev.h
80576@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
80577 #endif
80578
80579 struct k_atm_aal_stats {
80580-#define __HANDLE_ITEM(i) atomic_t i
80581+#define __HANDLE_ITEM(i) atomic_unchecked_t i
80582 __AAL_STAT_ITEMS
80583 #undef __HANDLE_ITEM
80584 };
80585@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
80586 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
80587 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
80588 struct module *owner;
80589-};
80590+} __do_const ;
80591
80592 struct atmphy_ops {
80593 int (*start)(struct atm_dev *dev);
80594diff --git a/include/linux/audit.h b/include/linux/audit.h
80595index 22cfddb..1514eef 100644
80596--- a/include/linux/audit.h
80597+++ b/include/linux/audit.h
80598@@ -86,7 +86,7 @@ extern unsigned compat_dir_class[];
80599 extern unsigned compat_chattr_class[];
80600 extern unsigned compat_signal_class[];
80601
80602-extern int __weak audit_classify_compat_syscall(int abi, unsigned syscall);
80603+extern int audit_classify_compat_syscall(int abi, unsigned syscall);
80604
80605 /* audit_names->type values */
80606 #define AUDIT_TYPE_UNKNOWN 0 /* we don't know yet */
80607@@ -210,7 +210,7 @@ static inline void audit_ptrace(struct task_struct *t)
80608 extern unsigned int audit_serial(void);
80609 extern int auditsc_get_stamp(struct audit_context *ctx,
80610 struct timespec *t, unsigned int *serial);
80611-extern int audit_set_loginuid(kuid_t loginuid);
80612+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
80613
80614 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
80615 {
80616diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
80617index 61f29e5..e67c658 100644
80618--- a/include/linux/binfmts.h
80619+++ b/include/linux/binfmts.h
80620@@ -44,7 +44,7 @@ struct linux_binprm {
80621 unsigned interp_flags;
80622 unsigned interp_data;
80623 unsigned long loader, exec;
80624-};
80625+} __randomize_layout;
80626
80627 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
80628 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
80629@@ -73,8 +73,10 @@ struct linux_binfmt {
80630 int (*load_binary)(struct linux_binprm *);
80631 int (*load_shlib)(struct file *);
80632 int (*core_dump)(struct coredump_params *cprm);
80633+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
80634+ void (*handle_mmap)(struct file *);
80635 unsigned long min_coredump; /* minimal dump size */
80636-};
80637+} __do_const __randomize_layout;
80638
80639 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
80640
80641diff --git a/include/linux/bitops.h b/include/linux/bitops.h
80642index 38b5f5c..645018c 100644
80643--- a/include/linux/bitops.h
80644+++ b/include/linux/bitops.h
80645@@ -125,7 +125,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
80646 * @word: value to rotate
80647 * @shift: bits to roll
80648 */
80649-static inline __u32 rol32(__u32 word, unsigned int shift)
80650+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
80651 {
80652 return (word << shift) | (word >> (32 - shift));
80653 }
80654@@ -135,7 +135,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
80655 * @word: value to rotate
80656 * @shift: bits to roll
80657 */
80658-static inline __u32 ror32(__u32 word, unsigned int shift)
80659+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
80660 {
80661 return (word >> shift) | (word << (32 - shift));
80662 }
80663@@ -191,7 +191,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
80664 return (__s32)(value << shift) >> shift;
80665 }
80666
80667-static inline unsigned fls_long(unsigned long l)
80668+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
80669 {
80670 if (sizeof(l) == 4)
80671 return fls(l);
80672diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
80673index f2057ff8..59dfa2d 100644
80674--- a/include/linux/blkdev.h
80675+++ b/include/linux/blkdev.h
80676@@ -1625,7 +1625,7 @@ struct block_device_operations {
80677 /* this callback is with swap_lock and sometimes page table lock held */
80678 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
80679 struct module *owner;
80680-};
80681+} __do_const;
80682
80683 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
80684 unsigned long);
80685diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
80686index afc1343..9735539 100644
80687--- a/include/linux/blktrace_api.h
80688+++ b/include/linux/blktrace_api.h
80689@@ -25,7 +25,7 @@ struct blk_trace {
80690 struct dentry *dropped_file;
80691 struct dentry *msg_file;
80692 struct list_head running_list;
80693- atomic_t dropped;
80694+ atomic_unchecked_t dropped;
80695 };
80696
80697 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
80698diff --git a/include/linux/cache.h b/include/linux/cache.h
80699index 17e7e82..1d7da26 100644
80700--- a/include/linux/cache.h
80701+++ b/include/linux/cache.h
80702@@ -16,6 +16,14 @@
80703 #define __read_mostly
80704 #endif
80705
80706+#ifndef __read_only
80707+#ifdef CONFIG_PAX_KERNEXEC
80708+#error KERNEXEC requires __read_only
80709+#else
80710+#define __read_only __read_mostly
80711+#endif
80712+#endif
80713+
80714 #ifndef ____cacheline_aligned
80715 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
80716 #endif
80717diff --git a/include/linux/capability.h b/include/linux/capability.h
80718index aa93e5e..985a1b0 100644
80719--- a/include/linux/capability.h
80720+++ b/include/linux/capability.h
80721@@ -214,9 +214,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
80722 extern bool capable(int cap);
80723 extern bool ns_capable(struct user_namespace *ns, int cap);
80724 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
80725+extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
80726 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
80727+extern bool capable_nolog(int cap);
80728+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
80729
80730 /* audit system wants to get cap info from files as well */
80731 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
80732
80733+extern int is_privileged_binary(const struct dentry *dentry);
80734+
80735 #endif /* !_LINUX_CAPABILITY_H */
80736diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
80737index 8609d57..86e4d79 100644
80738--- a/include/linux/cdrom.h
80739+++ b/include/linux/cdrom.h
80740@@ -87,7 +87,6 @@ struct cdrom_device_ops {
80741
80742 /* driver specifications */
80743 const int capability; /* capability flags */
80744- int n_minors; /* number of active minor devices */
80745 /* handle uniform packets for scsi type devices (scsi,atapi) */
80746 int (*generic_packet) (struct cdrom_device_info *,
80747 struct packet_command *);
80748diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
80749index 4ce9056..86caac6 100644
80750--- a/include/linux/cleancache.h
80751+++ b/include/linux/cleancache.h
80752@@ -31,7 +31,7 @@ struct cleancache_ops {
80753 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
80754 void (*invalidate_inode)(int, struct cleancache_filekey);
80755 void (*invalidate_fs)(int);
80756-};
80757+} __no_const;
80758
80759 extern struct cleancache_ops *
80760 cleancache_register_ops(struct cleancache_ops *ops);
80761diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
80762index da6996e..9d13d5f 100644
80763--- a/include/linux/clk-provider.h
80764+++ b/include/linux/clk-provider.h
80765@@ -180,6 +180,7 @@ struct clk_ops {
80766 void (*init)(struct clk_hw *hw);
80767 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
80768 };
80769+typedef struct clk_ops __no_const clk_ops_no_const;
80770
80771 /**
80772 * struct clk_init_data - holds init data that's common to all clocks and is
80773diff --git a/include/linux/compat.h b/include/linux/compat.h
80774index e649426..a74047b 100644
80775--- a/include/linux/compat.h
80776+++ b/include/linux/compat.h
80777@@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
80778 compat_size_t __user *len_ptr);
80779
80780 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
80781-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
80782+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
80783 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
80784 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
80785 compat_ssize_t msgsz, int msgflg);
80786@@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
80787 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
80788 compat_ulong_t addr, compat_ulong_t data);
80789 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
80790- compat_long_t addr, compat_long_t data);
80791+ compat_ulong_t addr, compat_ulong_t data);
80792
80793 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
80794 /*
80795diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
80796index 2507fd2..55203f8 100644
80797--- a/include/linux/compiler-gcc4.h
80798+++ b/include/linux/compiler-gcc4.h
80799@@ -39,9 +39,34 @@
80800 # define __compiletime_warning(message) __attribute__((warning(message)))
80801 # define __compiletime_error(message) __attribute__((error(message)))
80802 #endif /* __CHECKER__ */
80803+
80804+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
80805+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
80806+#define __bos0(ptr) __bos((ptr), 0)
80807+#define __bos1(ptr) __bos((ptr), 1)
80808 #endif /* GCC_VERSION >= 40300 */
80809
80810 #if GCC_VERSION >= 40500
80811+
80812+#ifdef RANDSTRUCT_PLUGIN
80813+#define __randomize_layout __attribute__((randomize_layout))
80814+#define __no_randomize_layout __attribute__((no_randomize_layout))
80815+#endif
80816+
80817+#ifdef CONSTIFY_PLUGIN
80818+#define __no_const __attribute__((no_const))
80819+#define __do_const __attribute__((do_const))
80820+#endif
80821+
80822+#ifdef SIZE_OVERFLOW_PLUGIN
80823+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
80824+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
80825+#endif
80826+
80827+#ifdef LATENT_ENTROPY_PLUGIN
80828+#define __latent_entropy __attribute__((latent_entropy))
80829+#endif
80830+
80831 /*
80832 * Mark a position in code as unreachable. This can be used to
80833 * suppress control flow warnings after asm blocks that transfer
80834diff --git a/include/linux/compiler.h b/include/linux/compiler.h
80835index d5ad7b1..3b74638 100644
80836--- a/include/linux/compiler.h
80837+++ b/include/linux/compiler.h
80838@@ -5,11 +5,14 @@
80839
80840 #ifdef __CHECKER__
80841 # define __user __attribute__((noderef, address_space(1)))
80842+# define __force_user __force __user
80843 # define __kernel __attribute__((address_space(0)))
80844+# define __force_kernel __force __kernel
80845 # define __safe __attribute__((safe))
80846 # define __force __attribute__((force))
80847 # define __nocast __attribute__((nocast))
80848 # define __iomem __attribute__((noderef, address_space(2)))
80849+# define __force_iomem __force __iomem
80850 # define __must_hold(x) __attribute__((context(x,1,1)))
80851 # define __acquires(x) __attribute__((context(x,0,1)))
80852 # define __releases(x) __attribute__((context(x,1,0)))
80853@@ -17,20 +20,37 @@
80854 # define __release(x) __context__(x,-1)
80855 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
80856 # define __percpu __attribute__((noderef, address_space(3)))
80857+# define __force_percpu __force __percpu
80858 #ifdef CONFIG_SPARSE_RCU_POINTER
80859 # define __rcu __attribute__((noderef, address_space(4)))
80860+# define __force_rcu __force __rcu
80861 #else
80862 # define __rcu
80863+# define __force_rcu
80864 #endif
80865 extern void __chk_user_ptr(const volatile void __user *);
80866 extern void __chk_io_ptr(const volatile void __iomem *);
80867 #else
80868-# define __user
80869-# define __kernel
80870+# ifdef CHECKER_PLUGIN
80871+//# define __user
80872+//# define __force_user
80873+//# define __kernel
80874+//# define __force_kernel
80875+# else
80876+# ifdef STRUCTLEAK_PLUGIN
80877+# define __user __attribute__((user))
80878+# else
80879+# define __user
80880+# endif
80881+# define __force_user
80882+# define __kernel
80883+# define __force_kernel
80884+# endif
80885 # define __safe
80886 # define __force
80887 # define __nocast
80888 # define __iomem
80889+# define __force_iomem
80890 # define __chk_user_ptr(x) (void)0
80891 # define __chk_io_ptr(x) (void)0
80892 # define __builtin_warning(x, y...) (1)
80893@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
80894 # define __release(x) (void)0
80895 # define __cond_lock(x,c) (c)
80896 # define __percpu
80897+# define __force_percpu
80898 # define __rcu
80899+# define __force_rcu
80900 #endif
80901
80902 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
80903@@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80904 # define __attribute_const__ /* unimplemented */
80905 #endif
80906
80907+#ifndef __randomize_layout
80908+# define __randomize_layout
80909+#endif
80910+
80911+#ifndef __no_randomize_layout
80912+# define __no_randomize_layout
80913+#endif
80914+
80915+#ifndef __no_const
80916+# define __no_const
80917+#endif
80918+
80919+#ifndef __do_const
80920+# define __do_const
80921+#endif
80922+
80923+#ifndef __size_overflow
80924+# define __size_overflow(...)
80925+#endif
80926+
80927+#ifndef __intentional_overflow
80928+# define __intentional_overflow(...)
80929+#endif
80930+
80931+#ifndef __latent_entropy
80932+# define __latent_entropy
80933+#endif
80934+
80935 /*
80936 * Tell gcc if a function is cold. The compiler will assume any path
80937 * directly leading to the call is unlikely.
80938@@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80939 #define __cold
80940 #endif
80941
80942+#ifndef __alloc_size
80943+#define __alloc_size(...)
80944+#endif
80945+
80946+#ifndef __bos
80947+#define __bos(ptr, arg)
80948+#endif
80949+
80950+#ifndef __bos0
80951+#define __bos0(ptr)
80952+#endif
80953+
80954+#ifndef __bos1
80955+#define __bos1(ptr)
80956+#endif
80957+
80958 /* Simple shorthand for a section definition */
80959 #ifndef __section
80960 # define __section(S) __attribute__ ((__section__(#S)))
80961@@ -378,7 +444,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80962 * use is to mediate communication between process-level code and irq/NMI
80963 * handlers, all running on the same CPU.
80964 */
80965-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
80966+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
80967+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
80968
80969 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
80970 #ifdef CONFIG_KPROBES
80971diff --git a/include/linux/completion.h b/include/linux/completion.h
80972index 5d5aaae..0ea9b84 100644
80973--- a/include/linux/completion.h
80974+++ b/include/linux/completion.h
80975@@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
80976
80977 extern void wait_for_completion(struct completion *);
80978 extern void wait_for_completion_io(struct completion *);
80979-extern int wait_for_completion_interruptible(struct completion *x);
80980-extern int wait_for_completion_killable(struct completion *x);
80981+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
80982+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
80983 extern unsigned long wait_for_completion_timeout(struct completion *x,
80984- unsigned long timeout);
80985+ unsigned long timeout) __intentional_overflow(-1);
80986 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
80987- unsigned long timeout);
80988+ unsigned long timeout) __intentional_overflow(-1);
80989 extern long wait_for_completion_interruptible_timeout(
80990- struct completion *x, unsigned long timeout);
80991+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80992 extern long wait_for_completion_killable_timeout(
80993- struct completion *x, unsigned long timeout);
80994+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80995 extern bool try_wait_for_completion(struct completion *x);
80996 extern bool completion_done(struct completion *x);
80997
80998diff --git a/include/linux/configfs.h b/include/linux/configfs.h
80999index 34025df..d94bbbc 100644
81000--- a/include/linux/configfs.h
81001+++ b/include/linux/configfs.h
81002@@ -125,7 +125,7 @@ struct configfs_attribute {
81003 const char *ca_name;
81004 struct module *ca_owner;
81005 umode_t ca_mode;
81006-};
81007+} __do_const;
81008
81009 /*
81010 * Users often need to create attribute structures for their configurable
81011diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
81012index 7d1955a..d86a3ca 100644
81013--- a/include/linux/cpufreq.h
81014+++ b/include/linux/cpufreq.h
81015@@ -203,6 +203,7 @@ struct global_attr {
81016 ssize_t (*store)(struct kobject *a, struct attribute *b,
81017 const char *c, size_t count);
81018 };
81019+typedef struct global_attr __no_const global_attr_no_const;
81020
81021 #define define_one_global_ro(_name) \
81022 static struct global_attr _name = \
81023@@ -269,7 +270,7 @@ struct cpufreq_driver {
81024 bool boost_supported;
81025 bool boost_enabled;
81026 int (*set_boost) (int state);
81027-};
81028+} __do_const;
81029
81030 /* flags */
81031 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
81032diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
81033index 25e0df6..952dffd 100644
81034--- a/include/linux/cpuidle.h
81035+++ b/include/linux/cpuidle.h
81036@@ -50,7 +50,8 @@ struct cpuidle_state {
81037 int index);
81038
81039 int (*enter_dead) (struct cpuidle_device *dev, int index);
81040-};
81041+} __do_const;
81042+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
81043
81044 /* Idle State Flags */
81045 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
81046@@ -209,7 +210,7 @@ struct cpuidle_governor {
81047 void (*reflect) (struct cpuidle_device *dev, int index);
81048
81049 struct module *owner;
81050-};
81051+} __do_const;
81052
81053 #ifdef CONFIG_CPU_IDLE
81054 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
81055diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
81056index 2997af6..424ddc1 100644
81057--- a/include/linux/cpumask.h
81058+++ b/include/linux/cpumask.h
81059@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
81060 }
81061
81062 /* Valid inputs for n are -1 and 0. */
81063-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
81064+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
81065 {
81066 return n+1;
81067 }
81068
81069-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
81070+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
81071 {
81072 return n+1;
81073 }
81074
81075-static inline unsigned int cpumask_next_and(int n,
81076+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
81077 const struct cpumask *srcp,
81078 const struct cpumask *andp)
81079 {
81080@@ -174,7 +174,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
81081 *
81082 * Returns >= nr_cpu_ids if no further cpus set.
81083 */
81084-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
81085+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
81086 {
81087 /* -1 is a legal arg here. */
81088 if (n != -1)
81089@@ -189,7 +189,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
81090 *
81091 * Returns >= nr_cpu_ids if no further cpus unset.
81092 */
81093-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
81094+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
81095 {
81096 /* -1 is a legal arg here. */
81097 if (n != -1)
81098@@ -197,7 +197,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
81099 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
81100 }
81101
81102-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
81103+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
81104 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
81105 int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp);
81106
81107diff --git a/include/linux/cred.h b/include/linux/cred.h
81108index b2d0820..2ecafd3 100644
81109--- a/include/linux/cred.h
81110+++ b/include/linux/cred.h
81111@@ -35,7 +35,7 @@ struct group_info {
81112 int nblocks;
81113 kgid_t small_block[NGROUPS_SMALL];
81114 kgid_t *blocks[0];
81115-};
81116+} __randomize_layout;
81117
81118 /**
81119 * get_group_info - Get a reference to a group info structure
81120@@ -136,7 +136,7 @@ struct cred {
81121 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
81122 struct group_info *group_info; /* supplementary groups for euid/fsgid */
81123 struct rcu_head rcu; /* RCU deletion hook */
81124-};
81125+} __randomize_layout;
81126
81127 extern void __put_cred(struct cred *);
81128 extern void exit_creds(struct task_struct *);
81129@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
81130 static inline void validate_process_creds(void)
81131 {
81132 }
81133+static inline void validate_task_creds(struct task_struct *task)
81134+{
81135+}
81136 #endif
81137
81138 /**
81139@@ -331,6 +334,7 @@ static inline void put_cred(const struct cred *_cred)
81140
81141 #define task_uid(task) (task_cred_xxx((task), uid))
81142 #define task_euid(task) (task_cred_xxx((task), euid))
81143+#define task_securebits(task) (task_cred_xxx((task), securebits))
81144
81145 #define current_cred_xxx(xxx) \
81146 ({ \
81147diff --git a/include/linux/crypto.h b/include/linux/crypto.h
81148index d45e949..51cf5ea 100644
81149--- a/include/linux/crypto.h
81150+++ b/include/linux/crypto.h
81151@@ -373,7 +373,7 @@ struct cipher_tfm {
81152 const u8 *key, unsigned int keylen);
81153 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
81154 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
81155-};
81156+} __no_const;
81157
81158 struct hash_tfm {
81159 int (*init)(struct hash_desc *desc);
81160@@ -394,13 +394,13 @@ struct compress_tfm {
81161 int (*cot_decompress)(struct crypto_tfm *tfm,
81162 const u8 *src, unsigned int slen,
81163 u8 *dst, unsigned int *dlen);
81164-};
81165+} __no_const;
81166
81167 struct rng_tfm {
81168 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
81169 unsigned int dlen);
81170 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
81171-};
81172+} __no_const;
81173
81174 #define crt_ablkcipher crt_u.ablkcipher
81175 #define crt_aead crt_u.aead
81176diff --git a/include/linux/ctype.h b/include/linux/ctype.h
81177index 653589e..4ef254a 100644
81178--- a/include/linux/ctype.h
81179+++ b/include/linux/ctype.h
81180@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
81181 * Fast implementation of tolower() for internal usage. Do not use in your
81182 * code.
81183 */
81184-static inline char _tolower(const char c)
81185+static inline unsigned char _tolower(const unsigned char c)
81186 {
81187 return c | 0x20;
81188 }
81189diff --git a/include/linux/dcache.h b/include/linux/dcache.h
81190index 75a227c..1456987 100644
81191--- a/include/linux/dcache.h
81192+++ b/include/linux/dcache.h
81193@@ -134,7 +134,7 @@ struct dentry {
81194 } d_u;
81195 struct list_head d_subdirs; /* our children */
81196 struct hlist_node d_alias; /* inode alias list */
81197-};
81198+} __randomize_layout;
81199
81200 /*
81201 * dentry->d_lock spinlock nesting subclasses:
81202diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
81203index 7925bf0..d5143d2 100644
81204--- a/include/linux/decompress/mm.h
81205+++ b/include/linux/decompress/mm.h
81206@@ -77,7 +77,7 @@ static void free(void *where)
81207 * warnings when not needed (indeed large_malloc / large_free are not
81208 * needed by inflate */
81209
81210-#define malloc(a) kmalloc(a, GFP_KERNEL)
81211+#define malloc(a) kmalloc((a), GFP_KERNEL)
81212 #define free(a) kfree(a)
81213
81214 #define large_malloc(a) vmalloc(a)
81215diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
81216index f1863dc..5c26074 100644
81217--- a/include/linux/devfreq.h
81218+++ b/include/linux/devfreq.h
81219@@ -114,7 +114,7 @@ struct devfreq_governor {
81220 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
81221 int (*event_handler)(struct devfreq *devfreq,
81222 unsigned int event, void *data);
81223-};
81224+} __do_const;
81225
81226 /**
81227 * struct devfreq - Device devfreq structure
81228diff --git a/include/linux/device.h b/include/linux/device.h
81229index 43d183a..03b6ba2 100644
81230--- a/include/linux/device.h
81231+++ b/include/linux/device.h
81232@@ -310,7 +310,7 @@ struct subsys_interface {
81233 struct list_head node;
81234 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
81235 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
81236-};
81237+} __do_const;
81238
81239 int subsys_interface_register(struct subsys_interface *sif);
81240 void subsys_interface_unregister(struct subsys_interface *sif);
81241@@ -506,7 +506,7 @@ struct device_type {
81242 void (*release)(struct device *dev);
81243
81244 const struct dev_pm_ops *pm;
81245-};
81246+} __do_const;
81247
81248 /* interface for exporting device attributes */
81249 struct device_attribute {
81250@@ -516,11 +516,12 @@ struct device_attribute {
81251 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
81252 const char *buf, size_t count);
81253 };
81254+typedef struct device_attribute __no_const device_attribute_no_const;
81255
81256 struct dev_ext_attribute {
81257 struct device_attribute attr;
81258 void *var;
81259-};
81260+} __do_const;
81261
81262 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
81263 char *buf);
81264diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
81265index 931b709..89b2d89 100644
81266--- a/include/linux/dma-mapping.h
81267+++ b/include/linux/dma-mapping.h
81268@@ -60,7 +60,7 @@ struct dma_map_ops {
81269 u64 (*get_required_mask)(struct device *dev);
81270 #endif
81271 int is_phys;
81272-};
81273+} __do_const;
81274
81275 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
81276
81277diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
81278index 1f9e642..39e4263 100644
81279--- a/include/linux/dmaengine.h
81280+++ b/include/linux/dmaengine.h
81281@@ -1147,9 +1147,9 @@ struct dma_pinned_list {
81282 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
81283 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
81284
81285-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
81286+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
81287 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
81288-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
81289+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
81290 struct dma_pinned_list *pinned_list, struct page *page,
81291 unsigned int offset, size_t len);
81292
81293diff --git a/include/linux/efi.h b/include/linux/efi.h
81294index 45cb4ff..c9b4912 100644
81295--- a/include/linux/efi.h
81296+++ b/include/linux/efi.h
81297@@ -1036,6 +1036,7 @@ struct efivar_operations {
81298 efi_set_variable_t *set_variable;
81299 efi_query_variable_store_t *query_variable_store;
81300 };
81301+typedef struct efivar_operations __no_const efivar_operations_no_const;
81302
81303 struct efivars {
81304 /*
81305diff --git a/include/linux/elf.h b/include/linux/elf.h
81306index 67a5fa7..b817372 100644
81307--- a/include/linux/elf.h
81308+++ b/include/linux/elf.h
81309@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
81310 #define elf_note elf32_note
81311 #define elf_addr_t Elf32_Off
81312 #define Elf_Half Elf32_Half
81313+#define elf_dyn Elf32_Dyn
81314
81315 #else
81316
81317@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
81318 #define elf_note elf64_note
81319 #define elf_addr_t Elf64_Off
81320 #define Elf_Half Elf64_Half
81321+#define elf_dyn Elf64_Dyn
81322
81323 #endif
81324
81325diff --git a/include/linux/err.h b/include/linux/err.h
81326index a729120..6ede2c9 100644
81327--- a/include/linux/err.h
81328+++ b/include/linux/err.h
81329@@ -20,12 +20,12 @@
81330
81331 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
81332
81333-static inline void * __must_check ERR_PTR(long error)
81334+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
81335 {
81336 return (void *) error;
81337 }
81338
81339-static inline long __must_check PTR_ERR(__force const void *ptr)
81340+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
81341 {
81342 return (long) ptr;
81343 }
81344diff --git a/include/linux/extcon.h b/include/linux/extcon.h
81345index 36f49c4..a2a1f4c 100644
81346--- a/include/linux/extcon.h
81347+++ b/include/linux/extcon.h
81348@@ -135,7 +135,7 @@ struct extcon_dev {
81349 /* /sys/class/extcon/.../mutually_exclusive/... */
81350 struct attribute_group attr_g_muex;
81351 struct attribute **attrs_muex;
81352- struct device_attribute *d_attrs_muex;
81353+ device_attribute_no_const *d_attrs_muex;
81354 };
81355
81356 /**
81357diff --git a/include/linux/fb.h b/include/linux/fb.h
81358index 09bb7a1..d98870a 100644
81359--- a/include/linux/fb.h
81360+++ b/include/linux/fb.h
81361@@ -305,7 +305,7 @@ struct fb_ops {
81362 /* called at KDB enter and leave time to prepare the console */
81363 int (*fb_debug_enter)(struct fb_info *info);
81364 int (*fb_debug_leave)(struct fb_info *info);
81365-};
81366+} __do_const;
81367
81368 #ifdef CONFIG_FB_TILEBLITTING
81369 #define FB_TILE_CURSOR_NONE 0
81370diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
81371index 230f87b..1fd0485 100644
81372--- a/include/linux/fdtable.h
81373+++ b/include/linux/fdtable.h
81374@@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
81375 void put_files_struct(struct files_struct *fs);
81376 void reset_files_struct(struct files_struct *);
81377 int unshare_files(struct files_struct **);
81378-struct files_struct *dup_fd(struct files_struct *, int *);
81379+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
81380 void do_close_on_exec(struct files_struct *);
81381 int iterate_fd(struct files_struct *, unsigned,
81382 int (*)(const void *, struct file *, unsigned),
81383diff --git a/include/linux/filter.h b/include/linux/filter.h
81384index a5227ab..c789945 100644
81385--- a/include/linux/filter.h
81386+++ b/include/linux/filter.h
81387@@ -9,6 +9,11 @@
81388 #include <linux/skbuff.h>
81389 #include <linux/workqueue.h>
81390 #include <uapi/linux/filter.h>
81391+#include <asm/cacheflush.h>
81392+
81393+struct sk_buff;
81394+struct sock;
81395+struct seccomp_data;
81396
81397 /* Internally used and optimized filter representation with extended
81398 * instruction set based on top of classic BPF.
81399@@ -320,20 +325,23 @@ struct sock_fprog_kern {
81400 struct sock_filter *filter;
81401 };
81402
81403-struct sk_buff;
81404-struct sock;
81405-struct seccomp_data;
81406+struct bpf_work_struct {
81407+ struct bpf_prog *prog;
81408+ struct work_struct work;
81409+};
81410
81411 struct bpf_prog {
81412+ u32 pages; /* Number of allocated pages */
81413 u32 jited:1, /* Is our filter JIT'ed? */
81414 len:31; /* Number of filter blocks */
81415 struct sock_fprog_kern *orig_prog; /* Original BPF program */
81416+ struct bpf_work_struct *work; /* Deferred free work struct */
81417 unsigned int (*bpf_func)(const struct sk_buff *skb,
81418 const struct bpf_insn *filter);
81419+ /* Instructions for interpreter */
81420 union {
81421 struct sock_filter insns[0];
81422 struct bpf_insn insnsi[0];
81423- struct work_struct work;
81424 };
81425 };
81426
81427@@ -353,6 +361,26 @@ static inline unsigned int bpf_prog_size(unsigned int proglen)
81428
81429 #define bpf_classic_proglen(fprog) (fprog->len * sizeof(fprog->filter[0]))
81430
81431+#ifdef CONFIG_DEBUG_SET_MODULE_RONX
81432+static inline void bpf_prog_lock_ro(struct bpf_prog *fp)
81433+{
81434+ set_memory_ro((unsigned long)fp, fp->pages);
81435+}
81436+
81437+static inline void bpf_prog_unlock_ro(struct bpf_prog *fp)
81438+{
81439+ set_memory_rw((unsigned long)fp, fp->pages);
81440+}
81441+#else
81442+static inline void bpf_prog_lock_ro(struct bpf_prog *fp)
81443+{
81444+}
81445+
81446+static inline void bpf_prog_unlock_ro(struct bpf_prog *fp)
81447+{
81448+}
81449+#endif /* CONFIG_DEBUG_SET_MODULE_RONX */
81450+
81451 int sk_filter(struct sock *sk, struct sk_buff *skb);
81452
81453 void bpf_prog_select_runtime(struct bpf_prog *fp);
81454@@ -361,6 +389,17 @@ void bpf_prog_free(struct bpf_prog *fp);
81455 int bpf_convert_filter(struct sock_filter *prog, int len,
81456 struct bpf_insn *new_prog, int *new_len);
81457
81458+struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags);
81459+struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size,
81460+ gfp_t gfp_extra_flags);
81461+void __bpf_prog_free(struct bpf_prog *fp);
81462+
81463+static inline void bpf_prog_unlock_free(struct bpf_prog *fp)
81464+{
81465+ bpf_prog_unlock_ro(fp);
81466+ __bpf_prog_free(fp);
81467+}
81468+
81469 int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog);
81470 void bpf_prog_destroy(struct bpf_prog *fp);
81471
81472@@ -450,7 +489,7 @@ static inline void bpf_jit_compile(struct bpf_prog *fp)
81473
81474 static inline void bpf_jit_free(struct bpf_prog *fp)
81475 {
81476- kfree(fp);
81477+ bpf_prog_unlock_free(fp);
81478 }
81479 #endif /* CONFIG_BPF_JIT */
81480
81481diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
81482index 8293262..2b3b8bd 100644
81483--- a/include/linux/frontswap.h
81484+++ b/include/linux/frontswap.h
81485@@ -11,7 +11,7 @@ struct frontswap_ops {
81486 int (*load)(unsigned, pgoff_t, struct page *);
81487 void (*invalidate_page)(unsigned, pgoff_t);
81488 void (*invalidate_area)(unsigned);
81489-};
81490+} __no_const;
81491
81492 extern bool frontswap_enabled;
81493 extern struct frontswap_ops *
81494diff --git a/include/linux/fs.h b/include/linux/fs.h
81495index 9418772..0155807 100644
81496--- a/include/linux/fs.h
81497+++ b/include/linux/fs.h
81498@@ -401,7 +401,7 @@ struct address_space {
81499 spinlock_t private_lock; /* for use by the address_space */
81500 struct list_head private_list; /* ditto */
81501 void *private_data; /* ditto */
81502-} __attribute__((aligned(sizeof(long))));
81503+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
81504 /*
81505 * On most architectures that alignment is already the case; but
81506 * must be enforced here for CRIS, to let the least significant bit
81507@@ -444,7 +444,7 @@ struct block_device {
81508 int bd_fsfreeze_count;
81509 /* Mutex for freeze */
81510 struct mutex bd_fsfreeze_mutex;
81511-};
81512+} __randomize_layout;
81513
81514 /*
81515 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
81516@@ -613,7 +613,7 @@ struct inode {
81517 #endif
81518
81519 void *i_private; /* fs or device private pointer */
81520-};
81521+} __randomize_layout;
81522
81523 static inline int inode_unhashed(struct inode *inode)
81524 {
81525@@ -806,7 +806,7 @@ struct file {
81526 struct list_head f_tfile_llink;
81527 #endif /* #ifdef CONFIG_EPOLL */
81528 struct address_space *f_mapping;
81529-} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
81530+} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
81531
81532 struct file_handle {
81533 __u32 handle_bytes;
81534@@ -934,7 +934,7 @@ struct file_lock {
81535 int state; /* state of grant or error if -ve */
81536 } afs;
81537 } fl_u;
81538-};
81539+} __randomize_layout;
81540
81541 /* The following constant reflects the upper bound of the file/locking space */
81542 #ifndef OFFSET_MAX
81543@@ -1284,7 +1284,7 @@ struct super_block {
81544 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
81545 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
81546 struct rcu_head rcu;
81547-};
81548+} __randomize_layout;
81549
81550 extern struct timespec current_fs_time(struct super_block *sb);
81551
81552@@ -1510,7 +1510,8 @@ struct file_operations {
81553 long (*fallocate)(struct file *file, int mode, loff_t offset,
81554 loff_t len);
81555 int (*show_fdinfo)(struct seq_file *m, struct file *f);
81556-};
81557+} __do_const __randomize_layout;
81558+typedef struct file_operations __no_const file_operations_no_const;
81559
81560 struct inode_operations {
81561 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
81562@@ -2796,4 +2797,14 @@ static inline bool dir_relax(struct inode *inode)
81563 return !IS_DEADDIR(inode);
81564 }
81565
81566+static inline bool is_sidechannel_device(const struct inode *inode)
81567+{
81568+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
81569+ umode_t mode = inode->i_mode;
81570+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
81571+#else
81572+ return false;
81573+#endif
81574+}
81575+
81576 #endif /* _LINUX_FS_H */
81577diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
81578index 0efc3e6..fd23610 100644
81579--- a/include/linux/fs_struct.h
81580+++ b/include/linux/fs_struct.h
81581@@ -6,13 +6,13 @@
81582 #include <linux/seqlock.h>
81583
81584 struct fs_struct {
81585- int users;
81586+ atomic_t users;
81587 spinlock_t lock;
81588 seqcount_t seq;
81589 int umask;
81590 int in_exec;
81591 struct path root, pwd;
81592-};
81593+} __randomize_layout;
81594
81595 extern struct kmem_cache *fs_cachep;
81596
81597diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
81598index 7714849..a4a5c7a 100644
81599--- a/include/linux/fscache-cache.h
81600+++ b/include/linux/fscache-cache.h
81601@@ -113,7 +113,7 @@ struct fscache_operation {
81602 fscache_operation_release_t release;
81603 };
81604
81605-extern atomic_t fscache_op_debug_id;
81606+extern atomic_unchecked_t fscache_op_debug_id;
81607 extern void fscache_op_work_func(struct work_struct *work);
81608
81609 extern void fscache_enqueue_operation(struct fscache_operation *);
81610@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
81611 INIT_WORK(&op->work, fscache_op_work_func);
81612 atomic_set(&op->usage, 1);
81613 op->state = FSCACHE_OP_ST_INITIALISED;
81614- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
81615+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
81616 op->processor = processor;
81617 op->release = release;
81618 INIT_LIST_HEAD(&op->pend_link);
81619diff --git a/include/linux/fscache.h b/include/linux/fscache.h
81620index 115bb81..e7b812b 100644
81621--- a/include/linux/fscache.h
81622+++ b/include/linux/fscache.h
81623@@ -152,7 +152,7 @@ struct fscache_cookie_def {
81624 * - this is mandatory for any object that may have data
81625 */
81626 void (*now_uncached)(void *cookie_netfs_data);
81627-};
81628+} __do_const;
81629
81630 /*
81631 * fscache cached network filesystem type
81632diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
81633index 1c804b0..1432c2b 100644
81634--- a/include/linux/fsnotify.h
81635+++ b/include/linux/fsnotify.h
81636@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
81637 struct inode *inode = file_inode(file);
81638 __u32 mask = FS_ACCESS;
81639
81640+ if (is_sidechannel_device(inode))
81641+ return;
81642+
81643 if (S_ISDIR(inode->i_mode))
81644 mask |= FS_ISDIR;
81645
81646@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
81647 struct inode *inode = file_inode(file);
81648 __u32 mask = FS_MODIFY;
81649
81650+ if (is_sidechannel_device(inode))
81651+ return;
81652+
81653 if (S_ISDIR(inode->i_mode))
81654 mask |= FS_ISDIR;
81655
81656@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
81657 */
81658 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
81659 {
81660- return kstrdup(name, GFP_KERNEL);
81661+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
81662 }
81663
81664 /*
81665diff --git a/include/linux/genhd.h b/include/linux/genhd.h
81666index ec274e0..e678159 100644
81667--- a/include/linux/genhd.h
81668+++ b/include/linux/genhd.h
81669@@ -194,7 +194,7 @@ struct gendisk {
81670 struct kobject *slave_dir;
81671
81672 struct timer_rand_state *random;
81673- atomic_t sync_io; /* RAID */
81674+ atomic_unchecked_t sync_io; /* RAID */
81675 struct disk_events *ev;
81676 #ifdef CONFIG_BLK_DEV_INTEGRITY
81677 struct blk_integrity *integrity;
81678@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
81679 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
81680
81681 /* drivers/char/random.c */
81682-extern void add_disk_randomness(struct gendisk *disk);
81683+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
81684 extern void rand_initialize_disk(struct gendisk *disk);
81685
81686 static inline sector_t get_start_sect(struct block_device *bdev)
81687diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
81688index c0894dd..2fbf10c 100644
81689--- a/include/linux/genl_magic_func.h
81690+++ b/include/linux/genl_magic_func.h
81691@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
81692 },
81693
81694 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
81695-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
81696+static struct genl_ops ZZZ_genl_ops[] = {
81697 #include GENL_MAGIC_INCLUDE_FILE
81698 };
81699
81700diff --git a/include/linux/gfp.h b/include/linux/gfp.h
81701index 5e7219d..b1ed627 100644
81702--- a/include/linux/gfp.h
81703+++ b/include/linux/gfp.h
81704@@ -34,6 +34,13 @@ struct vm_area_struct;
81705 #define ___GFP_NO_KSWAPD 0x400000u
81706 #define ___GFP_OTHER_NODE 0x800000u
81707 #define ___GFP_WRITE 0x1000000u
81708+
81709+#ifdef CONFIG_PAX_USERCOPY_SLABS
81710+#define ___GFP_USERCOPY 0x2000000u
81711+#else
81712+#define ___GFP_USERCOPY 0
81713+#endif
81714+
81715 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
81716
81717 /*
81718@@ -90,6 +97,7 @@ struct vm_area_struct;
81719 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
81720 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
81721 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
81722+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
81723
81724 /*
81725 * This may seem redundant, but it's a way of annotating false positives vs.
81726@@ -97,7 +105,7 @@ struct vm_area_struct;
81727 */
81728 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
81729
81730-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
81731+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
81732 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
81733
81734 /* This equals 0, but use constants in case they ever change */
81735@@ -155,6 +163,8 @@ struct vm_area_struct;
81736 /* 4GB DMA on some platforms */
81737 #define GFP_DMA32 __GFP_DMA32
81738
81739+#define GFP_USERCOPY __GFP_USERCOPY
81740+
81741 /* Convert GFP flags to their corresponding migrate type */
81742 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
81743 {
81744diff --git a/include/linux/gracl.h b/include/linux/gracl.h
81745new file mode 100644
81746index 0000000..edb2cb6
81747--- /dev/null
81748+++ b/include/linux/gracl.h
81749@@ -0,0 +1,340 @@
81750+#ifndef GR_ACL_H
81751+#define GR_ACL_H
81752+
81753+#include <linux/grdefs.h>
81754+#include <linux/resource.h>
81755+#include <linux/capability.h>
81756+#include <linux/dcache.h>
81757+#include <asm/resource.h>
81758+
81759+/* Major status information */
81760+
81761+#define GR_VERSION "grsecurity 3.0"
81762+#define GRSECURITY_VERSION 0x3000
81763+
81764+enum {
81765+ GR_SHUTDOWN = 0,
81766+ GR_ENABLE = 1,
81767+ GR_SPROLE = 2,
81768+ GR_OLDRELOAD = 3,
81769+ GR_SEGVMOD = 4,
81770+ GR_STATUS = 5,
81771+ GR_UNSPROLE = 6,
81772+ GR_PASSSET = 7,
81773+ GR_SPROLEPAM = 8,
81774+ GR_RELOAD = 9,
81775+};
81776+
81777+/* Password setup definitions
81778+ * kernel/grhash.c */
81779+enum {
81780+ GR_PW_LEN = 128,
81781+ GR_SALT_LEN = 16,
81782+ GR_SHA_LEN = 32,
81783+};
81784+
81785+enum {
81786+ GR_SPROLE_LEN = 64,
81787+};
81788+
81789+enum {
81790+ GR_NO_GLOB = 0,
81791+ GR_REG_GLOB,
81792+ GR_CREATE_GLOB
81793+};
81794+
81795+#define GR_NLIMITS 32
81796+
81797+/* Begin Data Structures */
81798+
81799+struct sprole_pw {
81800+ unsigned char *rolename;
81801+ unsigned char salt[GR_SALT_LEN];
81802+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
81803+};
81804+
81805+struct name_entry {
81806+ __u32 key;
81807+ ino_t inode;
81808+ dev_t device;
81809+ char *name;
81810+ __u16 len;
81811+ __u8 deleted;
81812+ struct name_entry *prev;
81813+ struct name_entry *next;
81814+};
81815+
81816+struct inodev_entry {
81817+ struct name_entry *nentry;
81818+ struct inodev_entry *prev;
81819+ struct inodev_entry *next;
81820+};
81821+
81822+struct acl_role_db {
81823+ struct acl_role_label **r_hash;
81824+ __u32 r_size;
81825+};
81826+
81827+struct inodev_db {
81828+ struct inodev_entry **i_hash;
81829+ __u32 i_size;
81830+};
81831+
81832+struct name_db {
81833+ struct name_entry **n_hash;
81834+ __u32 n_size;
81835+};
81836+
81837+struct crash_uid {
81838+ uid_t uid;
81839+ unsigned long expires;
81840+};
81841+
81842+struct gr_hash_struct {
81843+ void **table;
81844+ void **nametable;
81845+ void *first;
81846+ __u32 table_size;
81847+ __u32 used_size;
81848+ int type;
81849+};
81850+
81851+/* Userspace Grsecurity ACL data structures */
81852+
81853+struct acl_subject_label {
81854+ char *filename;
81855+ ino_t inode;
81856+ dev_t device;
81857+ __u32 mode;
81858+ kernel_cap_t cap_mask;
81859+ kernel_cap_t cap_lower;
81860+ kernel_cap_t cap_invert_audit;
81861+
81862+ struct rlimit res[GR_NLIMITS];
81863+ __u32 resmask;
81864+
81865+ __u8 user_trans_type;
81866+ __u8 group_trans_type;
81867+ uid_t *user_transitions;
81868+ gid_t *group_transitions;
81869+ __u16 user_trans_num;
81870+ __u16 group_trans_num;
81871+
81872+ __u32 sock_families[2];
81873+ __u32 ip_proto[8];
81874+ __u32 ip_type;
81875+ struct acl_ip_label **ips;
81876+ __u32 ip_num;
81877+ __u32 inaddr_any_override;
81878+
81879+ __u32 crashes;
81880+ unsigned long expires;
81881+
81882+ struct acl_subject_label *parent_subject;
81883+ struct gr_hash_struct *hash;
81884+ struct acl_subject_label *prev;
81885+ struct acl_subject_label *next;
81886+
81887+ struct acl_object_label **obj_hash;
81888+ __u32 obj_hash_size;
81889+ __u16 pax_flags;
81890+};
81891+
81892+struct role_allowed_ip {
81893+ __u32 addr;
81894+ __u32 netmask;
81895+
81896+ struct role_allowed_ip *prev;
81897+ struct role_allowed_ip *next;
81898+};
81899+
81900+struct role_transition {
81901+ char *rolename;
81902+
81903+ struct role_transition *prev;
81904+ struct role_transition *next;
81905+};
81906+
81907+struct acl_role_label {
81908+ char *rolename;
81909+ uid_t uidgid;
81910+ __u16 roletype;
81911+
81912+ __u16 auth_attempts;
81913+ unsigned long expires;
81914+
81915+ struct acl_subject_label *root_label;
81916+ struct gr_hash_struct *hash;
81917+
81918+ struct acl_role_label *prev;
81919+ struct acl_role_label *next;
81920+
81921+ struct role_transition *transitions;
81922+ struct role_allowed_ip *allowed_ips;
81923+ uid_t *domain_children;
81924+ __u16 domain_child_num;
81925+
81926+ umode_t umask;
81927+
81928+ struct acl_subject_label **subj_hash;
81929+ __u32 subj_hash_size;
81930+};
81931+
81932+struct user_acl_role_db {
81933+ struct acl_role_label **r_table;
81934+ __u32 num_pointers; /* Number of allocations to track */
81935+ __u32 num_roles; /* Number of roles */
81936+ __u32 num_domain_children; /* Number of domain children */
81937+ __u32 num_subjects; /* Number of subjects */
81938+ __u32 num_objects; /* Number of objects */
81939+};
81940+
81941+struct acl_object_label {
81942+ char *filename;
81943+ ino_t inode;
81944+ dev_t device;
81945+ __u32 mode;
81946+
81947+ struct acl_subject_label *nested;
81948+ struct acl_object_label *globbed;
81949+
81950+ /* next two structures not used */
81951+
81952+ struct acl_object_label *prev;
81953+ struct acl_object_label *next;
81954+};
81955+
81956+struct acl_ip_label {
81957+ char *iface;
81958+ __u32 addr;
81959+ __u32 netmask;
81960+ __u16 low, high;
81961+ __u8 mode;
81962+ __u32 type;
81963+ __u32 proto[8];
81964+
81965+ /* next two structures not used */
81966+
81967+ struct acl_ip_label *prev;
81968+ struct acl_ip_label *next;
81969+};
81970+
81971+struct gr_arg {
81972+ struct user_acl_role_db role_db;
81973+ unsigned char pw[GR_PW_LEN];
81974+ unsigned char salt[GR_SALT_LEN];
81975+ unsigned char sum[GR_SHA_LEN];
81976+ unsigned char sp_role[GR_SPROLE_LEN];
81977+ struct sprole_pw *sprole_pws;
81978+ dev_t segv_device;
81979+ ino_t segv_inode;
81980+ uid_t segv_uid;
81981+ __u16 num_sprole_pws;
81982+ __u16 mode;
81983+};
81984+
81985+struct gr_arg_wrapper {
81986+ struct gr_arg *arg;
81987+ __u32 version;
81988+ __u32 size;
81989+};
81990+
81991+struct subject_map {
81992+ struct acl_subject_label *user;
81993+ struct acl_subject_label *kernel;
81994+ struct subject_map *prev;
81995+ struct subject_map *next;
81996+};
81997+
81998+struct acl_subj_map_db {
81999+ struct subject_map **s_hash;
82000+ __u32 s_size;
82001+};
82002+
82003+struct gr_policy_state {
82004+ struct sprole_pw **acl_special_roles;
82005+ __u16 num_sprole_pws;
82006+ struct acl_role_label *kernel_role;
82007+ struct acl_role_label *role_list;
82008+ struct acl_role_label *default_role;
82009+ struct acl_role_db acl_role_set;
82010+ struct acl_subj_map_db subj_map_set;
82011+ struct name_db name_set;
82012+ struct inodev_db inodev_set;
82013+};
82014+
82015+struct gr_alloc_state {
82016+ unsigned long alloc_stack_next;
82017+ unsigned long alloc_stack_size;
82018+ void **alloc_stack;
82019+};
82020+
82021+struct gr_reload_state {
82022+ struct gr_policy_state oldpolicy;
82023+ struct gr_alloc_state oldalloc;
82024+ struct gr_policy_state newpolicy;
82025+ struct gr_alloc_state newalloc;
82026+ struct gr_policy_state *oldpolicy_ptr;
82027+ struct gr_alloc_state *oldalloc_ptr;
82028+ unsigned char oldmode;
82029+};
82030+
82031+/* End Data Structures Section */
82032+
82033+/* Hash functions generated by empirical testing by Brad Spengler
82034+ Makes good use of the low bits of the inode. Generally 0-1 times
82035+ in loop for successful match. 0-3 for unsuccessful match.
82036+ Shift/add algorithm with modulus of table size and an XOR*/
82037+
82038+static __inline__ unsigned int
82039+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
82040+{
82041+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
82042+}
82043+
82044+ static __inline__ unsigned int
82045+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
82046+{
82047+ return ((const unsigned long)userp % sz);
82048+}
82049+
82050+static __inline__ unsigned int
82051+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
82052+{
82053+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
82054+}
82055+
82056+static __inline__ unsigned int
82057+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
82058+{
82059+ return full_name_hash((const unsigned char *)name, len) % sz;
82060+}
82061+
82062+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
82063+ subj = NULL; \
82064+ iter = 0; \
82065+ while (iter < role->subj_hash_size) { \
82066+ if (subj == NULL) \
82067+ subj = role->subj_hash[iter]; \
82068+ if (subj == NULL) { \
82069+ iter++; \
82070+ continue; \
82071+ }
82072+
82073+#define FOR_EACH_SUBJECT_END(subj,iter) \
82074+ subj = subj->next; \
82075+ if (subj == NULL) \
82076+ iter++; \
82077+ }
82078+
82079+
82080+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
82081+ subj = role->hash->first; \
82082+ while (subj != NULL) {
82083+
82084+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
82085+ subj = subj->next; \
82086+ }
82087+
82088+#endif
82089+
82090diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
82091new file mode 100644
82092index 0000000..33ebd1f
82093--- /dev/null
82094+++ b/include/linux/gracl_compat.h
82095@@ -0,0 +1,156 @@
82096+#ifndef GR_ACL_COMPAT_H
82097+#define GR_ACL_COMPAT_H
82098+
82099+#include <linux/resource.h>
82100+#include <asm/resource.h>
82101+
82102+struct sprole_pw_compat {
82103+ compat_uptr_t rolename;
82104+ unsigned char salt[GR_SALT_LEN];
82105+ unsigned char sum[GR_SHA_LEN];
82106+};
82107+
82108+struct gr_hash_struct_compat {
82109+ compat_uptr_t table;
82110+ compat_uptr_t nametable;
82111+ compat_uptr_t first;
82112+ __u32 table_size;
82113+ __u32 used_size;
82114+ int type;
82115+};
82116+
82117+struct acl_subject_label_compat {
82118+ compat_uptr_t filename;
82119+ compat_ino_t inode;
82120+ __u32 device;
82121+ __u32 mode;
82122+ kernel_cap_t cap_mask;
82123+ kernel_cap_t cap_lower;
82124+ kernel_cap_t cap_invert_audit;
82125+
82126+ struct compat_rlimit res[GR_NLIMITS];
82127+ __u32 resmask;
82128+
82129+ __u8 user_trans_type;
82130+ __u8 group_trans_type;
82131+ compat_uptr_t user_transitions;
82132+ compat_uptr_t group_transitions;
82133+ __u16 user_trans_num;
82134+ __u16 group_trans_num;
82135+
82136+ __u32 sock_families[2];
82137+ __u32 ip_proto[8];
82138+ __u32 ip_type;
82139+ compat_uptr_t ips;
82140+ __u32 ip_num;
82141+ __u32 inaddr_any_override;
82142+
82143+ __u32 crashes;
82144+ compat_ulong_t expires;
82145+
82146+ compat_uptr_t parent_subject;
82147+ compat_uptr_t hash;
82148+ compat_uptr_t prev;
82149+ compat_uptr_t next;
82150+
82151+ compat_uptr_t obj_hash;
82152+ __u32 obj_hash_size;
82153+ __u16 pax_flags;
82154+};
82155+
82156+struct role_allowed_ip_compat {
82157+ __u32 addr;
82158+ __u32 netmask;
82159+
82160+ compat_uptr_t prev;
82161+ compat_uptr_t next;
82162+};
82163+
82164+struct role_transition_compat {
82165+ compat_uptr_t rolename;
82166+
82167+ compat_uptr_t prev;
82168+ compat_uptr_t next;
82169+};
82170+
82171+struct acl_role_label_compat {
82172+ compat_uptr_t rolename;
82173+ uid_t uidgid;
82174+ __u16 roletype;
82175+
82176+ __u16 auth_attempts;
82177+ compat_ulong_t expires;
82178+
82179+ compat_uptr_t root_label;
82180+ compat_uptr_t hash;
82181+
82182+ compat_uptr_t prev;
82183+ compat_uptr_t next;
82184+
82185+ compat_uptr_t transitions;
82186+ compat_uptr_t allowed_ips;
82187+ compat_uptr_t domain_children;
82188+ __u16 domain_child_num;
82189+
82190+ umode_t umask;
82191+
82192+ compat_uptr_t subj_hash;
82193+ __u32 subj_hash_size;
82194+};
82195+
82196+struct user_acl_role_db_compat {
82197+ compat_uptr_t r_table;
82198+ __u32 num_pointers;
82199+ __u32 num_roles;
82200+ __u32 num_domain_children;
82201+ __u32 num_subjects;
82202+ __u32 num_objects;
82203+};
82204+
82205+struct acl_object_label_compat {
82206+ compat_uptr_t filename;
82207+ compat_ino_t inode;
82208+ __u32 device;
82209+ __u32 mode;
82210+
82211+ compat_uptr_t nested;
82212+ compat_uptr_t globbed;
82213+
82214+ compat_uptr_t prev;
82215+ compat_uptr_t next;
82216+};
82217+
82218+struct acl_ip_label_compat {
82219+ compat_uptr_t iface;
82220+ __u32 addr;
82221+ __u32 netmask;
82222+ __u16 low, high;
82223+ __u8 mode;
82224+ __u32 type;
82225+ __u32 proto[8];
82226+
82227+ compat_uptr_t prev;
82228+ compat_uptr_t next;
82229+};
82230+
82231+struct gr_arg_compat {
82232+ struct user_acl_role_db_compat role_db;
82233+ unsigned char pw[GR_PW_LEN];
82234+ unsigned char salt[GR_SALT_LEN];
82235+ unsigned char sum[GR_SHA_LEN];
82236+ unsigned char sp_role[GR_SPROLE_LEN];
82237+ compat_uptr_t sprole_pws;
82238+ __u32 segv_device;
82239+ compat_ino_t segv_inode;
82240+ uid_t segv_uid;
82241+ __u16 num_sprole_pws;
82242+ __u16 mode;
82243+};
82244+
82245+struct gr_arg_wrapper_compat {
82246+ compat_uptr_t arg;
82247+ __u32 version;
82248+ __u32 size;
82249+};
82250+
82251+#endif
82252diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
82253new file mode 100644
82254index 0000000..323ecf2
82255--- /dev/null
82256+++ b/include/linux/gralloc.h
82257@@ -0,0 +1,9 @@
82258+#ifndef __GRALLOC_H
82259+#define __GRALLOC_H
82260+
82261+void acl_free_all(void);
82262+int acl_alloc_stack_init(unsigned long size);
82263+void *acl_alloc(unsigned long len);
82264+void *acl_alloc_num(unsigned long num, unsigned long len);
82265+
82266+#endif
82267diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
82268new file mode 100644
82269index 0000000..be66033
82270--- /dev/null
82271+++ b/include/linux/grdefs.h
82272@@ -0,0 +1,140 @@
82273+#ifndef GRDEFS_H
82274+#define GRDEFS_H
82275+
82276+/* Begin grsecurity status declarations */
82277+
82278+enum {
82279+ GR_READY = 0x01,
82280+ GR_STATUS_INIT = 0x00 // disabled state
82281+};
82282+
82283+/* Begin ACL declarations */
82284+
82285+/* Role flags */
82286+
82287+enum {
82288+ GR_ROLE_USER = 0x0001,
82289+ GR_ROLE_GROUP = 0x0002,
82290+ GR_ROLE_DEFAULT = 0x0004,
82291+ GR_ROLE_SPECIAL = 0x0008,
82292+ GR_ROLE_AUTH = 0x0010,
82293+ GR_ROLE_NOPW = 0x0020,
82294+ GR_ROLE_GOD = 0x0040,
82295+ GR_ROLE_LEARN = 0x0080,
82296+ GR_ROLE_TPE = 0x0100,
82297+ GR_ROLE_DOMAIN = 0x0200,
82298+ GR_ROLE_PAM = 0x0400,
82299+ GR_ROLE_PERSIST = 0x0800
82300+};
82301+
82302+/* ACL Subject and Object mode flags */
82303+enum {
82304+ GR_DELETED = 0x80000000
82305+};
82306+
82307+/* ACL Object-only mode flags */
82308+enum {
82309+ GR_READ = 0x00000001,
82310+ GR_APPEND = 0x00000002,
82311+ GR_WRITE = 0x00000004,
82312+ GR_EXEC = 0x00000008,
82313+ GR_FIND = 0x00000010,
82314+ GR_INHERIT = 0x00000020,
82315+ GR_SETID = 0x00000040,
82316+ GR_CREATE = 0x00000080,
82317+ GR_DELETE = 0x00000100,
82318+ GR_LINK = 0x00000200,
82319+ GR_AUDIT_READ = 0x00000400,
82320+ GR_AUDIT_APPEND = 0x00000800,
82321+ GR_AUDIT_WRITE = 0x00001000,
82322+ GR_AUDIT_EXEC = 0x00002000,
82323+ GR_AUDIT_FIND = 0x00004000,
82324+ GR_AUDIT_INHERIT= 0x00008000,
82325+ GR_AUDIT_SETID = 0x00010000,
82326+ GR_AUDIT_CREATE = 0x00020000,
82327+ GR_AUDIT_DELETE = 0x00040000,
82328+ GR_AUDIT_LINK = 0x00080000,
82329+ GR_PTRACERD = 0x00100000,
82330+ GR_NOPTRACE = 0x00200000,
82331+ GR_SUPPRESS = 0x00400000,
82332+ GR_NOLEARN = 0x00800000,
82333+ GR_INIT_TRANSFER= 0x01000000
82334+};
82335+
82336+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
82337+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
82338+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
82339+
82340+/* ACL subject-only mode flags */
82341+enum {
82342+ GR_KILL = 0x00000001,
82343+ GR_VIEW = 0x00000002,
82344+ GR_PROTECTED = 0x00000004,
82345+ GR_LEARN = 0x00000008,
82346+ GR_OVERRIDE = 0x00000010,
82347+ /* just a placeholder, this mode is only used in userspace */
82348+ GR_DUMMY = 0x00000020,
82349+ GR_PROTSHM = 0x00000040,
82350+ GR_KILLPROC = 0x00000080,
82351+ GR_KILLIPPROC = 0x00000100,
82352+ /* just a placeholder, this mode is only used in userspace */
82353+ GR_NOTROJAN = 0x00000200,
82354+ GR_PROTPROCFD = 0x00000400,
82355+ GR_PROCACCT = 0x00000800,
82356+ GR_RELAXPTRACE = 0x00001000,
82357+ //GR_NESTED = 0x00002000,
82358+ GR_INHERITLEARN = 0x00004000,
82359+ GR_PROCFIND = 0x00008000,
82360+ GR_POVERRIDE = 0x00010000,
82361+ GR_KERNELAUTH = 0x00020000,
82362+ GR_ATSECURE = 0x00040000,
82363+ GR_SHMEXEC = 0x00080000
82364+};
82365+
82366+enum {
82367+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
82368+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
82369+ GR_PAX_ENABLE_MPROTECT = 0x0004,
82370+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
82371+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
82372+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
82373+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
82374+ GR_PAX_DISABLE_MPROTECT = 0x0400,
82375+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
82376+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
82377+};
82378+
82379+enum {
82380+ GR_ID_USER = 0x01,
82381+ GR_ID_GROUP = 0x02,
82382+};
82383+
82384+enum {
82385+ GR_ID_ALLOW = 0x01,
82386+ GR_ID_DENY = 0x02,
82387+};
82388+
82389+#define GR_CRASH_RES 31
82390+#define GR_UIDTABLE_MAX 500
82391+
82392+/* begin resource learning section */
82393+enum {
82394+ GR_RLIM_CPU_BUMP = 60,
82395+ GR_RLIM_FSIZE_BUMP = 50000,
82396+ GR_RLIM_DATA_BUMP = 10000,
82397+ GR_RLIM_STACK_BUMP = 1000,
82398+ GR_RLIM_CORE_BUMP = 10000,
82399+ GR_RLIM_RSS_BUMP = 500000,
82400+ GR_RLIM_NPROC_BUMP = 1,
82401+ GR_RLIM_NOFILE_BUMP = 5,
82402+ GR_RLIM_MEMLOCK_BUMP = 50000,
82403+ GR_RLIM_AS_BUMP = 500000,
82404+ GR_RLIM_LOCKS_BUMP = 2,
82405+ GR_RLIM_SIGPENDING_BUMP = 5,
82406+ GR_RLIM_MSGQUEUE_BUMP = 10000,
82407+ GR_RLIM_NICE_BUMP = 1,
82408+ GR_RLIM_RTPRIO_BUMP = 1,
82409+ GR_RLIM_RTTIME_BUMP = 1000000
82410+};
82411+
82412+#endif
82413diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
82414new file mode 100644
82415index 0000000..d25522e
82416--- /dev/null
82417+++ b/include/linux/grinternal.h
82418@@ -0,0 +1,229 @@
82419+#ifndef __GRINTERNAL_H
82420+#define __GRINTERNAL_H
82421+
82422+#ifdef CONFIG_GRKERNSEC
82423+
82424+#include <linux/fs.h>
82425+#include <linux/mnt_namespace.h>
82426+#include <linux/nsproxy.h>
82427+#include <linux/gracl.h>
82428+#include <linux/grdefs.h>
82429+#include <linux/grmsg.h>
82430+
82431+void gr_add_learn_entry(const char *fmt, ...)
82432+ __attribute__ ((format (printf, 1, 2)));
82433+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
82434+ const struct vfsmount *mnt);
82435+__u32 gr_check_create(const struct dentry *new_dentry,
82436+ const struct dentry *parent,
82437+ const struct vfsmount *mnt, const __u32 mode);
82438+int gr_check_protected_task(const struct task_struct *task);
82439+__u32 to_gr_audit(const __u32 reqmode);
82440+int gr_set_acls(const int type);
82441+int gr_acl_is_enabled(void);
82442+char gr_roletype_to_char(void);
82443+
82444+void gr_handle_alertkill(struct task_struct *task);
82445+char *gr_to_filename(const struct dentry *dentry,
82446+ const struct vfsmount *mnt);
82447+char *gr_to_filename1(const struct dentry *dentry,
82448+ const struct vfsmount *mnt);
82449+char *gr_to_filename2(const struct dentry *dentry,
82450+ const struct vfsmount *mnt);
82451+char *gr_to_filename3(const struct dentry *dentry,
82452+ const struct vfsmount *mnt);
82453+
82454+extern int grsec_enable_ptrace_readexec;
82455+extern int grsec_enable_harden_ptrace;
82456+extern int grsec_enable_link;
82457+extern int grsec_enable_fifo;
82458+extern int grsec_enable_execve;
82459+extern int grsec_enable_shm;
82460+extern int grsec_enable_execlog;
82461+extern int grsec_enable_signal;
82462+extern int grsec_enable_audit_ptrace;
82463+extern int grsec_enable_forkfail;
82464+extern int grsec_enable_time;
82465+extern int grsec_enable_rofs;
82466+extern int grsec_deny_new_usb;
82467+extern int grsec_enable_chroot_shmat;
82468+extern int grsec_enable_chroot_mount;
82469+extern int grsec_enable_chroot_double;
82470+extern int grsec_enable_chroot_pivot;
82471+extern int grsec_enable_chroot_chdir;
82472+extern int grsec_enable_chroot_chmod;
82473+extern int grsec_enable_chroot_mknod;
82474+extern int grsec_enable_chroot_fchdir;
82475+extern int grsec_enable_chroot_nice;
82476+extern int grsec_enable_chroot_execlog;
82477+extern int grsec_enable_chroot_caps;
82478+extern int grsec_enable_chroot_sysctl;
82479+extern int grsec_enable_chroot_unix;
82480+extern int grsec_enable_symlinkown;
82481+extern kgid_t grsec_symlinkown_gid;
82482+extern int grsec_enable_tpe;
82483+extern kgid_t grsec_tpe_gid;
82484+extern int grsec_enable_tpe_all;
82485+extern int grsec_enable_tpe_invert;
82486+extern int grsec_enable_socket_all;
82487+extern kgid_t grsec_socket_all_gid;
82488+extern int grsec_enable_socket_client;
82489+extern kgid_t grsec_socket_client_gid;
82490+extern int grsec_enable_socket_server;
82491+extern kgid_t grsec_socket_server_gid;
82492+extern kgid_t grsec_audit_gid;
82493+extern int grsec_enable_group;
82494+extern int grsec_enable_log_rwxmaps;
82495+extern int grsec_enable_mount;
82496+extern int grsec_enable_chdir;
82497+extern int grsec_resource_logging;
82498+extern int grsec_enable_blackhole;
82499+extern int grsec_lastack_retries;
82500+extern int grsec_enable_brute;
82501+extern int grsec_enable_harden_ipc;
82502+extern int grsec_lock;
82503+
82504+extern spinlock_t grsec_alert_lock;
82505+extern unsigned long grsec_alert_wtime;
82506+extern unsigned long grsec_alert_fyet;
82507+
82508+extern spinlock_t grsec_audit_lock;
82509+
82510+extern rwlock_t grsec_exec_file_lock;
82511+
82512+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
82513+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
82514+ (tsk)->exec_file->f_path.mnt) : "/")
82515+
82516+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
82517+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
82518+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
82519+
82520+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
82521+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
82522+ (tsk)->exec_file->f_path.mnt) : "/")
82523+
82524+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
82525+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
82526+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
82527+
82528+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
82529+
82530+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
82531+
82532+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
82533+{
82534+ if (file1 && file2) {
82535+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
82536+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
82537+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
82538+ return true;
82539+ }
82540+
82541+ return false;
82542+}
82543+
82544+#define GR_CHROOT_CAPS {{ \
82545+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
82546+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
82547+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
82548+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
82549+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
82550+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
82551+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
82552+
82553+#define security_learn(normal_msg,args...) \
82554+({ \
82555+ read_lock(&grsec_exec_file_lock); \
82556+ gr_add_learn_entry(normal_msg "\n", ## args); \
82557+ read_unlock(&grsec_exec_file_lock); \
82558+})
82559+
82560+enum {
82561+ GR_DO_AUDIT,
82562+ GR_DONT_AUDIT,
82563+ /* used for non-audit messages that we shouldn't kill the task on */
82564+ GR_DONT_AUDIT_GOOD
82565+};
82566+
82567+enum {
82568+ GR_TTYSNIFF,
82569+ GR_RBAC,
82570+ GR_RBAC_STR,
82571+ GR_STR_RBAC,
82572+ GR_RBAC_MODE2,
82573+ GR_RBAC_MODE3,
82574+ GR_FILENAME,
82575+ GR_SYSCTL_HIDDEN,
82576+ GR_NOARGS,
82577+ GR_ONE_INT,
82578+ GR_ONE_INT_TWO_STR,
82579+ GR_ONE_STR,
82580+ GR_STR_INT,
82581+ GR_TWO_STR_INT,
82582+ GR_TWO_INT,
82583+ GR_TWO_U64,
82584+ GR_THREE_INT,
82585+ GR_FIVE_INT_TWO_STR,
82586+ GR_TWO_STR,
82587+ GR_THREE_STR,
82588+ GR_FOUR_STR,
82589+ GR_STR_FILENAME,
82590+ GR_FILENAME_STR,
82591+ GR_FILENAME_TWO_INT,
82592+ GR_FILENAME_TWO_INT_STR,
82593+ GR_TEXTREL,
82594+ GR_PTRACE,
82595+ GR_RESOURCE,
82596+ GR_CAP,
82597+ GR_SIG,
82598+ GR_SIG2,
82599+ GR_CRASH1,
82600+ GR_CRASH2,
82601+ GR_PSACCT,
82602+ GR_RWXMAP,
82603+ GR_RWXMAPVMA
82604+};
82605+
82606+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
82607+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
82608+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
82609+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
82610+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
82611+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
82612+#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)
82613+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
82614+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
82615+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
82616+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
82617+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
82618+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
82619+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
82620+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
82621+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
82622+#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)
82623+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
82624+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
82625+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
82626+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
82627+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
82628+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
82629+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
82630+#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)
82631+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
82632+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
82633+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
82634+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
82635+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
82636+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
82637+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
82638+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
82639+#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)
82640+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
82641+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
82642+
82643+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
82644+
82645+#endif
82646+
82647+#endif
82648diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
82649new file mode 100644
82650index 0000000..b02ba9d
82651--- /dev/null
82652+++ b/include/linux/grmsg.h
82653@@ -0,0 +1,117 @@
82654+#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"
82655+#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"
82656+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
82657+#define GR_STOPMOD_MSG "denied modification of module state by "
82658+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
82659+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
82660+#define GR_IOPERM_MSG "denied use of ioperm() by "
82661+#define GR_IOPL_MSG "denied use of iopl() by "
82662+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
82663+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
82664+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
82665+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
82666+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
82667+#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"
82668+#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"
82669+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
82670+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
82671+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
82672+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
82673+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
82674+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
82675+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
82676+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
82677+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
82678+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
82679+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
82680+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
82681+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
82682+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
82683+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
82684+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
82685+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
82686+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
82687+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
82688+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
82689+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
82690+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
82691+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
82692+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
82693+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
82694+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
82695+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
82696+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
82697+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
82698+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
82699+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
82700+#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
82701+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
82702+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
82703+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
82704+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
82705+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
82706+#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"
82707+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
82708+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
82709+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
82710+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
82711+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
82712+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
82713+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
82714+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
82715+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
82716+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
82717+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
82718+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
82719+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
82720+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
82721+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
82722+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
82723+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
82724+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
82725+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
82726+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
82727+#define GR_FAILFORK_MSG "failed fork with errno %s by "
82728+#define GR_NICE_CHROOT_MSG "denied priority change by "
82729+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
82730+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
82731+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
82732+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
82733+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
82734+#define GR_TIME_MSG "time set by "
82735+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
82736+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
82737+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
82738+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
82739+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
82740+#define GR_BIND_MSG "denied bind() by "
82741+#define GR_CONNECT_MSG "denied connect() by "
82742+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
82743+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
82744+#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"
82745+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
82746+#define GR_CAP_ACL_MSG "use of %s denied for "
82747+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
82748+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
82749+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
82750+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
82751+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
82752+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
82753+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
82754+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
82755+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
82756+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
82757+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
82758+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
82759+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
82760+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
82761+#define GR_VM86_MSG "denied use of vm86 by "
82762+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
82763+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
82764+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
82765+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
82766+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
82767+#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 "
82768+#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 "
82769+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
82770+#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
82771diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
82772new file mode 100644
82773index 0000000..10b9635
82774--- /dev/null
82775+++ b/include/linux/grsecurity.h
82776@@ -0,0 +1,254 @@
82777+#ifndef GR_SECURITY_H
82778+#define GR_SECURITY_H
82779+#include <linux/fs.h>
82780+#include <linux/fs_struct.h>
82781+#include <linux/binfmts.h>
82782+#include <linux/gracl.h>
82783+
82784+/* notify of brain-dead configs */
82785+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82786+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
82787+#endif
82788+#if defined(CONFIG_GRKERNSEC_PROC) && !defined(CONFIG_GRKERNSEC_PROC_USER) && !defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82789+#error "CONFIG_GRKERNSEC_PROC enabled, but neither CONFIG_GRKERNSEC_PROC_USER nor CONFIG_GRKERNSEC_PROC_USERGROUP enabled"
82790+#endif
82791+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
82792+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
82793+#endif
82794+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
82795+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
82796+#endif
82797+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
82798+#error "CONFIG_PAX enabled, but no PaX options are enabled."
82799+#endif
82800+
82801+int gr_handle_new_usb(void);
82802+
82803+void gr_handle_brute_attach(int dumpable);
82804+void gr_handle_brute_check(void);
82805+void gr_handle_kernel_exploit(void);
82806+
82807+char gr_roletype_to_char(void);
82808+
82809+int gr_proc_is_restricted(void);
82810+
82811+int gr_acl_enable_at_secure(void);
82812+
82813+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
82814+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
82815+
82816+int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap);
82817+
82818+void gr_del_task_from_ip_table(struct task_struct *p);
82819+
82820+int gr_pid_is_chrooted(struct task_struct *p);
82821+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
82822+int gr_handle_chroot_nice(void);
82823+int gr_handle_chroot_sysctl(const int op);
82824+int gr_handle_chroot_setpriority(struct task_struct *p,
82825+ const int niceval);
82826+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
82827+int gr_chroot_fhandle(void);
82828+int gr_handle_chroot_chroot(const struct dentry *dentry,
82829+ const struct vfsmount *mnt);
82830+void gr_handle_chroot_chdir(const struct path *path);
82831+int gr_handle_chroot_chmod(const struct dentry *dentry,
82832+ const struct vfsmount *mnt, const int mode);
82833+int gr_handle_chroot_mknod(const struct dentry *dentry,
82834+ const struct vfsmount *mnt, const int mode);
82835+int gr_handle_chroot_mount(const struct dentry *dentry,
82836+ const struct vfsmount *mnt,
82837+ const char *dev_name);
82838+int gr_handle_chroot_pivot(void);
82839+int gr_handle_chroot_unix(const pid_t pid);
82840+
82841+int gr_handle_rawio(const struct inode *inode);
82842+
82843+void gr_handle_ioperm(void);
82844+void gr_handle_iopl(void);
82845+void gr_handle_msr_write(void);
82846+
82847+umode_t gr_acl_umask(void);
82848+
82849+int gr_tpe_allow(const struct file *file);
82850+
82851+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
82852+void gr_clear_chroot_entries(struct task_struct *task);
82853+
82854+void gr_log_forkfail(const int retval);
82855+void gr_log_timechange(void);
82856+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
82857+void gr_log_chdir(const struct dentry *dentry,
82858+ const struct vfsmount *mnt);
82859+void gr_log_chroot_exec(const struct dentry *dentry,
82860+ const struct vfsmount *mnt);
82861+void gr_log_remount(const char *devname, const int retval);
82862+void gr_log_unmount(const char *devname, const int retval);
82863+void gr_log_mount(const char *from, const char *to, const int retval);
82864+void gr_log_textrel(struct vm_area_struct *vma);
82865+void gr_log_ptgnustack(struct file *file);
82866+void gr_log_rwxmmap(struct file *file);
82867+void gr_log_rwxmprotect(struct vm_area_struct *vma);
82868+
82869+int gr_handle_follow_link(const struct inode *parent,
82870+ const struct inode *inode,
82871+ const struct dentry *dentry,
82872+ const struct vfsmount *mnt);
82873+int gr_handle_fifo(const struct dentry *dentry,
82874+ const struct vfsmount *mnt,
82875+ const struct dentry *dir, const int flag,
82876+ const int acc_mode);
82877+int gr_handle_hardlink(const struct dentry *dentry,
82878+ const struct vfsmount *mnt,
82879+ struct inode *inode,
82880+ const int mode, const struct filename *to);
82881+
82882+int gr_is_capable(const int cap);
82883+int gr_is_capable_nolog(const int cap);
82884+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
82885+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
82886+
82887+void gr_copy_label(struct task_struct *tsk);
82888+void gr_handle_crash(struct task_struct *task, const int sig);
82889+int gr_handle_signal(const struct task_struct *p, const int sig);
82890+int gr_check_crash_uid(const kuid_t uid);
82891+int gr_check_protected_task(const struct task_struct *task);
82892+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
82893+int gr_acl_handle_mmap(const struct file *file,
82894+ const unsigned long prot);
82895+int gr_acl_handle_mprotect(const struct file *file,
82896+ const unsigned long prot);
82897+int gr_check_hidden_task(const struct task_struct *tsk);
82898+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
82899+ const struct vfsmount *mnt);
82900+__u32 gr_acl_handle_utime(const struct dentry *dentry,
82901+ const struct vfsmount *mnt);
82902+__u32 gr_acl_handle_access(const struct dentry *dentry,
82903+ const struct vfsmount *mnt, const int fmode);
82904+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
82905+ const struct vfsmount *mnt, umode_t *mode);
82906+__u32 gr_acl_handle_chown(const struct dentry *dentry,
82907+ const struct vfsmount *mnt);
82908+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
82909+ const struct vfsmount *mnt);
82910+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
82911+ const struct vfsmount *mnt);
82912+int gr_handle_ptrace(struct task_struct *task, const long request);
82913+int gr_handle_proc_ptrace(struct task_struct *task);
82914+__u32 gr_acl_handle_execve(const struct dentry *dentry,
82915+ const struct vfsmount *mnt);
82916+int gr_check_crash_exec(const struct file *filp);
82917+int gr_acl_is_enabled(void);
82918+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
82919+ const kgid_t gid);
82920+int gr_set_proc_label(const struct dentry *dentry,
82921+ const struct vfsmount *mnt,
82922+ const int unsafe_flags);
82923+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
82924+ const struct vfsmount *mnt);
82925+__u32 gr_acl_handle_open(const struct dentry *dentry,
82926+ const struct vfsmount *mnt, int acc_mode);
82927+__u32 gr_acl_handle_creat(const struct dentry *dentry,
82928+ const struct dentry *p_dentry,
82929+ const struct vfsmount *p_mnt,
82930+ int open_flags, int acc_mode, const int imode);
82931+void gr_handle_create(const struct dentry *dentry,
82932+ const struct vfsmount *mnt);
82933+void gr_handle_proc_create(const struct dentry *dentry,
82934+ const struct inode *inode);
82935+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
82936+ const struct dentry *parent_dentry,
82937+ const struct vfsmount *parent_mnt,
82938+ const int mode);
82939+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
82940+ const struct dentry *parent_dentry,
82941+ const struct vfsmount *parent_mnt);
82942+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
82943+ const struct vfsmount *mnt);
82944+void gr_handle_delete(const ino_t ino, const dev_t dev);
82945+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
82946+ const struct vfsmount *mnt);
82947+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
82948+ const struct dentry *parent_dentry,
82949+ const struct vfsmount *parent_mnt,
82950+ const struct filename *from);
82951+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
82952+ const struct dentry *parent_dentry,
82953+ const struct vfsmount *parent_mnt,
82954+ const struct dentry *old_dentry,
82955+ const struct vfsmount *old_mnt, const struct filename *to);
82956+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
82957+int gr_acl_handle_rename(struct dentry *new_dentry,
82958+ struct dentry *parent_dentry,
82959+ const struct vfsmount *parent_mnt,
82960+ struct dentry *old_dentry,
82961+ struct inode *old_parent_inode,
82962+ struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
82963+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
82964+ struct dentry *old_dentry,
82965+ struct dentry *new_dentry,
82966+ struct vfsmount *mnt, const __u8 replace, unsigned int flags);
82967+__u32 gr_check_link(const struct dentry *new_dentry,
82968+ const struct dentry *parent_dentry,
82969+ const struct vfsmount *parent_mnt,
82970+ const struct dentry *old_dentry,
82971+ const struct vfsmount *old_mnt);
82972+int gr_acl_handle_filldir(const struct file *file, const char *name,
82973+ const unsigned int namelen, const ino_t ino);
82974+
82975+__u32 gr_acl_handle_unix(const struct dentry *dentry,
82976+ const struct vfsmount *mnt);
82977+void gr_acl_handle_exit(void);
82978+void gr_acl_handle_psacct(struct task_struct *task, const long code);
82979+int gr_acl_handle_procpidmem(const struct task_struct *task);
82980+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
82981+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
82982+void gr_audit_ptrace(struct task_struct *task);
82983+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
82984+void gr_put_exec_file(struct task_struct *task);
82985+
82986+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
82987+
82988+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
82989+extern void gr_learn_resource(const struct task_struct *task, const int res,
82990+ const unsigned long wanted, const int gt);
82991+#else
82992+static inline void gr_learn_resource(const struct task_struct *task, const int res,
82993+ const unsigned long wanted, const int gt)
82994+{
82995+}
82996+#endif
82997+
82998+#ifdef CONFIG_GRKERNSEC_RESLOG
82999+extern void gr_log_resource(const struct task_struct *task, const int res,
83000+ const unsigned long wanted, const int gt);
83001+#else
83002+static inline void gr_log_resource(const struct task_struct *task, const int res,
83003+ const unsigned long wanted, const int gt)
83004+{
83005+}
83006+#endif
83007+
83008+#ifdef CONFIG_GRKERNSEC
83009+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
83010+void gr_handle_vm86(void);
83011+void gr_handle_mem_readwrite(u64 from, u64 to);
83012+
83013+void gr_log_badprocpid(const char *entry);
83014+
83015+extern int grsec_enable_dmesg;
83016+extern int grsec_disable_privio;
83017+
83018+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
83019+extern kgid_t grsec_proc_gid;
83020+#endif
83021+
83022+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
83023+extern int grsec_enable_chroot_findtask;
83024+#endif
83025+#ifdef CONFIG_GRKERNSEC_SETXID
83026+extern int grsec_enable_setxid;
83027+#endif
83028+#endif
83029+
83030+#endif
83031diff --git a/include/linux/grsock.h b/include/linux/grsock.h
83032new file mode 100644
83033index 0000000..e7ffaaf
83034--- /dev/null
83035+++ b/include/linux/grsock.h
83036@@ -0,0 +1,19 @@
83037+#ifndef __GRSOCK_H
83038+#define __GRSOCK_H
83039+
83040+extern void gr_attach_curr_ip(const struct sock *sk);
83041+extern int gr_handle_sock_all(const int family, const int type,
83042+ const int protocol);
83043+extern int gr_handle_sock_server(const struct sockaddr *sck);
83044+extern int gr_handle_sock_server_other(const struct sock *sck);
83045+extern int gr_handle_sock_client(const struct sockaddr *sck);
83046+extern int gr_search_connect(struct socket * sock,
83047+ struct sockaddr_in * addr);
83048+extern int gr_search_bind(struct socket * sock,
83049+ struct sockaddr_in * addr);
83050+extern int gr_search_listen(struct socket * sock);
83051+extern int gr_search_accept(struct socket * sock);
83052+extern int gr_search_socket(const int domain, const int type,
83053+ const int protocol);
83054+
83055+#endif
83056diff --git a/include/linux/hash.h b/include/linux/hash.h
83057index d0494c3..69b7715 100644
83058--- a/include/linux/hash.h
83059+++ b/include/linux/hash.h
83060@@ -87,7 +87,7 @@ static inline u32 hash32_ptr(const void *ptr)
83061 struct fast_hash_ops {
83062 u32 (*hash)(const void *data, u32 len, u32 seed);
83063 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
83064-};
83065+} __no_const;
83066
83067 /**
83068 * arch_fast_hash - Caclulates a hash over a given buffer that can have
83069diff --git a/include/linux/highmem.h b/include/linux/highmem.h
83070index 9286a46..373f27f 100644
83071--- a/include/linux/highmem.h
83072+++ b/include/linux/highmem.h
83073@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
83074 kunmap_atomic(kaddr);
83075 }
83076
83077+static inline void sanitize_highpage(struct page *page)
83078+{
83079+ void *kaddr;
83080+ unsigned long flags;
83081+
83082+ local_irq_save(flags);
83083+ kaddr = kmap_atomic(page);
83084+ clear_page(kaddr);
83085+ kunmap_atomic(kaddr);
83086+ local_irq_restore(flags);
83087+}
83088+
83089 static inline void zero_user_segments(struct page *page,
83090 unsigned start1, unsigned end1,
83091 unsigned start2, unsigned end2)
83092diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
83093index 1c7b89a..7dda400 100644
83094--- a/include/linux/hwmon-sysfs.h
83095+++ b/include/linux/hwmon-sysfs.h
83096@@ -25,7 +25,8 @@
83097 struct sensor_device_attribute{
83098 struct device_attribute dev_attr;
83099 int index;
83100-};
83101+} __do_const;
83102+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
83103 #define to_sensor_dev_attr(_dev_attr) \
83104 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
83105
83106@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
83107 struct device_attribute dev_attr;
83108 u8 index;
83109 u8 nr;
83110-};
83111+} __do_const;
83112+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
83113 #define to_sensor_dev_attr_2(_dev_attr) \
83114 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
83115
83116diff --git a/include/linux/i2c.h b/include/linux/i2c.h
83117index b556e0a..c10a515 100644
83118--- a/include/linux/i2c.h
83119+++ b/include/linux/i2c.h
83120@@ -378,6 +378,7 @@ struct i2c_algorithm {
83121 /* To determine what the adapter supports */
83122 u32 (*functionality) (struct i2c_adapter *);
83123 };
83124+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
83125
83126 /**
83127 * struct i2c_bus_recovery_info - I2C bus recovery information
83128diff --git a/include/linux/i2o.h b/include/linux/i2o.h
83129index d23c3c2..eb63c81 100644
83130--- a/include/linux/i2o.h
83131+++ b/include/linux/i2o.h
83132@@ -565,7 +565,7 @@ struct i2o_controller {
83133 struct i2o_device *exec; /* Executive */
83134 #if BITS_PER_LONG == 64
83135 spinlock_t context_list_lock; /* lock for context_list */
83136- atomic_t context_list_counter; /* needed for unique contexts */
83137+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
83138 struct list_head context_list; /* list of context id's
83139 and pointers */
83140 #endif
83141diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
83142index aff7ad8..3942bbd 100644
83143--- a/include/linux/if_pppox.h
83144+++ b/include/linux/if_pppox.h
83145@@ -76,7 +76,7 @@ struct pppox_proto {
83146 int (*ioctl)(struct socket *sock, unsigned int cmd,
83147 unsigned long arg);
83148 struct module *owner;
83149-};
83150+} __do_const;
83151
83152 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
83153 extern void unregister_pppox_proto(int proto_num);
83154diff --git a/include/linux/init.h b/include/linux/init.h
83155index 2df8e8d..3e1280d 100644
83156--- a/include/linux/init.h
83157+++ b/include/linux/init.h
83158@@ -37,9 +37,17 @@
83159 * section.
83160 */
83161
83162+#define add_init_latent_entropy __latent_entropy
83163+
83164+#ifdef CONFIG_MEMORY_HOTPLUG
83165+#define add_meminit_latent_entropy
83166+#else
83167+#define add_meminit_latent_entropy __latent_entropy
83168+#endif
83169+
83170 /* These are for everybody (although not all archs will actually
83171 discard it in modules) */
83172-#define __init __section(.init.text) __cold notrace
83173+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
83174 #define __initdata __section(.init.data)
83175 #define __initconst __constsection(.init.rodata)
83176 #define __exitdata __section(.exit.data)
83177@@ -100,7 +108,7 @@
83178 #define __cpuexitconst
83179
83180 /* Used for MEMORY_HOTPLUG */
83181-#define __meminit __section(.meminit.text) __cold notrace
83182+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
83183 #define __meminitdata __section(.meminit.data)
83184 #define __meminitconst __constsection(.meminit.rodata)
83185 #define __memexit __section(.memexit.text) __exitused __cold notrace
83186diff --git a/include/linux/init_task.h b/include/linux/init_task.h
83187index 2bb4c4f3..e0fac69 100644
83188--- a/include/linux/init_task.h
83189+++ b/include/linux/init_task.h
83190@@ -149,6 +149,12 @@ extern struct task_group root_task_group;
83191
83192 #define INIT_TASK_COMM "swapper"
83193
83194+#ifdef CONFIG_X86
83195+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
83196+#else
83197+#define INIT_TASK_THREAD_INFO
83198+#endif
83199+
83200 #ifdef CONFIG_RT_MUTEXES
83201 # define INIT_RT_MUTEXES(tsk) \
83202 .pi_waiters = RB_ROOT, \
83203@@ -196,6 +202,7 @@ extern struct task_group root_task_group;
83204 RCU_POINTER_INITIALIZER(cred, &init_cred), \
83205 .comm = INIT_TASK_COMM, \
83206 .thread = INIT_THREAD, \
83207+ INIT_TASK_THREAD_INFO \
83208 .fs = &init_fs, \
83209 .files = &init_files, \
83210 .signal = &init_signals, \
83211diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
83212index 698ad05..8601bb7 100644
83213--- a/include/linux/interrupt.h
83214+++ b/include/linux/interrupt.h
83215@@ -418,8 +418,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
83216
83217 struct softirq_action
83218 {
83219- void (*action)(struct softirq_action *);
83220-};
83221+ void (*action)(void);
83222+} __no_const;
83223
83224 asmlinkage void do_softirq(void);
83225 asmlinkage void __do_softirq(void);
83226@@ -433,7 +433,7 @@ static inline void do_softirq_own_stack(void)
83227 }
83228 #endif
83229
83230-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
83231+extern void open_softirq(int nr, void (*action)(void));
83232 extern void softirq_init(void);
83233 extern void __raise_softirq_irqoff(unsigned int nr);
83234
83235diff --git a/include/linux/iommu.h b/include/linux/iommu.h
83236index 20f9a52..63ee2e3 100644
83237--- a/include/linux/iommu.h
83238+++ b/include/linux/iommu.h
83239@@ -131,7 +131,7 @@ struct iommu_ops {
83240 u32 (*domain_get_windows)(struct iommu_domain *domain);
83241
83242 unsigned long pgsize_bitmap;
83243-};
83244+} __do_const;
83245
83246 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
83247 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
83248diff --git a/include/linux/ioport.h b/include/linux/ioport.h
83249index 142ec54..873e033 100644
83250--- a/include/linux/ioport.h
83251+++ b/include/linux/ioport.h
83252@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
83253 int adjust_resource(struct resource *res, resource_size_t start,
83254 resource_size_t size);
83255 resource_size_t resource_alignment(struct resource *res);
83256-static inline resource_size_t resource_size(const struct resource *res)
83257+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
83258 {
83259 return res->end - res->start + 1;
83260 }
83261diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
83262index 35e7eca..6afb7ad 100644
83263--- a/include/linux/ipc_namespace.h
83264+++ b/include/linux/ipc_namespace.h
83265@@ -69,7 +69,7 @@ struct ipc_namespace {
83266 struct user_namespace *user_ns;
83267
83268 unsigned int proc_inum;
83269-};
83270+} __randomize_layout;
83271
83272 extern struct ipc_namespace init_ipc_ns;
83273 extern atomic_t nr_ipc_ns;
83274diff --git a/include/linux/irq.h b/include/linux/irq.h
83275index 62af592..cc3b0d0 100644
83276--- a/include/linux/irq.h
83277+++ b/include/linux/irq.h
83278@@ -344,7 +344,8 @@ struct irq_chip {
83279 void (*irq_release_resources)(struct irq_data *data);
83280
83281 unsigned long flags;
83282-};
83283+} __do_const;
83284+typedef struct irq_chip __no_const irq_chip_no_const;
83285
83286 /*
83287 * irq_chip specific flags
83288diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
83289index 45e2d8c..26d85da 100644
83290--- a/include/linux/irqchip/arm-gic.h
83291+++ b/include/linux/irqchip/arm-gic.h
83292@@ -75,9 +75,11 @@
83293
83294 #ifndef __ASSEMBLY__
83295
83296+#include <linux/irq.h>
83297+
83298 struct device_node;
83299
83300-extern struct irq_chip gic_arch_extn;
83301+extern irq_chip_no_const gic_arch_extn;
83302
83303 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
83304 u32 offset, struct device_node *);
83305diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
83306index c367cbd..c9b79e6 100644
83307--- a/include/linux/jiffies.h
83308+++ b/include/linux/jiffies.h
83309@@ -280,20 +280,20 @@ extern unsigned long preset_lpj;
83310 /*
83311 * Convert various time units to each other:
83312 */
83313-extern unsigned int jiffies_to_msecs(const unsigned long j);
83314-extern unsigned int jiffies_to_usecs(const unsigned long j);
83315+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
83316+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
83317
83318-static inline u64 jiffies_to_nsecs(const unsigned long j)
83319+static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
83320 {
83321 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
83322 }
83323
83324-extern unsigned long msecs_to_jiffies(const unsigned int m);
83325-extern unsigned long usecs_to_jiffies(const unsigned int u);
83326+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
83327+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
83328 extern unsigned long timespec_to_jiffies(const struct timespec *value);
83329 extern void jiffies_to_timespec(const unsigned long jiffies,
83330- struct timespec *value);
83331-extern unsigned long timeval_to_jiffies(const struct timeval *value);
83332+ struct timespec *value) __intentional_overflow(-1);
83333+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
83334 extern void jiffies_to_timeval(const unsigned long jiffies,
83335 struct timeval *value);
83336
83337diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
83338index 6883e19..e854fcb 100644
83339--- a/include/linux/kallsyms.h
83340+++ b/include/linux/kallsyms.h
83341@@ -15,7 +15,8 @@
83342
83343 struct module;
83344
83345-#ifdef CONFIG_KALLSYMS
83346+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
83347+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
83348 /* Lookup the address for a symbol. Returns 0 if not found. */
83349 unsigned long kallsyms_lookup_name(const char *name);
83350
83351@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
83352 /* Stupid that this does nothing, but I didn't create this mess. */
83353 #define __print_symbol(fmt, addr)
83354 #endif /*CONFIG_KALLSYMS*/
83355+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
83356+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
83357+extern unsigned long kallsyms_lookup_name(const char *name);
83358+extern void __print_symbol(const char *fmt, unsigned long address);
83359+extern int sprint_backtrace(char *buffer, unsigned long address);
83360+extern int sprint_symbol(char *buffer, unsigned long address);
83361+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
83362+const char *kallsyms_lookup(unsigned long addr,
83363+ unsigned long *symbolsize,
83364+ unsigned long *offset,
83365+ char **modname, char *namebuf);
83366+extern int kallsyms_lookup_size_offset(unsigned long addr,
83367+ unsigned long *symbolsize,
83368+ unsigned long *offset);
83369+#endif
83370
83371 /* This macro allows us to keep printk typechecking */
83372 static __printf(1, 2)
83373diff --git a/include/linux/key-type.h b/include/linux/key-type.h
83374index 44792ee..6172f2a 100644
83375--- a/include/linux/key-type.h
83376+++ b/include/linux/key-type.h
83377@@ -132,7 +132,7 @@ struct key_type {
83378 /* internal fields */
83379 struct list_head link; /* link in types list */
83380 struct lock_class_key lock_class; /* key->sem lock class */
83381-};
83382+} __do_const;
83383
83384 extern struct key_type key_type_keyring;
83385
83386diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
83387index e465bb1..19f605f 100644
83388--- a/include/linux/kgdb.h
83389+++ b/include/linux/kgdb.h
83390@@ -52,7 +52,7 @@ extern int kgdb_connected;
83391 extern int kgdb_io_module_registered;
83392
83393 extern atomic_t kgdb_setting_breakpoint;
83394-extern atomic_t kgdb_cpu_doing_single_step;
83395+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
83396
83397 extern struct task_struct *kgdb_usethread;
83398 extern struct task_struct *kgdb_contthread;
83399@@ -254,7 +254,7 @@ struct kgdb_arch {
83400 void (*correct_hw_break)(void);
83401
83402 void (*enable_nmi)(bool on);
83403-};
83404+} __do_const;
83405
83406 /**
83407 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
83408@@ -279,7 +279,7 @@ struct kgdb_io {
83409 void (*pre_exception) (void);
83410 void (*post_exception) (void);
83411 int is_console;
83412-};
83413+} __do_const;
83414
83415 extern struct kgdb_arch arch_kgdb_ops;
83416
83417diff --git a/include/linux/kmod.h b/include/linux/kmod.h
83418index 0555cc6..40116ce 100644
83419--- a/include/linux/kmod.h
83420+++ b/include/linux/kmod.h
83421@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
83422 * usually useless though. */
83423 extern __printf(2, 3)
83424 int __request_module(bool wait, const char *name, ...);
83425+extern __printf(3, 4)
83426+int ___request_module(bool wait, char *param_name, const char *name, ...);
83427 #define request_module(mod...) __request_module(true, mod)
83428 #define request_module_nowait(mod...) __request_module(false, mod)
83429 #define try_then_request_module(x, mod...) \
83430@@ -57,6 +59,9 @@ struct subprocess_info {
83431 struct work_struct work;
83432 struct completion *complete;
83433 char *path;
83434+#ifdef CONFIG_GRKERNSEC
83435+ char *origpath;
83436+#endif
83437 char **argv;
83438 char **envp;
83439 int wait;
83440diff --git a/include/linux/kobject.h b/include/linux/kobject.h
83441index 2d61b90..a1d0a13 100644
83442--- a/include/linux/kobject.h
83443+++ b/include/linux/kobject.h
83444@@ -118,7 +118,7 @@ struct kobj_type {
83445 struct attribute **default_attrs;
83446 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
83447 const void *(*namespace)(struct kobject *kobj);
83448-};
83449+} __do_const;
83450
83451 struct kobj_uevent_env {
83452 char *argv[3];
83453@@ -142,6 +142,7 @@ struct kobj_attribute {
83454 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
83455 const char *buf, size_t count);
83456 };
83457+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
83458
83459 extern const struct sysfs_ops kobj_sysfs_ops;
83460
83461@@ -169,7 +170,7 @@ struct kset {
83462 spinlock_t list_lock;
83463 struct kobject kobj;
83464 const struct kset_uevent_ops *uevent_ops;
83465-};
83466+} __randomize_layout;
83467
83468 extern void kset_init(struct kset *kset);
83469 extern int __must_check kset_register(struct kset *kset);
83470diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
83471index df32d25..fb52e27 100644
83472--- a/include/linux/kobject_ns.h
83473+++ b/include/linux/kobject_ns.h
83474@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
83475 const void *(*netlink_ns)(struct sock *sk);
83476 const void *(*initial_ns)(void);
83477 void (*drop_ns)(void *);
83478-};
83479+} __do_const;
83480
83481 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
83482 int kobj_ns_type_registered(enum kobj_ns_type type);
83483diff --git a/include/linux/kref.h b/include/linux/kref.h
83484index 484604d..0f6c5b6 100644
83485--- a/include/linux/kref.h
83486+++ b/include/linux/kref.h
83487@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
83488 static inline int kref_sub(struct kref *kref, unsigned int count,
83489 void (*release)(struct kref *kref))
83490 {
83491- WARN_ON(release == NULL);
83492+ BUG_ON(release == NULL);
83493
83494 if (atomic_sub_and_test((int) count, &kref->refcount)) {
83495 release(kref);
83496diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
83497index a4c33b3..e854710 100644
83498--- a/include/linux/kvm_host.h
83499+++ b/include/linux/kvm_host.h
83500@@ -452,7 +452,7 @@ static inline void kvm_irqfd_exit(void)
83501 {
83502 }
83503 #endif
83504-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
83505+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
83506 struct module *module);
83507 void kvm_exit(void);
83508
83509@@ -618,7 +618,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
83510 struct kvm_guest_debug *dbg);
83511 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
83512
83513-int kvm_arch_init(void *opaque);
83514+int kvm_arch_init(const void *opaque);
83515 void kvm_arch_exit(void);
83516
83517 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
83518diff --git a/include/linux/libata.h b/include/linux/libata.h
83519index 92abb49..e7fff2a 100644
83520--- a/include/linux/libata.h
83521+++ b/include/linux/libata.h
83522@@ -976,7 +976,7 @@ struct ata_port_operations {
83523 * fields must be pointers.
83524 */
83525 const struct ata_port_operations *inherits;
83526-};
83527+} __do_const;
83528
83529 struct ata_port_info {
83530 unsigned long flags;
83531diff --git a/include/linux/linkage.h b/include/linux/linkage.h
83532index a6a42dd..6c5ebce 100644
83533--- a/include/linux/linkage.h
83534+++ b/include/linux/linkage.h
83535@@ -36,6 +36,7 @@
83536 #endif
83537
83538 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
83539+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
83540 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
83541
83542 /*
83543diff --git a/include/linux/list.h b/include/linux/list.h
83544index cbbb96f..602d023 100644
83545--- a/include/linux/list.h
83546+++ b/include/linux/list.h
83547@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
83548 extern void list_del(struct list_head *entry);
83549 #endif
83550
83551+extern void __pax_list_add(struct list_head *new,
83552+ struct list_head *prev,
83553+ struct list_head *next);
83554+static inline void pax_list_add(struct list_head *new, struct list_head *head)
83555+{
83556+ __pax_list_add(new, head, head->next);
83557+}
83558+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
83559+{
83560+ __pax_list_add(new, head->prev, head);
83561+}
83562+extern void pax_list_del(struct list_head *entry);
83563+
83564 /**
83565 * list_replace - replace old entry by new one
83566 * @old : the element to be replaced
83567@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
83568 INIT_LIST_HEAD(entry);
83569 }
83570
83571+extern void pax_list_del_init(struct list_head *entry);
83572+
83573 /**
83574 * list_move - delete from one list and add as another's head
83575 * @list: the entry to move
83576diff --git a/include/linux/lockref.h b/include/linux/lockref.h
83577index 4bfde0e..d6e2e09 100644
83578--- a/include/linux/lockref.h
83579+++ b/include/linux/lockref.h
83580@@ -47,4 +47,36 @@ static inline int __lockref_is_dead(const struct lockref *l)
83581 return ((int)l->count < 0);
83582 }
83583
83584+static inline unsigned int __lockref_read(struct lockref *lockref)
83585+{
83586+ return lockref->count;
83587+}
83588+
83589+static inline void __lockref_set(struct lockref *lockref, unsigned int count)
83590+{
83591+ lockref->count = count;
83592+}
83593+
83594+static inline void __lockref_inc(struct lockref *lockref)
83595+{
83596+
83597+#ifdef CONFIG_PAX_REFCOUNT
83598+ atomic_inc((atomic_t *)&lockref->count);
83599+#else
83600+ lockref->count++;
83601+#endif
83602+
83603+}
83604+
83605+static inline void __lockref_dec(struct lockref *lockref)
83606+{
83607+
83608+#ifdef CONFIG_PAX_REFCOUNT
83609+ atomic_dec((atomic_t *)&lockref->count);
83610+#else
83611+ lockref->count--;
83612+#endif
83613+
83614+}
83615+
83616 #endif /* __LINUX_LOCKREF_H */
83617diff --git a/include/linux/math64.h b/include/linux/math64.h
83618index c45c089..298841c 100644
83619--- a/include/linux/math64.h
83620+++ b/include/linux/math64.h
83621@@ -15,7 +15,7 @@
83622 * This is commonly provided by 32bit archs to provide an optimized 64bit
83623 * divide.
83624 */
83625-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83626+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83627 {
83628 *remainder = dividend % divisor;
83629 return dividend / divisor;
83630@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
83631 /**
83632 * div64_u64 - unsigned 64bit divide with 64bit divisor
83633 */
83634-static inline u64 div64_u64(u64 dividend, u64 divisor)
83635+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
83636 {
83637 return dividend / divisor;
83638 }
83639@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
83640 #define div64_ul(x, y) div_u64((x), (y))
83641
83642 #ifndef div_u64_rem
83643-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83644+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83645 {
83646 *remainder = do_div(dividend, divisor);
83647 return dividend;
83648@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
83649 #endif
83650
83651 #ifndef div64_u64
83652-extern u64 div64_u64(u64 dividend, u64 divisor);
83653+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
83654 #endif
83655
83656 #ifndef div64_s64
83657@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
83658 * divide.
83659 */
83660 #ifndef div_u64
83661-static inline u64 div_u64(u64 dividend, u32 divisor)
83662+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
83663 {
83664 u32 remainder;
83665 return div_u64_rem(dividend, divisor, &remainder);
83666diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
83667index f230a97..714c006 100644
83668--- a/include/linux/mempolicy.h
83669+++ b/include/linux/mempolicy.h
83670@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
83671 }
83672
83673 #define vma_policy(vma) ((vma)->vm_policy)
83674+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83675+{
83676+ vma->vm_policy = pol;
83677+}
83678
83679 static inline void mpol_get(struct mempolicy *pol)
83680 {
83681@@ -228,6 +232,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
83682 }
83683
83684 #define vma_policy(vma) NULL
83685+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83686+{
83687+}
83688
83689 static inline int
83690 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
83691diff --git a/include/linux/mm.h b/include/linux/mm.h
83692index f952cc8..b9f6135 100644
83693--- a/include/linux/mm.h
83694+++ b/include/linux/mm.h
83695@@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
83696 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
83697 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
83698 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
83699+
83700+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
83701+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
83702+#endif
83703+
83704 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
83705
83706 #ifdef CONFIG_MEM_SOFT_DIRTY
83707@@ -237,8 +242,8 @@ struct vm_operations_struct {
83708 /* called by access_process_vm when get_user_pages() fails, typically
83709 * for use by special VMAs that can switch between memory and hardware
83710 */
83711- int (*access)(struct vm_area_struct *vma, unsigned long addr,
83712- void *buf, int len, int write);
83713+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
83714+ void *buf, size_t len, int write);
83715
83716 /* Called by the /proc/PID/maps code to ask the vma whether it
83717 * has a special name. Returning non-NULL will also cause this
83718@@ -274,6 +279,7 @@ struct vm_operations_struct {
83719 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
83720 unsigned long size, pgoff_t pgoff);
83721 };
83722+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
83723
83724 struct mmu_gather;
83725 struct inode;
83726@@ -1163,8 +1169,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
83727 unsigned long *pfn);
83728 int follow_phys(struct vm_area_struct *vma, unsigned long address,
83729 unsigned int flags, unsigned long *prot, resource_size_t *phys);
83730-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83731- void *buf, int len, int write);
83732+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83733+ void *buf, size_t len, int write);
83734
83735 static inline void unmap_shared_mapping_range(struct address_space *mapping,
83736 loff_t const holebegin, loff_t const holelen)
83737@@ -1204,9 +1210,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
83738 }
83739 #endif
83740
83741-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
83742-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83743- void *buf, int len, int write);
83744+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
83745+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
83746+ void *buf, size_t len, int write);
83747
83748 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
83749 unsigned long start, unsigned long nr_pages,
83750@@ -1238,34 +1244,6 @@ int set_page_dirty_lock(struct page *page);
83751 int clear_page_dirty_for_io(struct page *page);
83752 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
83753
83754-/* Is the vma a continuation of the stack vma above it? */
83755-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
83756-{
83757- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
83758-}
83759-
83760-static inline int stack_guard_page_start(struct vm_area_struct *vma,
83761- unsigned long addr)
83762-{
83763- return (vma->vm_flags & VM_GROWSDOWN) &&
83764- (vma->vm_start == addr) &&
83765- !vma_growsdown(vma->vm_prev, addr);
83766-}
83767-
83768-/* Is the vma a continuation of the stack vma below it? */
83769-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
83770-{
83771- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
83772-}
83773-
83774-static inline int stack_guard_page_end(struct vm_area_struct *vma,
83775- unsigned long addr)
83776-{
83777- return (vma->vm_flags & VM_GROWSUP) &&
83778- (vma->vm_end == addr) &&
83779- !vma_growsup(vma->vm_next, addr);
83780-}
83781-
83782 extern pid_t
83783 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
83784
83785@@ -1365,6 +1343,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
83786 }
83787 #endif
83788
83789+#ifdef CONFIG_MMU
83790+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
83791+#else
83792+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
83793+{
83794+ return __pgprot(0);
83795+}
83796+#endif
83797+
83798 int vma_wants_writenotify(struct vm_area_struct *vma);
83799
83800 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
83801@@ -1383,8 +1370,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
83802 {
83803 return 0;
83804 }
83805+
83806+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
83807+ unsigned long address)
83808+{
83809+ return 0;
83810+}
83811 #else
83812 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83813+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83814 #endif
83815
83816 #ifdef __PAGETABLE_PMD_FOLDED
83817@@ -1393,8 +1387,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
83818 {
83819 return 0;
83820 }
83821+
83822+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
83823+ unsigned long address)
83824+{
83825+ return 0;
83826+}
83827 #else
83828 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
83829+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
83830 #endif
83831
83832 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
83833@@ -1412,11 +1413,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
83834 NULL: pud_offset(pgd, address);
83835 }
83836
83837+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
83838+{
83839+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
83840+ NULL: pud_offset(pgd, address);
83841+}
83842+
83843 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
83844 {
83845 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
83846 NULL: pmd_offset(pud, address);
83847 }
83848+
83849+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
83850+{
83851+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
83852+ NULL: pmd_offset(pud, address);
83853+}
83854 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
83855
83856 #if USE_SPLIT_PTE_PTLOCKS
83857@@ -1815,7 +1828,7 @@ extern int install_special_mapping(struct mm_struct *mm,
83858 unsigned long addr, unsigned long len,
83859 unsigned long flags, struct page **pages);
83860
83861-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
83862+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
83863
83864 extern unsigned long mmap_region(struct file *file, unsigned long addr,
83865 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
83866@@ -1823,6 +1836,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
83867 unsigned long len, unsigned long prot, unsigned long flags,
83868 unsigned long pgoff, unsigned long *populate);
83869 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
83870+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
83871
83872 #ifdef CONFIG_MMU
83873 extern int __mm_populate(unsigned long addr, unsigned long len,
83874@@ -1851,10 +1865,11 @@ struct vm_unmapped_area_info {
83875 unsigned long high_limit;
83876 unsigned long align_mask;
83877 unsigned long align_offset;
83878+ unsigned long threadstack_offset;
83879 };
83880
83881-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
83882-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83883+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
83884+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
83885
83886 /*
83887 * Search for an unmapped address range.
83888@@ -1866,7 +1881,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83889 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
83890 */
83891 static inline unsigned long
83892-vm_unmapped_area(struct vm_unmapped_area_info *info)
83893+vm_unmapped_area(const struct vm_unmapped_area_info *info)
83894 {
83895 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
83896 return unmapped_area(info);
83897@@ -1928,6 +1943,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
83898 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
83899 struct vm_area_struct **pprev);
83900
83901+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
83902+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
83903+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
83904+
83905 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
83906 NULL if none. Assume start_addr < end_addr. */
83907 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
83908@@ -1956,15 +1975,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
83909 return vma;
83910 }
83911
83912-#ifdef CONFIG_MMU
83913-pgprot_t vm_get_page_prot(unsigned long vm_flags);
83914-#else
83915-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
83916-{
83917- return __pgprot(0);
83918-}
83919-#endif
83920-
83921 #ifdef CONFIG_NUMA_BALANCING
83922 unsigned long change_prot_numa(struct vm_area_struct *vma,
83923 unsigned long start, unsigned long end);
83924@@ -2016,6 +2026,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
83925 static inline void vm_stat_account(struct mm_struct *mm,
83926 unsigned long flags, struct file *file, long pages)
83927 {
83928+
83929+#ifdef CONFIG_PAX_RANDMMAP
83930+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
83931+#endif
83932+
83933 mm->total_vm += pages;
83934 }
83935 #endif /* CONFIG_PROC_FS */
83936@@ -2104,7 +2119,7 @@ extern int unpoison_memory(unsigned long pfn);
83937 extern int sysctl_memory_failure_early_kill;
83938 extern int sysctl_memory_failure_recovery;
83939 extern void shake_page(struct page *p, int access);
83940-extern atomic_long_t num_poisoned_pages;
83941+extern atomic_long_unchecked_t num_poisoned_pages;
83942 extern int soft_offline_page(struct page *page, int flags);
83943
83944 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
83945@@ -2139,5 +2154,11 @@ void __init setup_nr_node_ids(void);
83946 static inline void setup_nr_node_ids(void) {}
83947 #endif
83948
83949+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83950+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
83951+#else
83952+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
83953+#endif
83954+
83955 #endif /* __KERNEL__ */
83956 #endif /* _LINUX_MM_H */
83957diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
83958index 6e0b286..90d9c0d 100644
83959--- a/include/linux/mm_types.h
83960+++ b/include/linux/mm_types.h
83961@@ -308,7 +308,9 @@ struct vm_area_struct {
83962 #ifdef CONFIG_NUMA
83963 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
83964 #endif
83965-};
83966+
83967+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
83968+} __randomize_layout;
83969
83970 struct core_thread {
83971 struct task_struct *task;
83972@@ -454,7 +456,25 @@ struct mm_struct {
83973 bool tlb_flush_pending;
83974 #endif
83975 struct uprobes_state uprobes_state;
83976-};
83977+
83978+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
83979+ unsigned long pax_flags;
83980+#endif
83981+
83982+#ifdef CONFIG_PAX_DLRESOLVE
83983+ unsigned long call_dl_resolve;
83984+#endif
83985+
83986+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
83987+ unsigned long call_syscall;
83988+#endif
83989+
83990+#ifdef CONFIG_PAX_ASLR
83991+ unsigned long delta_mmap; /* randomized offset */
83992+ unsigned long delta_stack; /* randomized offset */
83993+#endif
83994+
83995+} __randomize_layout;
83996
83997 static inline void mm_init_cpumask(struct mm_struct *mm)
83998 {
83999diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
84000index c5d5278..f0b68c8 100644
84001--- a/include/linux/mmiotrace.h
84002+++ b/include/linux/mmiotrace.h
84003@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
84004 /* Called from ioremap.c */
84005 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
84006 void __iomem *addr);
84007-extern void mmiotrace_iounmap(volatile void __iomem *addr);
84008+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
84009
84010 /* For anyone to insert markers. Remember trailing newline. */
84011 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
84012@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
84013 {
84014 }
84015
84016-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
84017+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
84018 {
84019 }
84020
84021diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
84022index b21bac4..94142ca 100644
84023--- a/include/linux/mmzone.h
84024+++ b/include/linux/mmzone.h
84025@@ -527,7 +527,7 @@ struct zone {
84026
84027 ZONE_PADDING(_pad3_)
84028 /* Zone statistics */
84029- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
84030+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
84031 } ____cacheline_internodealigned_in_smp;
84032
84033 typedef enum {
84034diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
84035index 44eeef0..a92d3f9 100644
84036--- a/include/linux/mod_devicetable.h
84037+++ b/include/linux/mod_devicetable.h
84038@@ -139,7 +139,7 @@ struct usb_device_id {
84039 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
84040 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
84041
84042-#define HID_ANY_ID (~0)
84043+#define HID_ANY_ID (~0U)
84044 #define HID_BUS_ANY 0xffff
84045 #define HID_GROUP_ANY 0x0000
84046
84047@@ -475,7 +475,7 @@ struct dmi_system_id {
84048 const char *ident;
84049 struct dmi_strmatch matches[4];
84050 void *driver_data;
84051-};
84052+} __do_const;
84053 /*
84054 * struct dmi_device_id appears during expansion of
84055 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
84056diff --git a/include/linux/module.h b/include/linux/module.h
84057index 71f282a..b2387e2 100644
84058--- a/include/linux/module.h
84059+++ b/include/linux/module.h
84060@@ -17,9 +17,11 @@
84061 #include <linux/moduleparam.h>
84062 #include <linux/jump_label.h>
84063 #include <linux/export.h>
84064+#include <linux/fs.h>
84065
84066 #include <linux/percpu.h>
84067 #include <asm/module.h>
84068+#include <asm/pgtable.h>
84069
84070 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
84071 #define MODULE_SIG_STRING "~Module signature appended~\n"
84072@@ -42,7 +44,7 @@ struct module_kobject {
84073 struct kobject *drivers_dir;
84074 struct module_param_attrs *mp;
84075 struct completion *kobj_completion;
84076-};
84077+} __randomize_layout;
84078
84079 struct module_attribute {
84080 struct attribute attr;
84081@@ -54,12 +56,13 @@ struct module_attribute {
84082 int (*test)(struct module *);
84083 void (*free)(struct module *);
84084 };
84085+typedef struct module_attribute __no_const module_attribute_no_const;
84086
84087 struct module_version_attribute {
84088 struct module_attribute mattr;
84089 const char *module_name;
84090 const char *version;
84091-} __attribute__ ((__aligned__(sizeof(void *))));
84092+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
84093
84094 extern ssize_t __modver_version_show(struct module_attribute *,
84095 struct module_kobject *, char *);
84096@@ -235,7 +238,7 @@ struct module {
84097
84098 /* Sysfs stuff. */
84099 struct module_kobject mkobj;
84100- struct module_attribute *modinfo_attrs;
84101+ module_attribute_no_const *modinfo_attrs;
84102 const char *version;
84103 const char *srcversion;
84104 struct kobject *holders_dir;
84105@@ -284,19 +287,16 @@ struct module {
84106 int (*init)(void);
84107
84108 /* If this is non-NULL, vfree after init() returns */
84109- void *module_init;
84110+ void *module_init_rx, *module_init_rw;
84111
84112 /* Here is the actual code + data, vfree'd on unload. */
84113- void *module_core;
84114+ void *module_core_rx, *module_core_rw;
84115
84116 /* Here are the sizes of the init and core sections */
84117- unsigned int init_size, core_size;
84118+ unsigned int init_size_rw, core_size_rw;
84119
84120 /* The size of the executable code in each section. */
84121- unsigned int init_text_size, core_text_size;
84122-
84123- /* Size of RO sections of the module (text+rodata) */
84124- unsigned int init_ro_size, core_ro_size;
84125+ unsigned int init_size_rx, core_size_rx;
84126
84127 /* Arch-specific module values */
84128 struct mod_arch_specific arch;
84129@@ -352,6 +352,10 @@ struct module {
84130 #ifdef CONFIG_EVENT_TRACING
84131 struct ftrace_event_call **trace_events;
84132 unsigned int num_trace_events;
84133+ struct file_operations trace_id;
84134+ struct file_operations trace_enable;
84135+ struct file_operations trace_format;
84136+ struct file_operations trace_filter;
84137 #endif
84138 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
84139 unsigned int num_ftrace_callsites;
84140@@ -375,7 +379,7 @@ struct module {
84141 ctor_fn_t *ctors;
84142 unsigned int num_ctors;
84143 #endif
84144-};
84145+} __randomize_layout;
84146 #ifndef MODULE_ARCH_INIT
84147 #define MODULE_ARCH_INIT {}
84148 #endif
84149@@ -396,18 +400,48 @@ bool is_module_address(unsigned long addr);
84150 bool is_module_percpu_address(unsigned long addr);
84151 bool is_module_text_address(unsigned long addr);
84152
84153+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
84154+{
84155+
84156+#ifdef CONFIG_PAX_KERNEXEC
84157+ if (ktla_ktva(addr) >= (unsigned long)start &&
84158+ ktla_ktva(addr) < (unsigned long)start + size)
84159+ return 1;
84160+#endif
84161+
84162+ return ((void *)addr >= start && (void *)addr < start + size);
84163+}
84164+
84165+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
84166+{
84167+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
84168+}
84169+
84170+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
84171+{
84172+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
84173+}
84174+
84175+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
84176+{
84177+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
84178+}
84179+
84180+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
84181+{
84182+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
84183+}
84184+
84185 static inline bool within_module_core(unsigned long addr,
84186 const struct module *mod)
84187 {
84188- return (unsigned long)mod->module_core <= addr &&
84189- addr < (unsigned long)mod->module_core + mod->core_size;
84190+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
84191 }
84192
84193 static inline bool within_module_init(unsigned long addr,
84194 const struct module *mod)
84195 {
84196- return (unsigned long)mod->module_init <= addr &&
84197- addr < (unsigned long)mod->module_init + mod->init_size;
84198+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
84199 }
84200
84201 static inline bool within_module(unsigned long addr, const struct module *mod)
84202diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
84203index 7eeb9bb..68f37e0 100644
84204--- a/include/linux/moduleloader.h
84205+++ b/include/linux/moduleloader.h
84206@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
84207 sections. Returns NULL on failure. */
84208 void *module_alloc(unsigned long size);
84209
84210+#ifdef CONFIG_PAX_KERNEXEC
84211+void *module_alloc_exec(unsigned long size);
84212+#else
84213+#define module_alloc_exec(x) module_alloc(x)
84214+#endif
84215+
84216 /* Free memory returned from module_alloc. */
84217 void module_free(struct module *mod, void *module_region);
84218
84219+#ifdef CONFIG_PAX_KERNEXEC
84220+void module_free_exec(struct module *mod, void *module_region);
84221+#else
84222+#define module_free_exec(x, y) module_free((x), (y))
84223+#endif
84224+
84225 /*
84226 * Apply the given relocation to the (simplified) ELF. Return -error
84227 * or 0.
84228@@ -45,8 +57,10 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
84229 unsigned int relsec,
84230 struct module *me)
84231 {
84232+#ifdef CONFIG_MODULES
84233 printk(KERN_ERR "module %s: REL relocation unsupported\n",
84234 module_name(me));
84235+#endif
84236 return -ENOEXEC;
84237 }
84238 #endif
84239@@ -68,8 +82,10 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
84240 unsigned int relsec,
84241 struct module *me)
84242 {
84243+#ifdef CONFIG_MODULES
84244 printk(KERN_ERR "module %s: REL relocation unsupported\n",
84245 module_name(me));
84246+#endif
84247 return -ENOEXEC;
84248 }
84249 #endif
84250diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
84251index 494f99e..5059f63 100644
84252--- a/include/linux/moduleparam.h
84253+++ b/include/linux/moduleparam.h
84254@@ -293,7 +293,7 @@ static inline void __kernel_param_unlock(void)
84255 * @len is usually just sizeof(string).
84256 */
84257 #define module_param_string(name, string, len, perm) \
84258- static const struct kparam_string __param_string_##name \
84259+ static const struct kparam_string __param_string_##name __used \
84260 = { len, string }; \
84261 __module_param_call(MODULE_PARAM_PREFIX, name, \
84262 &param_ops_string, \
84263@@ -437,7 +437,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
84264 */
84265 #define module_param_array_named(name, array, type, nump, perm) \
84266 param_check_##type(name, &(array)[0]); \
84267- static const struct kparam_array __param_arr_##name \
84268+ static const struct kparam_array __param_arr_##name __used \
84269 = { .max = ARRAY_SIZE(array), .num = nump, \
84270 .ops = &param_ops_##type, \
84271 .elemsize = sizeof(array[0]), .elem = array }; \
84272diff --git a/include/linux/mount.h b/include/linux/mount.h
84273index 9262e4b..0a45f98 100644
84274--- a/include/linux/mount.h
84275+++ b/include/linux/mount.h
84276@@ -66,7 +66,7 @@ struct vfsmount {
84277 struct dentry *mnt_root; /* root of the mounted tree */
84278 struct super_block *mnt_sb; /* pointer to superblock */
84279 int mnt_flags;
84280-};
84281+} __randomize_layout;
84282
84283 struct file; /* forward dec */
84284 struct path;
84285diff --git a/include/linux/namei.h b/include/linux/namei.h
84286index 492de72..1bddcd4 100644
84287--- a/include/linux/namei.h
84288+++ b/include/linux/namei.h
84289@@ -19,7 +19,7 @@ struct nameidata {
84290 unsigned seq, m_seq;
84291 int last_type;
84292 unsigned depth;
84293- char *saved_names[MAX_NESTED_LINKS + 1];
84294+ const char *saved_names[MAX_NESTED_LINKS + 1];
84295 };
84296
84297 /*
84298@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
84299
84300 extern void nd_jump_link(struct nameidata *nd, struct path *path);
84301
84302-static inline void nd_set_link(struct nameidata *nd, char *path)
84303+static inline void nd_set_link(struct nameidata *nd, const char *path)
84304 {
84305 nd->saved_names[nd->depth] = path;
84306 }
84307
84308-static inline char *nd_get_link(struct nameidata *nd)
84309+static inline const char *nd_get_link(const struct nameidata *nd)
84310 {
84311 return nd->saved_names[nd->depth];
84312 }
84313diff --git a/include/linux/net.h b/include/linux/net.h
84314index 17d8339..81656c0 100644
84315--- a/include/linux/net.h
84316+++ b/include/linux/net.h
84317@@ -192,7 +192,7 @@ struct net_proto_family {
84318 int (*create)(struct net *net, struct socket *sock,
84319 int protocol, int kern);
84320 struct module *owner;
84321-};
84322+} __do_const;
84323
84324 struct iovec;
84325 struct kvec;
84326diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
84327index c8e388e..5d8cd9b 100644
84328--- a/include/linux/netdevice.h
84329+++ b/include/linux/netdevice.h
84330@@ -1147,6 +1147,7 @@ struct net_device_ops {
84331 void *priv);
84332 int (*ndo_get_lock_subclass)(struct net_device *dev);
84333 };
84334+typedef struct net_device_ops __no_const net_device_ops_no_const;
84335
84336 /**
84337 * enum net_device_priv_flags - &struct net_device priv_flags
84338@@ -1485,10 +1486,10 @@ struct net_device {
84339
84340 struct net_device_stats stats;
84341
84342- atomic_long_t rx_dropped;
84343- atomic_long_t tx_dropped;
84344+ atomic_long_unchecked_t rx_dropped;
84345+ atomic_long_unchecked_t tx_dropped;
84346
84347- atomic_t carrier_changes;
84348+ atomic_unchecked_t carrier_changes;
84349
84350 #ifdef CONFIG_WIRELESS_EXT
84351 const struct iw_handler_def * wireless_handlers;
84352diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
84353index 2517ece..0bbfcfb 100644
84354--- a/include/linux/netfilter.h
84355+++ b/include/linux/netfilter.h
84356@@ -85,7 +85,7 @@ struct nf_sockopt_ops {
84357 #endif
84358 /* Use the module struct to lock set/get code in place */
84359 struct module *owner;
84360-};
84361+} __do_const;
84362
84363 /* Function to register/unregister hook points. */
84364 int nf_register_hook(struct nf_hook_ops *reg);
84365diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
84366index e955d47..04a5338 100644
84367--- a/include/linux/netfilter/nfnetlink.h
84368+++ b/include/linux/netfilter/nfnetlink.h
84369@@ -19,7 +19,7 @@ struct nfnl_callback {
84370 const struct nlattr * const cda[]);
84371 const struct nla_policy *policy; /* netlink attribute policy */
84372 const u_int16_t attr_count; /* number of nlattr's */
84373-};
84374+} __do_const;
84375
84376 struct nfnetlink_subsystem {
84377 const char *name;
84378diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
84379new file mode 100644
84380index 0000000..33f4af8
84381--- /dev/null
84382+++ b/include/linux/netfilter/xt_gradm.h
84383@@ -0,0 +1,9 @@
84384+#ifndef _LINUX_NETFILTER_XT_GRADM_H
84385+#define _LINUX_NETFILTER_XT_GRADM_H 1
84386+
84387+struct xt_gradm_mtinfo {
84388+ __u16 flags;
84389+ __u16 invflags;
84390+};
84391+
84392+#endif
84393diff --git a/include/linux/nls.h b/include/linux/nls.h
84394index 520681b..2b7fabb 100644
84395--- a/include/linux/nls.h
84396+++ b/include/linux/nls.h
84397@@ -31,7 +31,7 @@ struct nls_table {
84398 const unsigned char *charset2upper;
84399 struct module *owner;
84400 struct nls_table *next;
84401-};
84402+} __do_const;
84403
84404 /* this value hold the maximum octet of charset */
84405 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
84406@@ -46,7 +46,7 @@ enum utf16_endian {
84407 /* nls_base.c */
84408 extern int __register_nls(struct nls_table *, struct module *);
84409 extern int unregister_nls(struct nls_table *);
84410-extern struct nls_table *load_nls(char *);
84411+extern struct nls_table *load_nls(const char *);
84412 extern void unload_nls(struct nls_table *);
84413 extern struct nls_table *load_nls_default(void);
84414 #define register_nls(nls) __register_nls((nls), THIS_MODULE)
84415diff --git a/include/linux/notifier.h b/include/linux/notifier.h
84416index d14a4c3..a078786 100644
84417--- a/include/linux/notifier.h
84418+++ b/include/linux/notifier.h
84419@@ -54,7 +54,8 @@ struct notifier_block {
84420 notifier_fn_t notifier_call;
84421 struct notifier_block __rcu *next;
84422 int priority;
84423-};
84424+} __do_const;
84425+typedef struct notifier_block __no_const notifier_block_no_const;
84426
84427 struct atomic_notifier_head {
84428 spinlock_t lock;
84429diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
84430index b2a0f15..4d7da32 100644
84431--- a/include/linux/oprofile.h
84432+++ b/include/linux/oprofile.h
84433@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
84434 int oprofilefs_create_ro_ulong(struct dentry * root,
84435 char const * name, ulong * val);
84436
84437-/** Create a file for read-only access to an atomic_t. */
84438+/** Create a file for read-only access to an atomic_unchecked_t. */
84439 int oprofilefs_create_ro_atomic(struct dentry * root,
84440- char const * name, atomic_t * val);
84441+ char const * name, atomic_unchecked_t * val);
84442
84443 /** create a directory */
84444 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
84445diff --git a/include/linux/padata.h b/include/linux/padata.h
84446index 4386946..f50c615 100644
84447--- a/include/linux/padata.h
84448+++ b/include/linux/padata.h
84449@@ -129,7 +129,7 @@ struct parallel_data {
84450 struct padata_serial_queue __percpu *squeue;
84451 atomic_t reorder_objects;
84452 atomic_t refcnt;
84453- atomic_t seq_nr;
84454+ atomic_unchecked_t seq_nr;
84455 struct padata_cpumask cpumask;
84456 spinlock_t lock ____cacheline_aligned;
84457 unsigned int processed;
84458diff --git a/include/linux/path.h b/include/linux/path.h
84459index d137218..be0c176 100644
84460--- a/include/linux/path.h
84461+++ b/include/linux/path.h
84462@@ -1,13 +1,15 @@
84463 #ifndef _LINUX_PATH_H
84464 #define _LINUX_PATH_H
84465
84466+#include <linux/compiler.h>
84467+
84468 struct dentry;
84469 struct vfsmount;
84470
84471 struct path {
84472 struct vfsmount *mnt;
84473 struct dentry *dentry;
84474-};
84475+} __randomize_layout;
84476
84477 extern void path_get(const struct path *);
84478 extern void path_put(const struct path *);
84479diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
84480index 5f2e559..7d59314 100644
84481--- a/include/linux/pci_hotplug.h
84482+++ b/include/linux/pci_hotplug.h
84483@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
84484 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
84485 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
84486 int (*reset_slot) (struct hotplug_slot *slot, int probe);
84487-};
84488+} __do_const;
84489+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
84490
84491 /**
84492 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
84493diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
84494index 707617a..28a2e7e 100644
84495--- a/include/linux/perf_event.h
84496+++ b/include/linux/perf_event.h
84497@@ -339,8 +339,8 @@ struct perf_event {
84498
84499 enum perf_event_active_state state;
84500 unsigned int attach_state;
84501- local64_t count;
84502- atomic64_t child_count;
84503+ local64_t count; /* PaX: fix it one day */
84504+ atomic64_unchecked_t child_count;
84505
84506 /*
84507 * These are the total time in nanoseconds that the event
84508@@ -391,8 +391,8 @@ struct perf_event {
84509 * These accumulate total time (in nanoseconds) that children
84510 * events have been enabled and running, respectively.
84511 */
84512- atomic64_t child_total_time_enabled;
84513- atomic64_t child_total_time_running;
84514+ atomic64_unchecked_t child_total_time_enabled;
84515+ atomic64_unchecked_t child_total_time_running;
84516
84517 /*
84518 * Protect attach/detach and child_list:
84519@@ -722,7 +722,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
84520 entry->ip[entry->nr++] = ip;
84521 }
84522
84523-extern int sysctl_perf_event_paranoid;
84524+extern int sysctl_perf_event_legitimately_concerned;
84525 extern int sysctl_perf_event_mlock;
84526 extern int sysctl_perf_event_sample_rate;
84527 extern int sysctl_perf_cpu_time_max_percent;
84528@@ -737,19 +737,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
84529 loff_t *ppos);
84530
84531
84532+static inline bool perf_paranoid_any(void)
84533+{
84534+ return sysctl_perf_event_legitimately_concerned > 2;
84535+}
84536+
84537 static inline bool perf_paranoid_tracepoint_raw(void)
84538 {
84539- return sysctl_perf_event_paranoid > -1;
84540+ return sysctl_perf_event_legitimately_concerned > -1;
84541 }
84542
84543 static inline bool perf_paranoid_cpu(void)
84544 {
84545- return sysctl_perf_event_paranoid > 0;
84546+ return sysctl_perf_event_legitimately_concerned > 0;
84547 }
84548
84549 static inline bool perf_paranoid_kernel(void)
84550 {
84551- return sysctl_perf_event_paranoid > 1;
84552+ return sysctl_perf_event_legitimately_concerned > 1;
84553 }
84554
84555 extern void perf_event_init(void);
84556@@ -880,7 +885,7 @@ struct perf_pmu_events_attr {
84557 struct device_attribute attr;
84558 u64 id;
84559 const char *event_str;
84560-};
84561+} __do_const;
84562
84563 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
84564 static struct perf_pmu_events_attr _var = { \
84565diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
84566index 1997ffc..4f1f44d 100644
84567--- a/include/linux/pid_namespace.h
84568+++ b/include/linux/pid_namespace.h
84569@@ -44,7 +44,7 @@ struct pid_namespace {
84570 int hide_pid;
84571 int reboot; /* group exit code if this pidns was rebooted */
84572 unsigned int proc_inum;
84573-};
84574+} __randomize_layout;
84575
84576 extern struct pid_namespace init_pid_ns;
84577
84578diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
84579index eb8b8ac..62649e1 100644
84580--- a/include/linux/pipe_fs_i.h
84581+++ b/include/linux/pipe_fs_i.h
84582@@ -47,10 +47,10 @@ struct pipe_inode_info {
84583 struct mutex mutex;
84584 wait_queue_head_t wait;
84585 unsigned int nrbufs, curbuf, buffers;
84586- unsigned int readers;
84587- unsigned int writers;
84588- unsigned int files;
84589- unsigned int waiting_writers;
84590+ atomic_t readers;
84591+ atomic_t writers;
84592+ atomic_t files;
84593+ atomic_t waiting_writers;
84594 unsigned int r_counter;
84595 unsigned int w_counter;
84596 struct page *tmp_page;
84597diff --git a/include/linux/pm.h b/include/linux/pm.h
84598index 72c0fe0..26918ed 100644
84599--- a/include/linux/pm.h
84600+++ b/include/linux/pm.h
84601@@ -620,6 +620,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
84602 struct dev_pm_domain {
84603 struct dev_pm_ops ops;
84604 };
84605+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
84606
84607 /*
84608 * The PM_EVENT_ messages are also used by drivers implementing the legacy
84609diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
84610index ebc4c76..7fab7b0 100644
84611--- a/include/linux/pm_domain.h
84612+++ b/include/linux/pm_domain.h
84613@@ -44,11 +44,11 @@ struct gpd_dev_ops {
84614 int (*thaw_early)(struct device *dev);
84615 int (*thaw)(struct device *dev);
84616 bool (*active_wakeup)(struct device *dev);
84617-};
84618+} __no_const;
84619
84620 struct gpd_cpu_data {
84621 unsigned int saved_exit_latency;
84622- struct cpuidle_state *idle_state;
84623+ cpuidle_state_no_const *idle_state;
84624 };
84625
84626 struct generic_pm_domain {
84627diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
84628index 367f49b..d2f5a14 100644
84629--- a/include/linux/pm_runtime.h
84630+++ b/include/linux/pm_runtime.h
84631@@ -125,7 +125,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
84632
84633 static inline void pm_runtime_mark_last_busy(struct device *dev)
84634 {
84635- ACCESS_ONCE(dev->power.last_busy) = jiffies;
84636+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
84637 }
84638
84639 #else /* !CONFIG_PM_RUNTIME */
84640diff --git a/include/linux/pnp.h b/include/linux/pnp.h
84641index 195aafc..49a7bc2 100644
84642--- a/include/linux/pnp.h
84643+++ b/include/linux/pnp.h
84644@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
84645 struct pnp_fixup {
84646 char id[7];
84647 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
84648-};
84649+} __do_const;
84650
84651 /* config parameters */
84652 #define PNP_CONFIG_NORMAL 0x0001
84653diff --git a/include/linux/poison.h b/include/linux/poison.h
84654index 2110a81..13a11bb 100644
84655--- a/include/linux/poison.h
84656+++ b/include/linux/poison.h
84657@@ -19,8 +19,8 @@
84658 * under normal circumstances, used to verify that nobody uses
84659 * non-initialized list entries.
84660 */
84661-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
84662-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
84663+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
84664+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
84665
84666 /********** include/linux/timer.h **********/
84667 /*
84668diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
84669index d8b187c3..9a9257a 100644
84670--- a/include/linux/power/smartreflex.h
84671+++ b/include/linux/power/smartreflex.h
84672@@ -238,7 +238,7 @@ struct omap_sr_class_data {
84673 int (*notify)(struct omap_sr *sr, u32 status);
84674 u8 notify_flags;
84675 u8 class_type;
84676-};
84677+} __do_const;
84678
84679 /**
84680 * struct omap_sr_nvalue_table - Smartreflex n-target value info
84681diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
84682index 4ea1d37..80f4b33 100644
84683--- a/include/linux/ppp-comp.h
84684+++ b/include/linux/ppp-comp.h
84685@@ -84,7 +84,7 @@ struct compressor {
84686 struct module *owner;
84687 /* Extra skb space needed by the compressor algorithm */
84688 unsigned int comp_extra;
84689-};
84690+} __do_const;
84691
84692 /*
84693 * The return value from decompress routine is the length of the
84694diff --git a/include/linux/preempt.h b/include/linux/preempt.h
84695index de83b4e..c4b997d 100644
84696--- a/include/linux/preempt.h
84697+++ b/include/linux/preempt.h
84698@@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
84699 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
84700 #endif
84701
84702+#define raw_preempt_count_add(val) __preempt_count_add(val)
84703+#define raw_preempt_count_sub(val) __preempt_count_sub(val)
84704+
84705 #define __preempt_count_inc() __preempt_count_add(1)
84706 #define __preempt_count_dec() __preempt_count_sub(1)
84707
84708 #define preempt_count_inc() preempt_count_add(1)
84709+#define raw_preempt_count_inc() raw_preempt_count_add(1)
84710 #define preempt_count_dec() preempt_count_sub(1)
84711+#define raw_preempt_count_dec() raw_preempt_count_sub(1)
84712
84713 #ifdef CONFIG_PREEMPT_COUNT
84714
84715@@ -41,6 +46,12 @@ do { \
84716 barrier(); \
84717 } while (0)
84718
84719+#define raw_preempt_disable() \
84720+do { \
84721+ raw_preempt_count_inc(); \
84722+ barrier(); \
84723+} while (0)
84724+
84725 #define sched_preempt_enable_no_resched() \
84726 do { \
84727 barrier(); \
84728@@ -49,6 +60,12 @@ do { \
84729
84730 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
84731
84732+#define raw_preempt_enable_no_resched() \
84733+do { \
84734+ barrier(); \
84735+ raw_preempt_count_dec(); \
84736+} while (0)
84737+
84738 #ifdef CONFIG_PREEMPT
84739 #define preempt_enable() \
84740 do { \
84741@@ -113,8 +130,10 @@ do { \
84742 * region.
84743 */
84744 #define preempt_disable() barrier()
84745+#define raw_preempt_disable() barrier()
84746 #define sched_preempt_enable_no_resched() barrier()
84747 #define preempt_enable_no_resched() barrier()
84748+#define raw_preempt_enable_no_resched() barrier()
84749 #define preempt_enable() barrier()
84750 #define preempt_check_resched() do { } while (0)
84751
84752@@ -128,11 +147,13 @@ do { \
84753 /*
84754 * Modules have no business playing preemption tricks.
84755 */
84756+#ifndef CONFIG_PAX_KERNEXEC
84757 #undef sched_preempt_enable_no_resched
84758 #undef preempt_enable_no_resched
84759 #undef preempt_enable_no_resched_notrace
84760 #undef preempt_check_resched
84761 #endif
84762+#endif
84763
84764 #define preempt_set_need_resched() \
84765 do { \
84766diff --git a/include/linux/printk.h b/include/linux/printk.h
84767index d78125f..7f36596 100644
84768--- a/include/linux/printk.h
84769+++ b/include/linux/printk.h
84770@@ -124,6 +124,8 @@ static inline __printf(1, 2) __cold
84771 void early_printk(const char *s, ...) { }
84772 #endif
84773
84774+extern int kptr_restrict;
84775+
84776 #ifdef CONFIG_PRINTK
84777 asmlinkage __printf(5, 0)
84778 int vprintk_emit(int facility, int level,
84779@@ -158,7 +160,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
84780
84781 extern int printk_delay_msec;
84782 extern int dmesg_restrict;
84783-extern int kptr_restrict;
84784
84785 extern void wake_up_klogd(void);
84786
84787diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
84788index 9d117f6..d832b31 100644
84789--- a/include/linux/proc_fs.h
84790+++ b/include/linux/proc_fs.h
84791@@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
84792 extern struct proc_dir_entry *proc_symlink(const char *,
84793 struct proc_dir_entry *, const char *);
84794 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
84795+extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
84796 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
84797 struct proc_dir_entry *, void *);
84798+extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
84799+ struct proc_dir_entry *, void *);
84800 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
84801 struct proc_dir_entry *);
84802
84803@@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
84804 return proc_create_data(name, mode, parent, proc_fops, NULL);
84805 }
84806
84807+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
84808+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
84809+{
84810+#ifdef CONFIG_GRKERNSEC_PROC_USER
84811+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
84812+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84813+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
84814+#else
84815+ return proc_create_data(name, mode, parent, proc_fops, NULL);
84816+#endif
84817+}
84818+
84819+
84820 extern void proc_set_size(struct proc_dir_entry *, loff_t);
84821 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
84822 extern void *PDE_DATA(const struct inode *);
84823@@ -56,8 +72,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
84824 struct proc_dir_entry *parent,const char *dest) { return NULL;}
84825 static inline struct proc_dir_entry *proc_mkdir(const char *name,
84826 struct proc_dir_entry *parent) {return NULL;}
84827+static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
84828+ struct proc_dir_entry *parent) { return NULL; }
84829 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
84830 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84831+static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
84832+ umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84833 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
84834 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
84835 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
84836@@ -77,7 +97,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
84837 static inline struct proc_dir_entry *proc_net_mkdir(
84838 struct net *net, const char *name, struct proc_dir_entry *parent)
84839 {
84840- return proc_mkdir_data(name, 0, parent, net);
84841+ return proc_mkdir_data_restrict(name, 0, parent, net);
84842 }
84843
84844 #endif /* _LINUX_PROC_FS_H */
84845diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
84846index 34a1e10..70f6bde 100644
84847--- a/include/linux/proc_ns.h
84848+++ b/include/linux/proc_ns.h
84849@@ -14,7 +14,7 @@ struct proc_ns_operations {
84850 void (*put)(void *ns);
84851 int (*install)(struct nsproxy *nsproxy, void *ns);
84852 unsigned int (*inum)(void *ns);
84853-};
84854+} __do_const __randomize_layout;
84855
84856 struct proc_ns {
84857 void *ns;
84858diff --git a/include/linux/quota.h b/include/linux/quota.h
84859index 80d345a..9e89a9a 100644
84860--- a/include/linux/quota.h
84861+++ b/include/linux/quota.h
84862@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
84863
84864 extern bool qid_eq(struct kqid left, struct kqid right);
84865 extern bool qid_lt(struct kqid left, struct kqid right);
84866-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
84867+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
84868 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
84869 extern bool qid_valid(struct kqid qid);
84870
84871diff --git a/include/linux/random.h b/include/linux/random.h
84872index 57fbbff..2170304 100644
84873--- a/include/linux/random.h
84874+++ b/include/linux/random.h
84875@@ -9,9 +9,19 @@
84876 #include <uapi/linux/random.h>
84877
84878 extern void add_device_randomness(const void *, unsigned int);
84879+
84880+static inline void add_latent_entropy(void)
84881+{
84882+
84883+#ifdef LATENT_ENTROPY_PLUGIN
84884+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
84885+#endif
84886+
84887+}
84888+
84889 extern void add_input_randomness(unsigned int type, unsigned int code,
84890- unsigned int value);
84891-extern void add_interrupt_randomness(int irq, int irq_flags);
84892+ unsigned int value) __latent_entropy;
84893+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
84894
84895 extern void get_random_bytes(void *buf, int nbytes);
84896 extern void get_random_bytes_arch(void *buf, int nbytes);
84897@@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
84898 extern const struct file_operations random_fops, urandom_fops;
84899 #endif
84900
84901-unsigned int get_random_int(void);
84902+unsigned int __intentional_overflow(-1) get_random_int(void);
84903 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
84904
84905-u32 prandom_u32(void);
84906+u32 prandom_u32(void) __intentional_overflow(-1);
84907 void prandom_bytes(void *buf, int nbytes);
84908 void prandom_seed(u32 seed);
84909 void prandom_reseed_late(void);
84910@@ -37,6 +47,11 @@ struct rnd_state {
84911 u32 prandom_u32_state(struct rnd_state *state);
84912 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
84913
84914+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
84915+{
84916+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
84917+}
84918+
84919 /**
84920 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
84921 * @ep_ro: right open interval endpoint
84922@@ -49,7 +64,7 @@ void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
84923 *
84924 * Returns: pseudo-random number in interval [0, ep_ro)
84925 */
84926-static inline u32 prandom_u32_max(u32 ep_ro)
84927+static inline u32 __intentional_overflow(-1) prandom_u32_max(u32 ep_ro)
84928 {
84929 return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
84930 }
84931diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
84932index fea49b5..2ac22bb 100644
84933--- a/include/linux/rbtree_augmented.h
84934+++ b/include/linux/rbtree_augmented.h
84935@@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
84936 old->rbaugmented = rbcompute(old); \
84937 } \
84938 rbstatic const struct rb_augment_callbacks rbname = { \
84939- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
84940+ .propagate = rbname ## _propagate, \
84941+ .copy = rbname ## _copy, \
84942+ .rotate = rbname ## _rotate \
84943 };
84944
84945
84946diff --git a/include/linux/rculist.h b/include/linux/rculist.h
84947index 372ad5e..d4373f8 100644
84948--- a/include/linux/rculist.h
84949+++ b/include/linux/rculist.h
84950@@ -29,8 +29,8 @@
84951 */
84952 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
84953 {
84954- ACCESS_ONCE(list->next) = list;
84955- ACCESS_ONCE(list->prev) = list;
84956+ ACCESS_ONCE_RW(list->next) = list;
84957+ ACCESS_ONCE_RW(list->prev) = list;
84958 }
84959
84960 /*
84961@@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
84962 struct list_head *prev, struct list_head *next);
84963 #endif
84964
84965+void __pax_list_add_rcu(struct list_head *new,
84966+ struct list_head *prev, struct list_head *next);
84967+
84968 /**
84969 * list_add_rcu - add a new entry to rcu-protected list
84970 * @new: new entry to be added
84971@@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
84972 __list_add_rcu(new, head, head->next);
84973 }
84974
84975+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
84976+{
84977+ __pax_list_add_rcu(new, head, head->next);
84978+}
84979+
84980 /**
84981 * list_add_tail_rcu - add a new entry to rcu-protected list
84982 * @new: new entry to be added
84983@@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
84984 __list_add_rcu(new, head->prev, head);
84985 }
84986
84987+static inline void pax_list_add_tail_rcu(struct list_head *new,
84988+ struct list_head *head)
84989+{
84990+ __pax_list_add_rcu(new, head->prev, head);
84991+}
84992+
84993 /**
84994 * list_del_rcu - deletes entry from list without re-initialization
84995 * @entry: the element to delete from the list.
84996@@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
84997 entry->prev = LIST_POISON2;
84998 }
84999
85000+extern void pax_list_del_rcu(struct list_head *entry);
85001+
85002 /**
85003 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
85004 * @n: the element to delete from the hash list.
85005diff --git a/include/linux/reboot.h b/include/linux/reboot.h
85006index 48bf152..d38b785 100644
85007--- a/include/linux/reboot.h
85008+++ b/include/linux/reboot.h
85009@@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
85010 */
85011
85012 extern void migrate_to_reboot_cpu(void);
85013-extern void machine_restart(char *cmd);
85014-extern void machine_halt(void);
85015-extern void machine_power_off(void);
85016+extern void machine_restart(char *cmd) __noreturn;
85017+extern void machine_halt(void) __noreturn;
85018+extern void machine_power_off(void) __noreturn;
85019
85020 extern void machine_shutdown(void);
85021 struct pt_regs;
85022@@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
85023 */
85024
85025 extern void kernel_restart_prepare(char *cmd);
85026-extern void kernel_restart(char *cmd);
85027-extern void kernel_halt(void);
85028-extern void kernel_power_off(void);
85029+extern void kernel_restart(char *cmd) __noreturn;
85030+extern void kernel_halt(void) __noreturn;
85031+extern void kernel_power_off(void) __noreturn;
85032
85033 extern int C_A_D; /* for sysctl */
85034 void ctrl_alt_del(void);
85035@@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
85036 * Emergency restart, callable from an interrupt handler.
85037 */
85038
85039-extern void emergency_restart(void);
85040+extern void emergency_restart(void) __noreturn;
85041 #include <asm/emergency-restart.h>
85042
85043 #endif /* _LINUX_REBOOT_H */
85044diff --git a/include/linux/regset.h b/include/linux/regset.h
85045index 8e0c9fe..ac4d221 100644
85046--- a/include/linux/regset.h
85047+++ b/include/linux/regset.h
85048@@ -161,7 +161,8 @@ struct user_regset {
85049 unsigned int align;
85050 unsigned int bias;
85051 unsigned int core_note_type;
85052-};
85053+} __do_const;
85054+typedef struct user_regset __no_const user_regset_no_const;
85055
85056 /**
85057 * struct user_regset_view - available regsets
85058diff --git a/include/linux/relay.h b/include/linux/relay.h
85059index d7c8359..818daf5 100644
85060--- a/include/linux/relay.h
85061+++ b/include/linux/relay.h
85062@@ -157,7 +157,7 @@ struct rchan_callbacks
85063 * The callback should return 0 if successful, negative if not.
85064 */
85065 int (*remove_buf_file)(struct dentry *dentry);
85066-};
85067+} __no_const;
85068
85069 /*
85070 * CONFIG_RELAY kernel API, kernel/relay.c
85071diff --git a/include/linux/rio.h b/include/linux/rio.h
85072index 6bda06f..bf39a9b 100644
85073--- a/include/linux/rio.h
85074+++ b/include/linux/rio.h
85075@@ -358,7 +358,7 @@ struct rio_ops {
85076 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
85077 u64 rstart, u32 size, u32 flags);
85078 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
85079-};
85080+} __no_const;
85081
85082 #define RIO_RESOURCE_MEM 0x00000100
85083 #define RIO_RESOURCE_DOORBELL 0x00000200
85084diff --git a/include/linux/rmap.h b/include/linux/rmap.h
85085index be57450..31cf65e 100644
85086--- a/include/linux/rmap.h
85087+++ b/include/linux/rmap.h
85088@@ -144,8 +144,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
85089 void anon_vma_init(void); /* create anon_vma_cachep */
85090 int anon_vma_prepare(struct vm_area_struct *);
85091 void unlink_anon_vmas(struct vm_area_struct *);
85092-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
85093-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
85094+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
85095+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
85096
85097 static inline void anon_vma_merge(struct vm_area_struct *vma,
85098 struct vm_area_struct *next)
85099diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
85100index ed8f9e7..999bc96 100644
85101--- a/include/linux/scatterlist.h
85102+++ b/include/linux/scatterlist.h
85103@@ -1,6 +1,7 @@
85104 #ifndef _LINUX_SCATTERLIST_H
85105 #define _LINUX_SCATTERLIST_H
85106
85107+#include <linux/sched.h>
85108 #include <linux/string.h>
85109 #include <linux/bug.h>
85110 #include <linux/mm.h>
85111@@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
85112 #ifdef CONFIG_DEBUG_SG
85113 BUG_ON(!virt_addr_valid(buf));
85114 #endif
85115+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85116+ if (object_starts_on_stack(buf)) {
85117+ void *adjbuf = buf - current->stack + current->lowmem_stack;
85118+ sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
85119+ } else
85120+#endif
85121 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
85122 }
85123
85124diff --git a/include/linux/sched.h b/include/linux/sched.h
85125index 2b1d9e9..7fd5067 100644
85126--- a/include/linux/sched.h
85127+++ b/include/linux/sched.h
85128@@ -132,6 +132,7 @@ struct fs_struct;
85129 struct perf_event_context;
85130 struct blk_plug;
85131 struct filename;
85132+struct linux_binprm;
85133
85134 #define VMACACHE_BITS 2
85135 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
85136@@ -374,7 +375,7 @@ extern char __sched_text_start[], __sched_text_end[];
85137 extern int in_sched_functions(unsigned long addr);
85138
85139 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
85140-extern signed long schedule_timeout(signed long timeout);
85141+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
85142 extern signed long schedule_timeout_interruptible(signed long timeout);
85143 extern signed long schedule_timeout_killable(signed long timeout);
85144 extern signed long schedule_timeout_uninterruptible(signed long timeout);
85145@@ -385,6 +386,19 @@ struct nsproxy;
85146 struct user_namespace;
85147
85148 #ifdef CONFIG_MMU
85149+
85150+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
85151+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
85152+#else
85153+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
85154+{
85155+ return 0;
85156+}
85157+#endif
85158+
85159+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
85160+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
85161+
85162 extern void arch_pick_mmap_layout(struct mm_struct *mm);
85163 extern unsigned long
85164 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
85165@@ -682,6 +696,17 @@ struct signal_struct {
85166 #ifdef CONFIG_TASKSTATS
85167 struct taskstats *stats;
85168 #endif
85169+
85170+#ifdef CONFIG_GRKERNSEC
85171+ u32 curr_ip;
85172+ u32 saved_ip;
85173+ u32 gr_saddr;
85174+ u32 gr_daddr;
85175+ u16 gr_sport;
85176+ u16 gr_dport;
85177+ u8 used_accept:1;
85178+#endif
85179+
85180 #ifdef CONFIG_AUDIT
85181 unsigned audit_tty;
85182 unsigned audit_tty_log_passwd;
85183@@ -708,7 +733,7 @@ struct signal_struct {
85184 struct mutex cred_guard_mutex; /* guard against foreign influences on
85185 * credential calculations
85186 * (notably. ptrace) */
85187-};
85188+} __randomize_layout;
85189
85190 /*
85191 * Bits in flags field of signal_struct.
85192@@ -761,6 +786,14 @@ struct user_struct {
85193 struct key *session_keyring; /* UID's default session keyring */
85194 #endif
85195
85196+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
85197+ unsigned char kernel_banned;
85198+#endif
85199+#ifdef CONFIG_GRKERNSEC_BRUTE
85200+ unsigned char suid_banned;
85201+ unsigned long suid_ban_expires;
85202+#endif
85203+
85204 /* Hash table maintenance information */
85205 struct hlist_node uidhash_node;
85206 kuid_t uid;
85207@@ -768,7 +801,7 @@ struct user_struct {
85208 #ifdef CONFIG_PERF_EVENTS
85209 atomic_long_t locked_vm;
85210 #endif
85211-};
85212+} __randomize_layout;
85213
85214 extern int uids_sysfs_init(void);
85215
85216@@ -1224,6 +1257,9 @@ enum perf_event_task_context {
85217 struct task_struct {
85218 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
85219 void *stack;
85220+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85221+ void *lowmem_stack;
85222+#endif
85223 atomic_t usage;
85224 unsigned int flags; /* per process flags, defined below */
85225 unsigned int ptrace;
85226@@ -1345,8 +1381,8 @@ struct task_struct {
85227 struct list_head thread_node;
85228
85229 struct completion *vfork_done; /* for vfork() */
85230- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
85231- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
85232+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
85233+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
85234
85235 cputime_t utime, stime, utimescaled, stimescaled;
85236 cputime_t gtime;
85237@@ -1371,11 +1407,6 @@ struct task_struct {
85238 struct task_cputime cputime_expires;
85239 struct list_head cpu_timers[3];
85240
85241-/* process credentials */
85242- const struct cred __rcu *real_cred; /* objective and real subjective task
85243- * credentials (COW) */
85244- const struct cred __rcu *cred; /* effective (overridable) subjective task
85245- * credentials (COW) */
85246 char comm[TASK_COMM_LEN]; /* executable name excluding path
85247 - access with [gs]et_task_comm (which lock
85248 it with task_lock())
85249@@ -1393,6 +1424,10 @@ struct task_struct {
85250 #endif
85251 /* CPU-specific state of this task */
85252 struct thread_struct thread;
85253+/* thread_info moved to task_struct */
85254+#ifdef CONFIG_X86
85255+ struct thread_info tinfo;
85256+#endif
85257 /* filesystem information */
85258 struct fs_struct *fs;
85259 /* open file information */
85260@@ -1467,6 +1502,10 @@ struct task_struct {
85261 gfp_t lockdep_reclaim_gfp;
85262 #endif
85263
85264+/* process credentials */
85265+ const struct cred __rcu *real_cred; /* objective and real subjective task
85266+ * credentials (COW) */
85267+
85268 /* journalling filesystem info */
85269 void *journal_info;
85270
85271@@ -1505,6 +1544,10 @@ struct task_struct {
85272 /* cg_list protected by css_set_lock and tsk->alloc_lock */
85273 struct list_head cg_list;
85274 #endif
85275+
85276+ const struct cred __rcu *cred; /* effective (overridable) subjective task
85277+ * credentials (COW) */
85278+
85279 #ifdef CONFIG_FUTEX
85280 struct robust_list_head __user *robust_list;
85281 #ifdef CONFIG_COMPAT
85282@@ -1618,7 +1661,7 @@ struct task_struct {
85283 * Number of functions that haven't been traced
85284 * because of depth overrun.
85285 */
85286- atomic_t trace_overrun;
85287+ atomic_unchecked_t trace_overrun;
85288 /* Pause for the tracing */
85289 atomic_t tracing_graph_pause;
85290 #endif
85291@@ -1644,7 +1687,78 @@ struct task_struct {
85292 unsigned int sequential_io;
85293 unsigned int sequential_io_avg;
85294 #endif
85295-};
85296+
85297+#ifdef CONFIG_GRKERNSEC
85298+ /* grsecurity */
85299+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
85300+ u64 exec_id;
85301+#endif
85302+#ifdef CONFIG_GRKERNSEC_SETXID
85303+ const struct cred *delayed_cred;
85304+#endif
85305+ struct dentry *gr_chroot_dentry;
85306+ struct acl_subject_label *acl;
85307+ struct acl_subject_label *tmpacl;
85308+ struct acl_role_label *role;
85309+ struct file *exec_file;
85310+ unsigned long brute_expires;
85311+ u16 acl_role_id;
85312+ u8 inherited;
85313+ /* is this the task that authenticated to the special role */
85314+ u8 acl_sp_role;
85315+ u8 is_writable;
85316+ u8 brute;
85317+ u8 gr_is_chrooted;
85318+#endif
85319+
85320+} __randomize_layout;
85321+
85322+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
85323+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
85324+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
85325+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
85326+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
85327+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
85328+
85329+#ifdef CONFIG_PAX_SOFTMODE
85330+extern int pax_softmode;
85331+#endif
85332+
85333+extern int pax_check_flags(unsigned long *);
85334+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
85335+
85336+/* if tsk != current then task_lock must be held on it */
85337+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
85338+static inline unsigned long pax_get_flags(struct task_struct *tsk)
85339+{
85340+ if (likely(tsk->mm))
85341+ return tsk->mm->pax_flags;
85342+ else
85343+ return 0UL;
85344+}
85345+
85346+/* if tsk != current then task_lock must be held on it */
85347+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
85348+{
85349+ if (likely(tsk->mm)) {
85350+ tsk->mm->pax_flags = flags;
85351+ return 0;
85352+ }
85353+ return -EINVAL;
85354+}
85355+#endif
85356+
85357+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
85358+extern void pax_set_initial_flags(struct linux_binprm *bprm);
85359+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
85360+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
85361+#endif
85362+
85363+struct path;
85364+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
85365+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
85366+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
85367+extern void pax_report_refcount_overflow(struct pt_regs *regs);
85368
85369 /* Future-safe accessor for struct task_struct's cpus_allowed. */
85370 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
85371@@ -1726,7 +1840,7 @@ struct pid_namespace;
85372 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
85373 struct pid_namespace *ns);
85374
85375-static inline pid_t task_pid_nr(struct task_struct *tsk)
85376+static inline pid_t task_pid_nr(const struct task_struct *tsk)
85377 {
85378 return tsk->pid;
85379 }
85380@@ -2097,6 +2211,25 @@ extern u64 sched_clock_cpu(int cpu);
85381
85382 extern void sched_clock_init(void);
85383
85384+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85385+static inline void populate_stack(void)
85386+{
85387+ struct task_struct *curtask = current;
85388+ int c;
85389+ int *ptr = curtask->stack;
85390+ int *end = curtask->stack + THREAD_SIZE;
85391+
85392+ while (ptr < end) {
85393+ c = *(volatile int *)ptr;
85394+ ptr += PAGE_SIZE/sizeof(int);
85395+ }
85396+}
85397+#else
85398+static inline void populate_stack(void)
85399+{
85400+}
85401+#endif
85402+
85403 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
85404 static inline void sched_clock_tick(void)
85405 {
85406@@ -2230,7 +2363,9 @@ void yield(void);
85407 extern struct exec_domain default_exec_domain;
85408
85409 union thread_union {
85410+#ifndef CONFIG_X86
85411 struct thread_info thread_info;
85412+#endif
85413 unsigned long stack[THREAD_SIZE/sizeof(long)];
85414 };
85415
85416@@ -2263,6 +2398,7 @@ extern struct pid_namespace init_pid_ns;
85417 */
85418
85419 extern struct task_struct *find_task_by_vpid(pid_t nr);
85420+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
85421 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
85422 struct pid_namespace *ns);
85423
85424@@ -2427,7 +2563,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
85425 extern void exit_itimers(struct signal_struct *);
85426 extern void flush_itimer_signals(void);
85427
85428-extern void do_group_exit(int);
85429+extern __noreturn void do_group_exit(int);
85430
85431 extern int do_execve(struct filename *,
85432 const char __user * const __user *,
85433@@ -2642,9 +2778,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
85434
85435 #endif
85436
85437-static inline int object_is_on_stack(void *obj)
85438+static inline int object_starts_on_stack(const void *obj)
85439 {
85440- void *stack = task_stack_page(current);
85441+ const void *stack = task_stack_page(current);
85442
85443 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
85444 }
85445diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
85446index 596a0e0..bea77ec 100644
85447--- a/include/linux/sched/sysctl.h
85448+++ b/include/linux/sched/sysctl.h
85449@@ -34,6 +34,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
85450 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
85451
85452 extern int sysctl_max_map_count;
85453+extern unsigned long sysctl_heap_stack_gap;
85454
85455 extern unsigned int sysctl_sched_latency;
85456 extern unsigned int sysctl_sched_min_granularity;
85457diff --git a/include/linux/security.h b/include/linux/security.h
85458index 623f90e..90b39da 100644
85459--- a/include/linux/security.h
85460+++ b/include/linux/security.h
85461@@ -27,6 +27,7 @@
85462 #include <linux/slab.h>
85463 #include <linux/err.h>
85464 #include <linux/string.h>
85465+#include <linux/grsecurity.h>
85466
85467 struct linux_binprm;
85468 struct cred;
85469@@ -116,8 +117,6 @@ struct seq_file;
85470
85471 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
85472
85473-void reset_security_ops(void);
85474-
85475 #ifdef CONFIG_MMU
85476 extern unsigned long mmap_min_addr;
85477 extern unsigned long dac_mmap_min_addr;
85478@@ -1729,7 +1728,7 @@ struct security_operations {
85479 struct audit_context *actx);
85480 void (*audit_rule_free) (void *lsmrule);
85481 #endif /* CONFIG_AUDIT */
85482-};
85483+} __randomize_layout;
85484
85485 /* prototypes */
85486 extern int security_init(void);
85487diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
85488index dc368b8..e895209 100644
85489--- a/include/linux/semaphore.h
85490+++ b/include/linux/semaphore.h
85491@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
85492 }
85493
85494 extern void down(struct semaphore *sem);
85495-extern int __must_check down_interruptible(struct semaphore *sem);
85496+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
85497 extern int __must_check down_killable(struct semaphore *sem);
85498 extern int __must_check down_trylock(struct semaphore *sem);
85499 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
85500diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
85501index 52e0097..383f21d 100644
85502--- a/include/linux/seq_file.h
85503+++ b/include/linux/seq_file.h
85504@@ -27,6 +27,9 @@ struct seq_file {
85505 struct mutex lock;
85506 const struct seq_operations *op;
85507 int poll_event;
85508+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
85509+ u64 exec_id;
85510+#endif
85511 #ifdef CONFIG_USER_NS
85512 struct user_namespace *user_ns;
85513 #endif
85514@@ -39,6 +42,7 @@ struct seq_operations {
85515 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
85516 int (*show) (struct seq_file *m, void *v);
85517 };
85518+typedef struct seq_operations __no_const seq_operations_no_const;
85519
85520 #define SEQ_SKIP 1
85521
85522@@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
85523
85524 char *mangle_path(char *s, const char *p, const char *esc);
85525 int seq_open(struct file *, const struct seq_operations *);
85526+int seq_open_restrict(struct file *, const struct seq_operations *);
85527 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
85528 loff_t seq_lseek(struct file *, loff_t, int);
85529 int seq_release(struct inode *, struct file *);
85530@@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
85531 }
85532
85533 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
85534+int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
85535 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
85536 int single_release(struct inode *, struct file *);
85537 void *__seq_open_private(struct file *, const struct seq_operations *, int);
85538diff --git a/include/linux/shm.h b/include/linux/shm.h
85539index 6fb8016..ab4465e 100644
85540--- a/include/linux/shm.h
85541+++ b/include/linux/shm.h
85542@@ -22,6 +22,10 @@ struct shmid_kernel /* private to the kernel */
85543 /* The task created the shm object. NULL if the task is dead. */
85544 struct task_struct *shm_creator;
85545 struct list_head shm_clist; /* list by creator */
85546+#ifdef CONFIG_GRKERNSEC
85547+ u64 shm_createtime;
85548+ pid_t shm_lapid;
85549+#endif
85550 };
85551
85552 /* shm_mode upper byte flags */
85553diff --git a/include/linux/signal.h b/include/linux/signal.h
85554index 750196f..ae7a3a4 100644
85555--- a/include/linux/signal.h
85556+++ b/include/linux/signal.h
85557@@ -292,7 +292,7 @@ static inline void allow_signal(int sig)
85558 * know it'll be handled, so that they don't get converted to
85559 * SIGKILL or just silently dropped.
85560 */
85561- kernel_sigaction(sig, (__force __sighandler_t)2);
85562+ kernel_sigaction(sig, (__force_user __sighandler_t)2);
85563 }
85564
85565 static inline void disallow_signal(int sig)
85566diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
85567index abde271..bc9ece1 100644
85568--- a/include/linux/skbuff.h
85569+++ b/include/linux/skbuff.h
85570@@ -728,7 +728,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
85571 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
85572 int node);
85573 struct sk_buff *build_skb(void *data, unsigned int frag_size);
85574-static inline struct sk_buff *alloc_skb(unsigned int size,
85575+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
85576 gfp_t priority)
85577 {
85578 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
85579@@ -1845,7 +1845,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
85580 return skb->inner_transport_header - skb->inner_network_header;
85581 }
85582
85583-static inline int skb_network_offset(const struct sk_buff *skb)
85584+static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
85585 {
85586 return skb_network_header(skb) - skb->data;
85587 }
85588@@ -1917,7 +1917,7 @@ static inline void skb_pop_rcv_encapsulation(struct sk_buff *skb)
85589 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
85590 */
85591 #ifndef NET_SKB_PAD
85592-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
85593+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
85594 #endif
85595
85596 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
85597@@ -2524,7 +2524,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
85598 int *err);
85599 unsigned int datagram_poll(struct file *file, struct socket *sock,
85600 struct poll_table_struct *wait);
85601-int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85602+int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85603 struct iovec *to, int size);
85604 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
85605 struct iovec *iov);
85606@@ -2918,6 +2918,9 @@ static inline void nf_reset(struct sk_buff *skb)
85607 nf_bridge_put(skb->nf_bridge);
85608 skb->nf_bridge = NULL;
85609 #endif
85610+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
85611+ skb->nf_trace = 0;
85612+#endif
85613 }
85614
85615 static inline void nf_reset_trace(struct sk_buff *skb)
85616diff --git a/include/linux/slab.h b/include/linux/slab.h
85617index 1d9abb7..b1e8b10 100644
85618--- a/include/linux/slab.h
85619+++ b/include/linux/slab.h
85620@@ -14,15 +14,29 @@
85621 #include <linux/gfp.h>
85622 #include <linux/types.h>
85623 #include <linux/workqueue.h>
85624-
85625+#include <linux/err.h>
85626
85627 /*
85628 * Flags to pass to kmem_cache_create().
85629 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
85630 */
85631 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
85632+
85633+#ifdef CONFIG_PAX_USERCOPY_SLABS
85634+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
85635+#else
85636+#define SLAB_USERCOPY 0x00000000UL
85637+#endif
85638+
85639 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
85640 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
85641+
85642+#ifdef CONFIG_PAX_MEMORY_SANITIZE
85643+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
85644+#else
85645+#define SLAB_NO_SANITIZE 0x00000000UL
85646+#endif
85647+
85648 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
85649 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
85650 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
85651@@ -98,10 +112,13 @@
85652 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
85653 * Both make kfree a no-op.
85654 */
85655-#define ZERO_SIZE_PTR ((void *)16)
85656+#define ZERO_SIZE_PTR \
85657+({ \
85658+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
85659+ (void *)(-MAX_ERRNO-1L); \
85660+})
85661
85662-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
85663- (unsigned long)ZERO_SIZE_PTR)
85664+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
85665
85666 #include <linux/kmemleak.h>
85667
85668@@ -144,6 +161,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
85669 void kfree(const void *);
85670 void kzfree(const void *);
85671 size_t ksize(const void *);
85672+const char *check_heap_object(const void *ptr, unsigned long n);
85673+bool is_usercopy_object(const void *ptr);
85674
85675 /*
85676 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
85677@@ -176,7 +195,7 @@ struct kmem_cache {
85678 unsigned int align; /* Alignment as calculated */
85679 unsigned long flags; /* Active flags on the slab */
85680 const char *name; /* Slab name for sysfs */
85681- int refcount; /* Use counter */
85682+ atomic_t refcount; /* Use counter */
85683 void (*ctor)(void *); /* Called on object slot creation */
85684 struct list_head list; /* List of all slab caches on the system */
85685 };
85686@@ -261,6 +280,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
85687 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85688 #endif
85689
85690+#ifdef CONFIG_PAX_USERCOPY_SLABS
85691+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
85692+#endif
85693+
85694 /*
85695 * Figure out which kmalloc slab an allocation of a certain size
85696 * belongs to.
85697@@ -269,7 +292,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85698 * 2 = 120 .. 192 bytes
85699 * n = 2^(n-1) .. 2^n -1
85700 */
85701-static __always_inline int kmalloc_index(size_t size)
85702+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
85703 {
85704 if (!size)
85705 return 0;
85706@@ -312,11 +335,11 @@ static __always_inline int kmalloc_index(size_t size)
85707 }
85708 #endif /* !CONFIG_SLOB */
85709
85710-void *__kmalloc(size_t size, gfp_t flags);
85711+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
85712 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
85713
85714 #ifdef CONFIG_NUMA
85715-void *__kmalloc_node(size_t size, gfp_t flags, int node);
85716+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
85717 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
85718 #else
85719 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
85720diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
85721index 8235dfb..47ce586 100644
85722--- a/include/linux/slab_def.h
85723+++ b/include/linux/slab_def.h
85724@@ -38,7 +38,7 @@ struct kmem_cache {
85725 /* 4) cache creation/removal */
85726 const char *name;
85727 struct list_head list;
85728- int refcount;
85729+ atomic_t refcount;
85730 int object_size;
85731 int align;
85732
85733@@ -54,10 +54,14 @@ struct kmem_cache {
85734 unsigned long node_allocs;
85735 unsigned long node_frees;
85736 unsigned long node_overflow;
85737- atomic_t allochit;
85738- atomic_t allocmiss;
85739- atomic_t freehit;
85740- atomic_t freemiss;
85741+ atomic_unchecked_t allochit;
85742+ atomic_unchecked_t allocmiss;
85743+ atomic_unchecked_t freehit;
85744+ atomic_unchecked_t freemiss;
85745+#ifdef CONFIG_PAX_MEMORY_SANITIZE
85746+ atomic_unchecked_t sanitized;
85747+ atomic_unchecked_t not_sanitized;
85748+#endif
85749
85750 /*
85751 * If debugging is enabled, then the allocator can add additional
85752diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
85753index d82abd4..408c3a0 100644
85754--- a/include/linux/slub_def.h
85755+++ b/include/linux/slub_def.h
85756@@ -74,7 +74,7 @@ struct kmem_cache {
85757 struct kmem_cache_order_objects max;
85758 struct kmem_cache_order_objects min;
85759 gfp_t allocflags; /* gfp flags to use on each alloc */
85760- int refcount; /* Refcount for slab cache destroy */
85761+ atomic_t refcount; /* Refcount for slab cache destroy */
85762 void (*ctor)(void *);
85763 int inuse; /* Offset to metadata */
85764 int align; /* Alignment */
85765diff --git a/include/linux/smp.h b/include/linux/smp.h
85766index 34347f2..8739978 100644
85767--- a/include/linux/smp.h
85768+++ b/include/linux/smp.h
85769@@ -174,7 +174,9 @@ static inline void kick_all_cpus_sync(void) { }
85770 #endif
85771
85772 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
85773+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
85774 #define put_cpu() preempt_enable()
85775+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
85776
85777 /*
85778 * Callback to arch code if there's nosmp or maxcpus=0 on the
85779diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
85780index 46cca4c..3323536 100644
85781--- a/include/linux/sock_diag.h
85782+++ b/include/linux/sock_diag.h
85783@@ -11,7 +11,7 @@ struct sock;
85784 struct sock_diag_handler {
85785 __u8 family;
85786 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
85787-};
85788+} __do_const;
85789
85790 int sock_diag_register(const struct sock_diag_handler *h);
85791 void sock_diag_unregister(const struct sock_diag_handler *h);
85792diff --git a/include/linux/sonet.h b/include/linux/sonet.h
85793index 680f9a3..f13aeb0 100644
85794--- a/include/linux/sonet.h
85795+++ b/include/linux/sonet.h
85796@@ -7,7 +7,7 @@
85797 #include <uapi/linux/sonet.h>
85798
85799 struct k_sonet_stats {
85800-#define __HANDLE_ITEM(i) atomic_t i
85801+#define __HANDLE_ITEM(i) atomic_unchecked_t i
85802 __SONET_ITEMS
85803 #undef __HANDLE_ITEM
85804 };
85805diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
85806index 07d8e53..dc934c9 100644
85807--- a/include/linux/sunrpc/addr.h
85808+++ b/include/linux/sunrpc/addr.h
85809@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
85810 {
85811 switch (sap->sa_family) {
85812 case AF_INET:
85813- return ntohs(((struct sockaddr_in *)sap)->sin_port);
85814+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
85815 case AF_INET6:
85816- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
85817+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
85818 }
85819 return 0;
85820 }
85821@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
85822 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
85823 const struct sockaddr *src)
85824 {
85825- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
85826+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
85827 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
85828
85829 dsin->sin_family = ssin->sin_family;
85830@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
85831 if (sa->sa_family != AF_INET6)
85832 return 0;
85833
85834- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
85835+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
85836 }
85837
85838 #endif /* _LINUX_SUNRPC_ADDR_H */
85839diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
85840index 70736b9..37f33db 100644
85841--- a/include/linux/sunrpc/clnt.h
85842+++ b/include/linux/sunrpc/clnt.h
85843@@ -97,7 +97,7 @@ struct rpc_procinfo {
85844 unsigned int p_timer; /* Which RTT timer to use */
85845 u32 p_statidx; /* Which procedure to account */
85846 const char * p_name; /* name of procedure */
85847-};
85848+} __do_const;
85849
85850 #ifdef __KERNEL__
85851
85852diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
85853index cf61ecd..a4a9bc0 100644
85854--- a/include/linux/sunrpc/svc.h
85855+++ b/include/linux/sunrpc/svc.h
85856@@ -417,7 +417,7 @@ struct svc_procedure {
85857 unsigned int pc_count; /* call count */
85858 unsigned int pc_cachetype; /* cache info (NFS) */
85859 unsigned int pc_xdrressize; /* maximum size of XDR reply */
85860-};
85861+} __do_const;
85862
85863 /*
85864 * Function prototypes.
85865diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
85866index 975da75..318c083 100644
85867--- a/include/linux/sunrpc/svc_rdma.h
85868+++ b/include/linux/sunrpc/svc_rdma.h
85869@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
85870 extern unsigned int svcrdma_max_requests;
85871 extern unsigned int svcrdma_max_req_size;
85872
85873-extern atomic_t rdma_stat_recv;
85874-extern atomic_t rdma_stat_read;
85875-extern atomic_t rdma_stat_write;
85876-extern atomic_t rdma_stat_sq_starve;
85877-extern atomic_t rdma_stat_rq_starve;
85878-extern atomic_t rdma_stat_rq_poll;
85879-extern atomic_t rdma_stat_rq_prod;
85880-extern atomic_t rdma_stat_sq_poll;
85881-extern atomic_t rdma_stat_sq_prod;
85882+extern atomic_unchecked_t rdma_stat_recv;
85883+extern atomic_unchecked_t rdma_stat_read;
85884+extern atomic_unchecked_t rdma_stat_write;
85885+extern atomic_unchecked_t rdma_stat_sq_starve;
85886+extern atomic_unchecked_t rdma_stat_rq_starve;
85887+extern atomic_unchecked_t rdma_stat_rq_poll;
85888+extern atomic_unchecked_t rdma_stat_rq_prod;
85889+extern atomic_unchecked_t rdma_stat_sq_poll;
85890+extern atomic_unchecked_t rdma_stat_sq_prod;
85891
85892 #define RPCRDMA_VERSION 1
85893
85894diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
85895index 8d71d65..f79586e 100644
85896--- a/include/linux/sunrpc/svcauth.h
85897+++ b/include/linux/sunrpc/svcauth.h
85898@@ -120,7 +120,7 @@ struct auth_ops {
85899 int (*release)(struct svc_rqst *rq);
85900 void (*domain_release)(struct auth_domain *);
85901 int (*set_client)(struct svc_rqst *rq);
85902-};
85903+} __do_const;
85904
85905 #define SVC_GARBAGE 1
85906 #define SVC_SYSERR 2
85907diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
85908index e7a018e..49f8b17 100644
85909--- a/include/linux/swiotlb.h
85910+++ b/include/linux/swiotlb.h
85911@@ -60,7 +60,8 @@ extern void
85912
85913 extern void
85914 swiotlb_free_coherent(struct device *hwdev, size_t size,
85915- void *vaddr, dma_addr_t dma_handle);
85916+ void *vaddr, dma_addr_t dma_handle,
85917+ struct dma_attrs *attrs);
85918
85919 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
85920 unsigned long offset, size_t size,
85921diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
85922index 0f86d85..dff3419 100644
85923--- a/include/linux/syscalls.h
85924+++ b/include/linux/syscalls.h
85925@@ -98,10 +98,16 @@ struct sigaltstack;
85926 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
85927
85928 #define __SC_DECL(t, a) t a
85929+#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))
85930 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
85931 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
85932 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
85933-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
85934+#define __SC_LONG(t, a) __typeof( \
85935+ __builtin_choose_expr( \
85936+ sizeof(t) > sizeof(int), \
85937+ (t) 0, \
85938+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
85939+ )) a
85940 #define __SC_CAST(t, a) (t) a
85941 #define __SC_ARGS(t, a) a
85942 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
85943@@ -383,11 +389,11 @@ asmlinkage long sys_sync(void);
85944 asmlinkage long sys_fsync(unsigned int fd);
85945 asmlinkage long sys_fdatasync(unsigned int fd);
85946 asmlinkage long sys_bdflush(int func, long data);
85947-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
85948- char __user *type, unsigned long flags,
85949+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
85950+ const char __user *type, unsigned long flags,
85951 void __user *data);
85952-asmlinkage long sys_umount(char __user *name, int flags);
85953-asmlinkage long sys_oldumount(char __user *name);
85954+asmlinkage long sys_umount(const char __user *name, int flags);
85955+asmlinkage long sys_oldumount(const char __user *name);
85956 asmlinkage long sys_truncate(const char __user *path, long length);
85957 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
85958 asmlinkage long sys_stat(const char __user *filename,
85959@@ -599,7 +605,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
85960 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
85961 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
85962 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
85963- struct sockaddr __user *, int);
85964+ struct sockaddr __user *, int) __intentional_overflow(0);
85965 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
85966 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
85967 unsigned int vlen, unsigned flags);
85968diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
85969index 27b3b0b..e093dd9 100644
85970--- a/include/linux/syscore_ops.h
85971+++ b/include/linux/syscore_ops.h
85972@@ -16,7 +16,7 @@ struct syscore_ops {
85973 int (*suspend)(void);
85974 void (*resume)(void);
85975 void (*shutdown)(void);
85976-};
85977+} __do_const;
85978
85979 extern void register_syscore_ops(struct syscore_ops *ops);
85980 extern void unregister_syscore_ops(struct syscore_ops *ops);
85981diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
85982index b7361f8..341a15a 100644
85983--- a/include/linux/sysctl.h
85984+++ b/include/linux/sysctl.h
85985@@ -39,6 +39,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
85986
85987 extern int proc_dostring(struct ctl_table *, int,
85988 void __user *, size_t *, loff_t *);
85989+extern int proc_dostring_modpriv(struct ctl_table *, int,
85990+ void __user *, size_t *, loff_t *);
85991 extern int proc_dointvec(struct ctl_table *, int,
85992 void __user *, size_t *, loff_t *);
85993 extern int proc_dointvec_minmax(struct ctl_table *, int,
85994@@ -113,7 +115,8 @@ struct ctl_table
85995 struct ctl_table_poll *poll;
85996 void *extra1;
85997 void *extra2;
85998-};
85999+} __do_const __randomize_layout;
86000+typedef struct ctl_table __no_const ctl_table_no_const;
86001
86002 struct ctl_node {
86003 struct rb_node node;
86004diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
86005index f97d0db..c1187dc 100644
86006--- a/include/linux/sysfs.h
86007+++ b/include/linux/sysfs.h
86008@@ -34,7 +34,8 @@ struct attribute {
86009 struct lock_class_key *key;
86010 struct lock_class_key skey;
86011 #endif
86012-};
86013+} __do_const;
86014+typedef struct attribute __no_const attribute_no_const;
86015
86016 /**
86017 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
86018@@ -63,7 +64,8 @@ struct attribute_group {
86019 struct attribute *, int);
86020 struct attribute **attrs;
86021 struct bin_attribute **bin_attrs;
86022-};
86023+} __do_const;
86024+typedef struct attribute_group __no_const attribute_group_no_const;
86025
86026 /**
86027 * Use these macros to make defining attributes easier. See include/linux/device.h
86028@@ -128,7 +130,8 @@ struct bin_attribute {
86029 char *, loff_t, size_t);
86030 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
86031 struct vm_area_struct *vma);
86032-};
86033+} __do_const;
86034+typedef struct bin_attribute __no_const bin_attribute_no_const;
86035
86036 /**
86037 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
86038diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
86039index 387fa7d..3fcde6b 100644
86040--- a/include/linux/sysrq.h
86041+++ b/include/linux/sysrq.h
86042@@ -16,6 +16,7 @@
86043
86044 #include <linux/errno.h>
86045 #include <linux/types.h>
86046+#include <linux/compiler.h>
86047
86048 /* Possible values of bitmask for enabling sysrq functions */
86049 /* 0x0001 is reserved for enable everything */
86050@@ -33,7 +34,7 @@ struct sysrq_key_op {
86051 char *help_msg;
86052 char *action_msg;
86053 int enable_mask;
86054-};
86055+} __do_const;
86056
86057 #ifdef CONFIG_MAGIC_SYSRQ
86058
86059diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
86060index ff307b5..f1a4468 100644
86061--- a/include/linux/thread_info.h
86062+++ b/include/linux/thread_info.h
86063@@ -145,6 +145,13 @@ static inline bool test_and_clear_restore_sigmask(void)
86064 #error "no set_restore_sigmask() provided and default one won't work"
86065 #endif
86066
86067+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
86068+
86069+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
86070+{
86071+ __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
86072+}
86073+
86074 #endif /* __KERNEL__ */
86075
86076 #endif /* _LINUX_THREAD_INFO_H */
86077diff --git a/include/linux/tty.h b/include/linux/tty.h
86078index 8413294..44391c7 100644
86079--- a/include/linux/tty.h
86080+++ b/include/linux/tty.h
86081@@ -202,7 +202,7 @@ struct tty_port {
86082 const struct tty_port_operations *ops; /* Port operations */
86083 spinlock_t lock; /* Lock protecting tty field */
86084 int blocked_open; /* Waiting to open */
86085- int count; /* Usage count */
86086+ atomic_t count; /* Usage count */
86087 wait_queue_head_t open_wait; /* Open waiters */
86088 wait_queue_head_t close_wait; /* Close waiters */
86089 wait_queue_head_t delta_msr_wait; /* Modem status change */
86090@@ -284,7 +284,7 @@ struct tty_struct {
86091 /* If the tty has a pending do_SAK, queue it here - akpm */
86092 struct work_struct SAK_work;
86093 struct tty_port *port;
86094-};
86095+} __randomize_layout;
86096
86097 /* Each of a tty's open files has private_data pointing to tty_file_private */
86098 struct tty_file_private {
86099@@ -548,7 +548,7 @@ extern int tty_port_open(struct tty_port *port,
86100 struct tty_struct *tty, struct file *filp);
86101 static inline int tty_port_users(struct tty_port *port)
86102 {
86103- return port->count + port->blocked_open;
86104+ return atomic_read(&port->count) + port->blocked_open;
86105 }
86106
86107 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
86108diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
86109index e48c608..6a19af2 100644
86110--- a/include/linux/tty_driver.h
86111+++ b/include/linux/tty_driver.h
86112@@ -287,7 +287,7 @@ struct tty_operations {
86113 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
86114 #endif
86115 const struct file_operations *proc_fops;
86116-};
86117+} __do_const __randomize_layout;
86118
86119 struct tty_driver {
86120 int magic; /* magic number for this structure */
86121@@ -321,7 +321,7 @@ struct tty_driver {
86122
86123 const struct tty_operations *ops;
86124 struct list_head tty_drivers;
86125-};
86126+} __randomize_layout;
86127
86128 extern struct list_head tty_drivers;
86129
86130diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
86131index 00c9d68..bc0188b 100644
86132--- a/include/linux/tty_ldisc.h
86133+++ b/include/linux/tty_ldisc.h
86134@@ -215,7 +215,7 @@ struct tty_ldisc_ops {
86135
86136 struct module *owner;
86137
86138- int refcount;
86139+ atomic_t refcount;
86140 };
86141
86142 struct tty_ldisc {
86143diff --git a/include/linux/types.h b/include/linux/types.h
86144index a0bb704..f511c77 100644
86145--- a/include/linux/types.h
86146+++ b/include/linux/types.h
86147@@ -177,10 +177,26 @@ typedef struct {
86148 int counter;
86149 } atomic_t;
86150
86151+#ifdef CONFIG_PAX_REFCOUNT
86152+typedef struct {
86153+ int counter;
86154+} atomic_unchecked_t;
86155+#else
86156+typedef atomic_t atomic_unchecked_t;
86157+#endif
86158+
86159 #ifdef CONFIG_64BIT
86160 typedef struct {
86161 long counter;
86162 } atomic64_t;
86163+
86164+#ifdef CONFIG_PAX_REFCOUNT
86165+typedef struct {
86166+ long counter;
86167+} atomic64_unchecked_t;
86168+#else
86169+typedef atomic64_t atomic64_unchecked_t;
86170+#endif
86171 #endif
86172
86173 struct list_head {
86174diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
86175index ecd3319..8a36ded 100644
86176--- a/include/linux/uaccess.h
86177+++ b/include/linux/uaccess.h
86178@@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
86179 long ret; \
86180 mm_segment_t old_fs = get_fs(); \
86181 \
86182- set_fs(KERNEL_DS); \
86183 pagefault_disable(); \
86184- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
86185- pagefault_enable(); \
86186+ set_fs(KERNEL_DS); \
86187+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
86188 set_fs(old_fs); \
86189+ pagefault_enable(); \
86190 ret; \
86191 })
86192
86193diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
86194index 2d1f9b6..d7a9fce 100644
86195--- a/include/linux/uidgid.h
86196+++ b/include/linux/uidgid.h
86197@@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
86198
86199 #endif /* CONFIG_USER_NS */
86200
86201+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
86202+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
86203+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
86204+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
86205+
86206 #endif /* _LINUX_UIDGID_H */
86207diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
86208index 99c1b4d..562e6f3 100644
86209--- a/include/linux/unaligned/access_ok.h
86210+++ b/include/linux/unaligned/access_ok.h
86211@@ -4,34 +4,34 @@
86212 #include <linux/kernel.h>
86213 #include <asm/byteorder.h>
86214
86215-static inline u16 get_unaligned_le16(const void *p)
86216+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
86217 {
86218- return le16_to_cpup((__le16 *)p);
86219+ return le16_to_cpup((const __le16 *)p);
86220 }
86221
86222-static inline u32 get_unaligned_le32(const void *p)
86223+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
86224 {
86225- return le32_to_cpup((__le32 *)p);
86226+ return le32_to_cpup((const __le32 *)p);
86227 }
86228
86229-static inline u64 get_unaligned_le64(const void *p)
86230+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
86231 {
86232- return le64_to_cpup((__le64 *)p);
86233+ return le64_to_cpup((const __le64 *)p);
86234 }
86235
86236-static inline u16 get_unaligned_be16(const void *p)
86237+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
86238 {
86239- return be16_to_cpup((__be16 *)p);
86240+ return be16_to_cpup((const __be16 *)p);
86241 }
86242
86243-static inline u32 get_unaligned_be32(const void *p)
86244+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
86245 {
86246- return be32_to_cpup((__be32 *)p);
86247+ return be32_to_cpup((const __be32 *)p);
86248 }
86249
86250-static inline u64 get_unaligned_be64(const void *p)
86251+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
86252 {
86253- return be64_to_cpup((__be64 *)p);
86254+ return be64_to_cpup((const __be64 *)p);
86255 }
86256
86257 static inline void put_unaligned_le16(u16 val, void *p)
86258diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h
86259index 4f844c6..60beb5d 100644
86260--- a/include/linux/uprobes.h
86261+++ b/include/linux/uprobes.h
86262@@ -98,11 +98,11 @@ struct uprobes_state {
86263 struct xol_area *xol_area;
86264 };
86265
86266-extern int __weak set_swbp(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
86267-extern int __weak set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
86268-extern bool __weak is_swbp_insn(uprobe_opcode_t *insn);
86269-extern bool __weak is_trap_insn(uprobe_opcode_t *insn);
86270-extern unsigned long __weak uprobe_get_swbp_addr(struct pt_regs *regs);
86271+extern int set_swbp(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
86272+extern int set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
86273+extern bool is_swbp_insn(uprobe_opcode_t *insn);
86274+extern bool is_trap_insn(uprobe_opcode_t *insn);
86275+extern unsigned long uprobe_get_swbp_addr(struct pt_regs *regs);
86276 extern unsigned long uprobe_get_trap_addr(struct pt_regs *regs);
86277 extern int uprobe_write_opcode(struct mm_struct *mm, unsigned long vaddr, uprobe_opcode_t);
86278 extern int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc);
86279@@ -128,8 +128,8 @@ extern bool arch_uprobe_xol_was_trapped(struct task_struct *tsk);
86280 extern int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val, void *data);
86281 extern void arch_uprobe_abort_xol(struct arch_uprobe *aup, struct pt_regs *regs);
86282 extern unsigned long arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs *regs);
86283-extern bool __weak arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs);
86284-extern void __weak arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,
86285+extern bool arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs);
86286+extern void arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,
86287 void *src, unsigned long len);
86288 #else /* !CONFIG_UPROBES */
86289 struct uprobes_state {
86290diff --git a/include/linux/usb.h b/include/linux/usb.h
86291index d2465bc..5256de4 100644
86292--- a/include/linux/usb.h
86293+++ b/include/linux/usb.h
86294@@ -571,7 +571,7 @@ struct usb_device {
86295 int maxchild;
86296
86297 u32 quirks;
86298- atomic_t urbnum;
86299+ atomic_unchecked_t urbnum;
86300
86301 unsigned long active_duration;
86302
86303@@ -1655,7 +1655,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
86304
86305 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
86306 __u8 request, __u8 requesttype, __u16 value, __u16 index,
86307- void *data, __u16 size, int timeout);
86308+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
86309 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
86310 void *data, int len, int *actual_length, int timeout);
86311 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
86312diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
86313index d5952bb..9a626d4 100644
86314--- a/include/linux/usb/renesas_usbhs.h
86315+++ b/include/linux/usb/renesas_usbhs.h
86316@@ -39,7 +39,7 @@ enum {
86317 */
86318 struct renesas_usbhs_driver_callback {
86319 int (*notify_hotplug)(struct platform_device *pdev);
86320-};
86321+} __no_const;
86322
86323 /*
86324 * callback functions for platform
86325diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
86326index e953726..8edb26a 100644
86327--- a/include/linux/user_namespace.h
86328+++ b/include/linux/user_namespace.h
86329@@ -33,7 +33,7 @@ struct user_namespace {
86330 struct key *persistent_keyring_register;
86331 struct rw_semaphore persistent_keyring_register_sem;
86332 #endif
86333-};
86334+} __randomize_layout;
86335
86336 extern struct user_namespace init_user_ns;
86337
86338diff --git a/include/linux/utsname.h b/include/linux/utsname.h
86339index 239e277..22a5cf5 100644
86340--- a/include/linux/utsname.h
86341+++ b/include/linux/utsname.h
86342@@ -24,7 +24,7 @@ struct uts_namespace {
86343 struct new_utsname name;
86344 struct user_namespace *user_ns;
86345 unsigned int proc_inum;
86346-};
86347+} __randomize_layout;
86348 extern struct uts_namespace init_uts_ns;
86349
86350 #ifdef CONFIG_UTS_NS
86351diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
86352index 6f8fbcf..4efc177 100644
86353--- a/include/linux/vermagic.h
86354+++ b/include/linux/vermagic.h
86355@@ -25,9 +25,42 @@
86356 #define MODULE_ARCH_VERMAGIC ""
86357 #endif
86358
86359+#ifdef CONFIG_PAX_REFCOUNT
86360+#define MODULE_PAX_REFCOUNT "REFCOUNT "
86361+#else
86362+#define MODULE_PAX_REFCOUNT ""
86363+#endif
86364+
86365+#ifdef CONSTIFY_PLUGIN
86366+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
86367+#else
86368+#define MODULE_CONSTIFY_PLUGIN ""
86369+#endif
86370+
86371+#ifdef STACKLEAK_PLUGIN
86372+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
86373+#else
86374+#define MODULE_STACKLEAK_PLUGIN ""
86375+#endif
86376+
86377+#ifdef RANDSTRUCT_PLUGIN
86378+#include <generated/randomize_layout_hash.h>
86379+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
86380+#else
86381+#define MODULE_RANDSTRUCT_PLUGIN
86382+#endif
86383+
86384+#ifdef CONFIG_GRKERNSEC
86385+#define MODULE_GRSEC "GRSEC "
86386+#else
86387+#define MODULE_GRSEC ""
86388+#endif
86389+
86390 #define VERMAGIC_STRING \
86391 UTS_RELEASE " " \
86392 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
86393 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
86394- MODULE_ARCH_VERMAGIC
86395+ MODULE_ARCH_VERMAGIC \
86396+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
86397+ MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
86398
86399diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
86400index b483abd..af305ad 100644
86401--- a/include/linux/vga_switcheroo.h
86402+++ b/include/linux/vga_switcheroo.h
86403@@ -63,9 +63,9 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
86404
86405 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
86406
86407-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
86408+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
86409 void vga_switcheroo_fini_domain_pm_ops(struct device *dev);
86410-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
86411+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
86412 #else
86413
86414 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
86415@@ -82,9 +82,9 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
86416
86417 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
86418
86419-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
86420+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
86421 static inline void vga_switcheroo_fini_domain_pm_ops(struct device *dev) {}
86422-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
86423+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
86424
86425 #endif
86426 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
86427diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
86428index b87696f..1d11de7 100644
86429--- a/include/linux/vmalloc.h
86430+++ b/include/linux/vmalloc.h
86431@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
86432 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
86433 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
86434 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
86435+
86436+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
86437+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
86438+#endif
86439+
86440 /* bits [20..32] reserved for arch specific ioremap internals */
86441
86442 /*
86443@@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
86444 unsigned long flags, pgprot_t prot);
86445 extern void vunmap(const void *addr);
86446
86447+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86448+extern void unmap_process_stacks(struct task_struct *task);
86449+#endif
86450+
86451 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
86452 unsigned long uaddr, void *kaddr,
86453 unsigned long size);
86454@@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
86455
86456 /* for /dev/kmem */
86457 extern long vread(char *buf, char *addr, unsigned long count);
86458-extern long vwrite(char *buf, char *addr, unsigned long count);
86459+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
86460
86461 /*
86462 * Internals. Dont't use..
86463diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
86464index 82e7db7..f8ce3d0 100644
86465--- a/include/linux/vmstat.h
86466+++ b/include/linux/vmstat.h
86467@@ -108,18 +108,18 @@ static inline void vm_events_fold_cpu(int cpu)
86468 /*
86469 * Zone based page accounting with per cpu differentials.
86470 */
86471-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
86472+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
86473
86474 static inline void zone_page_state_add(long x, struct zone *zone,
86475 enum zone_stat_item item)
86476 {
86477- atomic_long_add(x, &zone->vm_stat[item]);
86478- atomic_long_add(x, &vm_stat[item]);
86479+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
86480+ atomic_long_add_unchecked(x, &vm_stat[item]);
86481 }
86482
86483-static inline unsigned long global_page_state(enum zone_stat_item item)
86484+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
86485 {
86486- long x = atomic_long_read(&vm_stat[item]);
86487+ long x = atomic_long_read_unchecked(&vm_stat[item]);
86488 #ifdef CONFIG_SMP
86489 if (x < 0)
86490 x = 0;
86491@@ -127,10 +127,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
86492 return x;
86493 }
86494
86495-static inline unsigned long zone_page_state(struct zone *zone,
86496+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
86497 enum zone_stat_item item)
86498 {
86499- long x = atomic_long_read(&zone->vm_stat[item]);
86500+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
86501 #ifdef CONFIG_SMP
86502 if (x < 0)
86503 x = 0;
86504@@ -147,7 +147,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
86505 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
86506 enum zone_stat_item item)
86507 {
86508- long x = atomic_long_read(&zone->vm_stat[item]);
86509+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
86510
86511 #ifdef CONFIG_SMP
86512 int cpu;
86513@@ -234,14 +234,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
86514
86515 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
86516 {
86517- atomic_long_inc(&zone->vm_stat[item]);
86518- atomic_long_inc(&vm_stat[item]);
86519+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
86520+ atomic_long_inc_unchecked(&vm_stat[item]);
86521 }
86522
86523 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
86524 {
86525- atomic_long_dec(&zone->vm_stat[item]);
86526- atomic_long_dec(&vm_stat[item]);
86527+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
86528+ atomic_long_dec_unchecked(&vm_stat[item]);
86529 }
86530
86531 static inline void __inc_zone_page_state(struct page *page,
86532diff --git a/include/linux/xattr.h b/include/linux/xattr.h
86533index 91b0a68..0e9adf6 100644
86534--- a/include/linux/xattr.h
86535+++ b/include/linux/xattr.h
86536@@ -28,7 +28,7 @@ struct xattr_handler {
86537 size_t size, int handler_flags);
86538 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
86539 size_t size, int flags, int handler_flags);
86540-};
86541+} __do_const;
86542
86543 struct xattr {
86544 const char *name;
86545@@ -37,6 +37,9 @@ struct xattr {
86546 };
86547
86548 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
86549+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
86550+ssize_t pax_getxattr(struct dentry *, void *, size_t);
86551+#endif
86552 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
86553 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
86554 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
86555diff --git a/include/linux/zlib.h b/include/linux/zlib.h
86556index 92dbbd3..13ab0b3 100644
86557--- a/include/linux/zlib.h
86558+++ b/include/linux/zlib.h
86559@@ -31,6 +31,7 @@
86560 #define _ZLIB_H
86561
86562 #include <linux/zconf.h>
86563+#include <linux/compiler.h>
86564
86565 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
86566 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
86567@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
86568
86569 /* basic functions */
86570
86571-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
86572+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
86573 /*
86574 Returns the number of bytes that needs to be allocated for a per-
86575 stream workspace with the specified parameters. A pointer to this
86576diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
86577index eb76cfd..9fd0e7c 100644
86578--- a/include/media/v4l2-dev.h
86579+++ b/include/media/v4l2-dev.h
86580@@ -75,7 +75,7 @@ struct v4l2_file_operations {
86581 int (*mmap) (struct file *, struct vm_area_struct *);
86582 int (*open) (struct file *);
86583 int (*release) (struct file *);
86584-};
86585+} __do_const;
86586
86587 /*
86588 * Newer version of video_device, handled by videodev2.c
86589diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
86590index ffb69da..040393e 100644
86591--- a/include/media/v4l2-device.h
86592+++ b/include/media/v4l2-device.h
86593@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
86594 this function returns 0. If the name ends with a digit (e.g. cx18),
86595 then the name will be set to cx18-0 since cx180 looks really odd. */
86596 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
86597- atomic_t *instance);
86598+ atomic_unchecked_t *instance);
86599
86600 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
86601 Since the parent disappears this ensures that v4l2_dev doesn't have an
86602diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
86603index d9fa68f..45c88d1 100644
86604--- a/include/net/9p/transport.h
86605+++ b/include/net/9p/transport.h
86606@@ -63,7 +63,7 @@ struct p9_trans_module {
86607 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
86608 int (*zc_request)(struct p9_client *, struct p9_req_t *,
86609 char *, char *, int , int, int, int);
86610-};
86611+} __do_const;
86612
86613 void v9fs_register_trans(struct p9_trans_module *m);
86614 void v9fs_unregister_trans(struct p9_trans_module *m);
86615diff --git a/include/net/af_unix.h b/include/net/af_unix.h
86616index a175ba4..196eb8242 100644
86617--- a/include/net/af_unix.h
86618+++ b/include/net/af_unix.h
86619@@ -36,7 +36,7 @@ struct unix_skb_parms {
86620 u32 secid; /* Security ID */
86621 #endif
86622 u32 consumed;
86623-};
86624+} __randomize_layout;
86625
86626 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
86627 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
86628diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
86629index 8df15ad..837fbedd 100644
86630--- a/include/net/bluetooth/l2cap.h
86631+++ b/include/net/bluetooth/l2cap.h
86632@@ -608,7 +608,7 @@ struct l2cap_ops {
86633 unsigned char *kdata,
86634 struct iovec *iov,
86635 int len);
86636-};
86637+} __do_const;
86638
86639 struct l2cap_conn {
86640 struct hci_conn *hcon;
86641diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
86642index f2ae33d..c457cf0 100644
86643--- a/include/net/caif/cfctrl.h
86644+++ b/include/net/caif/cfctrl.h
86645@@ -52,7 +52,7 @@ struct cfctrl_rsp {
86646 void (*radioset_rsp)(void);
86647 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
86648 struct cflayer *client_layer);
86649-};
86650+} __no_const;
86651
86652 /* Link Setup Parameters for CAIF-Links. */
86653 struct cfctrl_link_param {
86654@@ -101,8 +101,8 @@ struct cfctrl_request_info {
86655 struct cfctrl {
86656 struct cfsrvl serv;
86657 struct cfctrl_rsp res;
86658- atomic_t req_seq_no;
86659- atomic_t rsp_seq_no;
86660+ atomic_unchecked_t req_seq_no;
86661+ atomic_unchecked_t rsp_seq_no;
86662 struct list_head list;
86663 /* Protects from simultaneous access to first_req list */
86664 spinlock_t info_list_lock;
86665diff --git a/include/net/flow.h b/include/net/flow.h
86666index 8109a15..504466d 100644
86667--- a/include/net/flow.h
86668+++ b/include/net/flow.h
86669@@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
86670
86671 void flow_cache_flush(struct net *net);
86672 void flow_cache_flush_deferred(struct net *net);
86673-extern atomic_t flow_cache_genid;
86674+extern atomic_unchecked_t flow_cache_genid;
86675
86676 #endif
86677diff --git a/include/net/genetlink.h b/include/net/genetlink.h
86678index af10c2c..a431cc5 100644
86679--- a/include/net/genetlink.h
86680+++ b/include/net/genetlink.h
86681@@ -120,7 +120,7 @@ struct genl_ops {
86682 u8 cmd;
86683 u8 internal_flags;
86684 u8 flags;
86685-};
86686+} __do_const;
86687
86688 int __genl_register_family(struct genl_family *family);
86689
86690diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
86691index 734d9b5..48a9a4b 100644
86692--- a/include/net/gro_cells.h
86693+++ b/include/net/gro_cells.h
86694@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
86695 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
86696
86697 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
86698- atomic_long_inc(&dev->rx_dropped);
86699+ atomic_long_inc_unchecked(&dev->rx_dropped);
86700 kfree_skb(skb);
86701 return;
86702 }
86703diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
86704index 5fbe656..9ed3d8b 100644
86705--- a/include/net/inet_connection_sock.h
86706+++ b/include/net/inet_connection_sock.h
86707@@ -63,7 +63,7 @@ struct inet_connection_sock_af_ops {
86708 int (*bind_conflict)(const struct sock *sk,
86709 const struct inet_bind_bucket *tb, bool relax);
86710 void (*mtu_reduced)(struct sock *sk);
86711-};
86712+} __do_const;
86713
86714 /** inet_connection_sock - INET connection oriented sock
86715 *
86716diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
86717index 01d590e..f69c61d 100644
86718--- a/include/net/inetpeer.h
86719+++ b/include/net/inetpeer.h
86720@@ -47,7 +47,7 @@ struct inet_peer {
86721 */
86722 union {
86723 struct {
86724- atomic_t rid; /* Frag reception counter */
86725+ atomic_unchecked_t rid; /* Frag reception counter */
86726 };
86727 struct rcu_head rcu;
86728 struct inet_peer *gc_next;
86729diff --git a/include/net/ip.h b/include/net/ip.h
86730index db4a771..965a42a 100644
86731--- a/include/net/ip.h
86732+++ b/include/net/ip.h
86733@@ -316,7 +316,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
86734 }
86735 }
86736
86737-u32 ip_idents_reserve(u32 hash, int segs);
86738+u32 ip_idents_reserve(u32 hash, int segs) __intentional_overflow(-1);
86739 void __ip_select_ident(struct iphdr *iph, int segs);
86740
86741 static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
86742diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
86743index 9922093..a1755d6 100644
86744--- a/include/net/ip_fib.h
86745+++ b/include/net/ip_fib.h
86746@@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
86747
86748 #define FIB_RES_SADDR(net, res) \
86749 ((FIB_RES_NH(res).nh_saddr_genid == \
86750- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
86751+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
86752 FIB_RES_NH(res).nh_saddr : \
86753 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
86754 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
86755diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
86756index 624a8a5..b1e2a24 100644
86757--- a/include/net/ip_vs.h
86758+++ b/include/net/ip_vs.h
86759@@ -558,7 +558,7 @@ struct ip_vs_conn {
86760 struct ip_vs_conn *control; /* Master control connection */
86761 atomic_t n_control; /* Number of controlled ones */
86762 struct ip_vs_dest *dest; /* real server */
86763- atomic_t in_pkts; /* incoming packet counter */
86764+ atomic_unchecked_t in_pkts; /* incoming packet counter */
86765
86766 /* packet transmitter for different forwarding methods. If it
86767 mangles the packet, it must return NF_DROP or better NF_STOLEN,
86768@@ -705,7 +705,7 @@ struct ip_vs_dest {
86769 __be16 port; /* port number of the server */
86770 union nf_inet_addr addr; /* IP address of the server */
86771 volatile unsigned int flags; /* dest status flags */
86772- atomic_t conn_flags; /* flags to copy to conn */
86773+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
86774 atomic_t weight; /* server weight */
86775
86776 atomic_t refcnt; /* reference counter */
86777@@ -960,11 +960,11 @@ struct netns_ipvs {
86778 /* ip_vs_lblc */
86779 int sysctl_lblc_expiration;
86780 struct ctl_table_header *lblc_ctl_header;
86781- struct ctl_table *lblc_ctl_table;
86782+ ctl_table_no_const *lblc_ctl_table;
86783 /* ip_vs_lblcr */
86784 int sysctl_lblcr_expiration;
86785 struct ctl_table_header *lblcr_ctl_header;
86786- struct ctl_table *lblcr_ctl_table;
86787+ ctl_table_no_const *lblcr_ctl_table;
86788 /* ip_vs_est */
86789 struct list_head est_list; /* estimator list */
86790 spinlock_t est_lock;
86791diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
86792index 8d4f588..2e37ad2 100644
86793--- a/include/net/irda/ircomm_tty.h
86794+++ b/include/net/irda/ircomm_tty.h
86795@@ -33,6 +33,7 @@
86796 #include <linux/termios.h>
86797 #include <linux/timer.h>
86798 #include <linux/tty.h> /* struct tty_struct */
86799+#include <asm/local.h>
86800
86801 #include <net/irda/irias_object.h>
86802 #include <net/irda/ircomm_core.h>
86803diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
86804index 714cc9a..ea05f3e 100644
86805--- a/include/net/iucv/af_iucv.h
86806+++ b/include/net/iucv/af_iucv.h
86807@@ -149,7 +149,7 @@ struct iucv_skb_cb {
86808 struct iucv_sock_list {
86809 struct hlist_head head;
86810 rwlock_t lock;
86811- atomic_t autobind_name;
86812+ atomic_unchecked_t autobind_name;
86813 };
86814
86815 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
86816diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
86817index f3be818..bf46196 100644
86818--- a/include/net/llc_c_ac.h
86819+++ b/include/net/llc_c_ac.h
86820@@ -87,7 +87,7 @@
86821 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
86822 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
86823
86824-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86825+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86826
86827 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
86828 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
86829diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
86830index 3948cf1..83b28c4 100644
86831--- a/include/net/llc_c_ev.h
86832+++ b/include/net/llc_c_ev.h
86833@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
86834 return (struct llc_conn_state_ev *)skb->cb;
86835 }
86836
86837-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86838-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86839+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86840+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86841
86842 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
86843 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
86844diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
86845index 0e79cfb..f46db31 100644
86846--- a/include/net/llc_c_st.h
86847+++ b/include/net/llc_c_st.h
86848@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
86849 u8 next_state;
86850 llc_conn_ev_qfyr_t *ev_qualifiers;
86851 llc_conn_action_t *ev_actions;
86852-};
86853+} __do_const;
86854
86855 struct llc_conn_state {
86856 u8 current_state;
86857diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
86858index a61b98c..aade1eb 100644
86859--- a/include/net/llc_s_ac.h
86860+++ b/include/net/llc_s_ac.h
86861@@ -23,7 +23,7 @@
86862 #define SAP_ACT_TEST_IND 9
86863
86864 /* All action functions must look like this */
86865-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86866+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86867
86868 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
86869 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
86870diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
86871index 567c681..cd73ac02 100644
86872--- a/include/net/llc_s_st.h
86873+++ b/include/net/llc_s_st.h
86874@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
86875 llc_sap_ev_t ev;
86876 u8 next_state;
86877 llc_sap_action_t *ev_actions;
86878-};
86879+} __do_const;
86880
86881 struct llc_sap_state {
86882 u8 curr_state;
86883diff --git a/include/net/mac80211.h b/include/net/mac80211.h
86884index dae2e24..89336e6 100644
86885--- a/include/net/mac80211.h
86886+++ b/include/net/mac80211.h
86887@@ -4650,7 +4650,7 @@ struct rate_control_ops {
86888 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
86889
86890 u32 (*get_expected_throughput)(void *priv_sta);
86891-};
86892+} __do_const;
86893
86894 static inline int rate_supported(struct ieee80211_sta *sta,
86895 enum ieee80211_band band,
86896diff --git a/include/net/neighbour.h b/include/net/neighbour.h
86897index 47f4254..fd095bc 100644
86898--- a/include/net/neighbour.h
86899+++ b/include/net/neighbour.h
86900@@ -163,7 +163,7 @@ struct neigh_ops {
86901 void (*error_report)(struct neighbour *, struct sk_buff *);
86902 int (*output)(struct neighbour *, struct sk_buff *);
86903 int (*connected_output)(struct neighbour *, struct sk_buff *);
86904-};
86905+} __do_const;
86906
86907 struct pneigh_entry {
86908 struct pneigh_entry *next;
86909@@ -217,7 +217,7 @@ struct neigh_table {
86910 struct neigh_statistics __percpu *stats;
86911 struct neigh_hash_table __rcu *nht;
86912 struct pneigh_entry **phash_buckets;
86913-};
86914+} __randomize_layout;
86915
86916 static inline int neigh_parms_family(struct neigh_parms *p)
86917 {
86918diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
86919index e0d6466..e2f3003 100644
86920--- a/include/net/net_namespace.h
86921+++ b/include/net/net_namespace.h
86922@@ -129,8 +129,8 @@ struct net {
86923 struct netns_ipvs *ipvs;
86924 #endif
86925 struct sock *diag_nlsk;
86926- atomic_t fnhe_genid;
86927-};
86928+ atomic_unchecked_t fnhe_genid;
86929+} __randomize_layout;
86930
86931 #include <linux/seq_file_net.h>
86932
86933@@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
86934 #define __net_init __init
86935 #define __net_exit __exit_refok
86936 #define __net_initdata __initdata
86937+#ifdef CONSTIFY_PLUGIN
86938 #define __net_initconst __initconst
86939+#else
86940+#define __net_initconst __initdata
86941+#endif
86942 #endif
86943
86944 struct pernet_operations {
86945@@ -296,7 +300,7 @@ struct pernet_operations {
86946 void (*exit_batch)(struct list_head *net_exit_list);
86947 int *id;
86948 size_t size;
86949-};
86950+} __do_const;
86951
86952 /*
86953 * Use these carefully. If you implement a network device and it
86954@@ -344,12 +348,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
86955
86956 static inline int rt_genid_ipv4(struct net *net)
86957 {
86958- return atomic_read(&net->ipv4.rt_genid);
86959+ return atomic_read_unchecked(&net->ipv4.rt_genid);
86960 }
86961
86962 static inline void rt_genid_bump_ipv4(struct net *net)
86963 {
86964- atomic_inc(&net->ipv4.rt_genid);
86965+ atomic_inc_unchecked(&net->ipv4.rt_genid);
86966 }
86967
86968 extern void (*__fib6_flush_trees)(struct net *net);
86969@@ -376,12 +380,12 @@ static inline void rt_genid_bump_all(struct net *net)
86970
86971 static inline int fnhe_genid(struct net *net)
86972 {
86973- return atomic_read(&net->fnhe_genid);
86974+ return atomic_read_unchecked(&net->fnhe_genid);
86975 }
86976
86977 static inline void fnhe_genid_bump(struct net *net)
86978 {
86979- atomic_inc(&net->fnhe_genid);
86980+ atomic_inc_unchecked(&net->fnhe_genid);
86981 }
86982
86983 #endif /* __NET_NET_NAMESPACE_H */
86984diff --git a/include/net/netdma.h b/include/net/netdma.h
86985index 8ba8ce2..99b7fff 100644
86986--- a/include/net/netdma.h
86987+++ b/include/net/netdma.h
86988@@ -24,7 +24,7 @@
86989 #include <linux/dmaengine.h>
86990 #include <linux/skbuff.h>
86991
86992-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
86993+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
86994 struct sk_buff *skb, int offset, struct iovec *to,
86995 size_t len, struct dma_pinned_list *pinned_list);
86996
86997diff --git a/include/net/netlink.h b/include/net/netlink.h
86998index 6c10762..3e5de0c 100644
86999--- a/include/net/netlink.h
87000+++ b/include/net/netlink.h
87001@@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
87002 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
87003 {
87004 if (mark)
87005- skb_trim(skb, (unsigned char *) mark - skb->data);
87006+ skb_trim(skb, (const unsigned char *) mark - skb->data);
87007 }
87008
87009 /**
87010diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
87011index 29d6a94..235d3d8 100644
87012--- a/include/net/netns/conntrack.h
87013+++ b/include/net/netns/conntrack.h
87014@@ -14,10 +14,10 @@ struct nf_conntrack_ecache;
87015 struct nf_proto_net {
87016 #ifdef CONFIG_SYSCTL
87017 struct ctl_table_header *ctl_table_header;
87018- struct ctl_table *ctl_table;
87019+ ctl_table_no_const *ctl_table;
87020 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
87021 struct ctl_table_header *ctl_compat_header;
87022- struct ctl_table *ctl_compat_table;
87023+ ctl_table_no_const *ctl_compat_table;
87024 #endif
87025 #endif
87026 unsigned int users;
87027@@ -60,7 +60,7 @@ struct nf_ip_net {
87028 struct nf_icmp_net icmpv6;
87029 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
87030 struct ctl_table_header *ctl_table_header;
87031- struct ctl_table *ctl_table;
87032+ ctl_table_no_const *ctl_table;
87033 #endif
87034 };
87035
87036diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
87037index aec5e12..807233f 100644
87038--- a/include/net/netns/ipv4.h
87039+++ b/include/net/netns/ipv4.h
87040@@ -82,7 +82,7 @@ struct netns_ipv4 {
87041
87042 struct ping_group_range ping_group_range;
87043
87044- atomic_t dev_addr_genid;
87045+ atomic_unchecked_t dev_addr_genid;
87046
87047 #ifdef CONFIG_SYSCTL
87048 unsigned long *sysctl_local_reserved_ports;
87049@@ -96,6 +96,6 @@ struct netns_ipv4 {
87050 struct fib_rules_ops *mr_rules_ops;
87051 #endif
87052 #endif
87053- atomic_t rt_genid;
87054+ atomic_unchecked_t rt_genid;
87055 };
87056 #endif
87057diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
87058index eade27a..42894dd 100644
87059--- a/include/net/netns/ipv6.h
87060+++ b/include/net/netns/ipv6.h
87061@@ -75,8 +75,8 @@ struct netns_ipv6 {
87062 struct fib_rules_ops *mr6_rules_ops;
87063 #endif
87064 #endif
87065- atomic_t dev_addr_genid;
87066- atomic_t rt_genid;
87067+ atomic_unchecked_t dev_addr_genid;
87068+ atomic_unchecked_t rt_genid;
87069 };
87070
87071 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
87072diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
87073index 3492434..209f58c 100644
87074--- a/include/net/netns/xfrm.h
87075+++ b/include/net/netns/xfrm.h
87076@@ -64,7 +64,7 @@ struct netns_xfrm {
87077
87078 /* flow cache part */
87079 struct flow_cache flow_cache_global;
87080- atomic_t flow_cache_genid;
87081+ atomic_unchecked_t flow_cache_genid;
87082 struct list_head flow_cache_gc_list;
87083 spinlock_t flow_cache_gc_lock;
87084 struct work_struct flow_cache_gc_work;
87085diff --git a/include/net/ping.h b/include/net/ping.h
87086index 026479b..d9b2829 100644
87087--- a/include/net/ping.h
87088+++ b/include/net/ping.h
87089@@ -54,7 +54,7 @@ struct ping_iter_state {
87090
87091 extern struct proto ping_prot;
87092 #if IS_ENABLED(CONFIG_IPV6)
87093-extern struct pingv6_ops pingv6_ops;
87094+extern struct pingv6_ops *pingv6_ops;
87095 #endif
87096
87097 struct pingfakehdr {
87098diff --git a/include/net/protocol.h b/include/net/protocol.h
87099index d6fcc1f..ca277058 100644
87100--- a/include/net/protocol.h
87101+++ b/include/net/protocol.h
87102@@ -49,7 +49,7 @@ struct net_protocol {
87103 * socket lookup?
87104 */
87105 icmp_strict_tag_validation:1;
87106-};
87107+} __do_const;
87108
87109 #if IS_ENABLED(CONFIG_IPV6)
87110 struct inet6_protocol {
87111@@ -62,7 +62,7 @@ struct inet6_protocol {
87112 u8 type, u8 code, int offset,
87113 __be32 info);
87114 unsigned int flags; /* INET6_PROTO_xxx */
87115-};
87116+} __do_const;
87117
87118 #define INET6_PROTO_NOPOLICY 0x1
87119 #define INET6_PROTO_FINAL 0x2
87120diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
87121index e21b9f9..0191ef0 100644
87122--- a/include/net/rtnetlink.h
87123+++ b/include/net/rtnetlink.h
87124@@ -93,7 +93,7 @@ struct rtnl_link_ops {
87125 int (*fill_slave_info)(struct sk_buff *skb,
87126 const struct net_device *dev,
87127 const struct net_device *slave_dev);
87128-};
87129+} __do_const;
87130
87131 int __rtnl_link_register(struct rtnl_link_ops *ops);
87132 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
87133diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
87134index 4a5b9a3..ca27d73 100644
87135--- a/include/net/sctp/checksum.h
87136+++ b/include/net/sctp/checksum.h
87137@@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
87138 unsigned int offset)
87139 {
87140 struct sctphdr *sh = sctp_hdr(skb);
87141- __le32 ret, old = sh->checksum;
87142- const struct skb_checksum_ops ops = {
87143+ __le32 ret, old = sh->checksum;
87144+ static const struct skb_checksum_ops ops = {
87145 .update = sctp_csum_update,
87146 .combine = sctp_csum_combine,
87147 };
87148diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
87149index 72a31db..aaa63d9 100644
87150--- a/include/net/sctp/sm.h
87151+++ b/include/net/sctp/sm.h
87152@@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
87153 typedef struct {
87154 sctp_state_fn_t *fn;
87155 const char *name;
87156-} sctp_sm_table_entry_t;
87157+} __do_const sctp_sm_table_entry_t;
87158
87159 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
87160 * currently in use.
87161@@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
87162 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
87163
87164 /* Extern declarations for major data structures. */
87165-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
87166+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
87167
87168
87169 /* Get the size of a DATA chunk payload. */
87170diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
87171index 4ff3f67..89ae38e 100644
87172--- a/include/net/sctp/structs.h
87173+++ b/include/net/sctp/structs.h
87174@@ -509,7 +509,7 @@ struct sctp_pf {
87175 void (*to_sk_saddr)(union sctp_addr *, struct sock *sk);
87176 void (*to_sk_daddr)(union sctp_addr *, struct sock *sk);
87177 struct sctp_af *af;
87178-};
87179+} __do_const;
87180
87181
87182 /* Structure to track chunk fragments that have been acked, but peer
87183diff --git a/include/net/sock.h b/include/net/sock.h
87184index b9a5bd0..dcd5f3c 100644
87185--- a/include/net/sock.h
87186+++ b/include/net/sock.h
87187@@ -356,7 +356,7 @@ struct sock {
87188 unsigned int sk_napi_id;
87189 unsigned int sk_ll_usec;
87190 #endif
87191- atomic_t sk_drops;
87192+ atomic_unchecked_t sk_drops;
87193 int sk_rcvbuf;
87194
87195 struct sk_filter __rcu *sk_filter;
87196@@ -1053,7 +1053,7 @@ struct proto {
87197 void (*destroy_cgroup)(struct mem_cgroup *memcg);
87198 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
87199 #endif
87200-};
87201+} __randomize_layout;
87202
87203 /*
87204 * Bits in struct cg_proto.flags
87205@@ -1240,7 +1240,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
87206 return ret >> PAGE_SHIFT;
87207 }
87208
87209-static inline long
87210+static inline long __intentional_overflow(-1)
87211 sk_memory_allocated(const struct sock *sk)
87212 {
87213 struct proto *prot = sk->sk_prot;
87214@@ -1385,7 +1385,7 @@ struct sock_iocb {
87215 struct scm_cookie *scm;
87216 struct msghdr *msg, async_msg;
87217 struct kiocb *kiocb;
87218-};
87219+} __randomize_layout;
87220
87221 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
87222 {
87223@@ -1820,7 +1820,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
87224 }
87225
87226 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
87227- char __user *from, char *to,
87228+ char __user *from, unsigned char *to,
87229 int copy, int offset)
87230 {
87231 if (skb->ip_summed == CHECKSUM_NONE) {
87232@@ -2091,7 +2091,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
87233 }
87234 }
87235
87236-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
87237+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
87238
87239 /**
87240 * sk_page_frag - return an appropriate page_frag
87241diff --git a/include/net/tcp.h b/include/net/tcp.h
87242index 590e01a..76498f3 100644
87243--- a/include/net/tcp.h
87244+++ b/include/net/tcp.h
87245@@ -523,7 +523,7 @@ void tcp_retransmit_timer(struct sock *sk);
87246 void tcp_xmit_retransmit_queue(struct sock *);
87247 void tcp_simple_retransmit(struct sock *);
87248 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
87249-int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
87250+int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
87251
87252 void tcp_send_probe0(struct sock *);
87253 void tcp_send_partial(struct sock *);
87254@@ -696,8 +696,8 @@ struct tcp_skb_cb {
87255 struct inet6_skb_parm h6;
87256 #endif
87257 } header; /* For incoming frames */
87258- __u32 seq; /* Starting sequence number */
87259- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
87260+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
87261+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
87262 __u32 when; /* used to compute rtt's */
87263 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
87264
87265@@ -713,7 +713,7 @@ struct tcp_skb_cb {
87266
87267 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
87268 /* 1 byte hole */
87269- __u32 ack_seq; /* Sequence number ACK'd */
87270+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
87271 };
87272
87273 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
87274diff --git a/include/net/xfrm.h b/include/net/xfrm.h
87275index 721e9c3b..3c81bbf 100644
87276--- a/include/net/xfrm.h
87277+++ b/include/net/xfrm.h
87278@@ -285,7 +285,6 @@ struct xfrm_dst;
87279 struct xfrm_policy_afinfo {
87280 unsigned short family;
87281 struct dst_ops *dst_ops;
87282- void (*garbage_collect)(struct net *net);
87283 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
87284 const xfrm_address_t *saddr,
87285 const xfrm_address_t *daddr);
87286@@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
87287 struct net_device *dev,
87288 const struct flowi *fl);
87289 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
87290-};
87291+} __do_const;
87292
87293 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
87294 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
87295@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
87296 int (*transport_finish)(struct sk_buff *skb,
87297 int async);
87298 void (*local_error)(struct sk_buff *skb, u32 mtu);
87299-};
87300+} __do_const;
87301
87302 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
87303 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
87304@@ -437,7 +436,7 @@ struct xfrm_mode {
87305 struct module *owner;
87306 unsigned int encap;
87307 int flags;
87308-};
87309+} __do_const;
87310
87311 /* Flags for xfrm_mode. */
87312 enum {
87313@@ -534,7 +533,7 @@ struct xfrm_policy {
87314 struct timer_list timer;
87315
87316 struct flow_cache_object flo;
87317- atomic_t genid;
87318+ atomic_unchecked_t genid;
87319 u32 priority;
87320 u32 index;
87321 struct xfrm_mark mark;
87322@@ -1167,6 +1166,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
87323 }
87324
87325 void xfrm_garbage_collect(struct net *net);
87326+void xfrm_garbage_collect_deferred(struct net *net);
87327
87328 #else
87329
87330@@ -1205,6 +1205,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
87331 static inline void xfrm_garbage_collect(struct net *net)
87332 {
87333 }
87334+static inline void xfrm_garbage_collect_deferred(struct net *net)
87335+{
87336+}
87337 #endif
87338
87339 static __inline__
87340diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
87341index 1017e0b..227aa4d 100644
87342--- a/include/rdma/iw_cm.h
87343+++ b/include/rdma/iw_cm.h
87344@@ -122,7 +122,7 @@ struct iw_cm_verbs {
87345 int backlog);
87346
87347 int (*destroy_listen)(struct iw_cm_id *cm_id);
87348-};
87349+} __no_const;
87350
87351 /**
87352 * iw_create_cm_id - Create an IW CM identifier.
87353diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
87354index 52beadf..598734c 100644
87355--- a/include/scsi/libfc.h
87356+++ b/include/scsi/libfc.h
87357@@ -771,6 +771,7 @@ struct libfc_function_template {
87358 */
87359 void (*disc_stop_final) (struct fc_lport *);
87360 };
87361+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
87362
87363 /**
87364 * struct fc_disc - Discovery context
87365@@ -875,7 +876,7 @@ struct fc_lport {
87366 struct fc_vport *vport;
87367
87368 /* Operational Information */
87369- struct libfc_function_template tt;
87370+ libfc_function_template_no_const tt;
87371 u8 link_up;
87372 u8 qfull;
87373 enum fc_lport_state state;
87374diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
87375index 1a0d184..4fb841f 100644
87376--- a/include/scsi/scsi_device.h
87377+++ b/include/scsi/scsi_device.h
87378@@ -185,9 +185,9 @@ struct scsi_device {
87379 unsigned int max_device_blocked; /* what device_blocked counts down from */
87380 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
87381
87382- atomic_t iorequest_cnt;
87383- atomic_t iodone_cnt;
87384- atomic_t ioerr_cnt;
87385+ atomic_unchecked_t iorequest_cnt;
87386+ atomic_unchecked_t iodone_cnt;
87387+ atomic_unchecked_t ioerr_cnt;
87388
87389 struct device sdev_gendev,
87390 sdev_dev;
87391diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
87392index 007a0bc..7188db8 100644
87393--- a/include/scsi/scsi_transport_fc.h
87394+++ b/include/scsi/scsi_transport_fc.h
87395@@ -756,7 +756,8 @@ struct fc_function_template {
87396 unsigned long show_host_system_hostname:1;
87397
87398 unsigned long disable_target_scan:1;
87399-};
87400+} __do_const;
87401+typedef struct fc_function_template __no_const fc_function_template_no_const;
87402
87403
87404 /**
87405diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
87406index ae6c3b8..fd748ac 100644
87407--- a/include/sound/compress_driver.h
87408+++ b/include/sound/compress_driver.h
87409@@ -128,7 +128,7 @@ struct snd_compr_ops {
87410 struct snd_compr_caps *caps);
87411 int (*get_codec_caps) (struct snd_compr_stream *stream,
87412 struct snd_compr_codec_caps *codec);
87413-};
87414+} __no_const;
87415
87416 /**
87417 * struct snd_compr: Compressed device
87418diff --git a/include/sound/soc.h b/include/sound/soc.h
87419index c83a334..27c8038 100644
87420--- a/include/sound/soc.h
87421+++ b/include/sound/soc.h
87422@@ -817,7 +817,7 @@ struct snd_soc_codec_driver {
87423 /* probe ordering - for components with runtime dependencies */
87424 int probe_order;
87425 int remove_order;
87426-};
87427+} __do_const;
87428
87429 /* SoC platform interface */
87430 struct snd_soc_platform_driver {
87431@@ -861,7 +861,7 @@ struct snd_soc_platform_driver {
87432 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
87433 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
87434 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
87435-};
87436+} __do_const;
87437
87438 struct snd_soc_dai_link_component {
87439 const char *name;
87440diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
87441index 9ec9864..e2ee1ee 100644
87442--- a/include/target/target_core_base.h
87443+++ b/include/target/target_core_base.h
87444@@ -761,7 +761,7 @@ struct se_device {
87445 atomic_long_t write_bytes;
87446 /* Active commands on this virtual SE device */
87447 atomic_t simple_cmds;
87448- atomic_t dev_ordered_id;
87449+ atomic_unchecked_t dev_ordered_id;
87450 atomic_t dev_ordered_sync;
87451 atomic_t dev_qf_count;
87452 int export_count;
87453diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
87454new file mode 100644
87455index 0000000..fb634b7
87456--- /dev/null
87457+++ b/include/trace/events/fs.h
87458@@ -0,0 +1,53 @@
87459+#undef TRACE_SYSTEM
87460+#define TRACE_SYSTEM fs
87461+
87462+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
87463+#define _TRACE_FS_H
87464+
87465+#include <linux/fs.h>
87466+#include <linux/tracepoint.h>
87467+
87468+TRACE_EVENT(do_sys_open,
87469+
87470+ TP_PROTO(const char *filename, int flags, int mode),
87471+
87472+ TP_ARGS(filename, flags, mode),
87473+
87474+ TP_STRUCT__entry(
87475+ __string( filename, filename )
87476+ __field( int, flags )
87477+ __field( int, mode )
87478+ ),
87479+
87480+ TP_fast_assign(
87481+ __assign_str(filename, filename);
87482+ __entry->flags = flags;
87483+ __entry->mode = mode;
87484+ ),
87485+
87486+ TP_printk("\"%s\" %x %o",
87487+ __get_str(filename), __entry->flags, __entry->mode)
87488+);
87489+
87490+TRACE_EVENT(open_exec,
87491+
87492+ TP_PROTO(const char *filename),
87493+
87494+ TP_ARGS(filename),
87495+
87496+ TP_STRUCT__entry(
87497+ __string( filename, filename )
87498+ ),
87499+
87500+ TP_fast_assign(
87501+ __assign_str(filename, filename);
87502+ ),
87503+
87504+ TP_printk("\"%s\"",
87505+ __get_str(filename))
87506+);
87507+
87508+#endif /* _TRACE_FS_H */
87509+
87510+/* This part must be outside protection */
87511+#include <trace/define_trace.h>
87512diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
87513index 3608beb..df39d8a 100644
87514--- a/include/trace/events/irq.h
87515+++ b/include/trace/events/irq.h
87516@@ -36,7 +36,7 @@ struct softirq_action;
87517 */
87518 TRACE_EVENT(irq_handler_entry,
87519
87520- TP_PROTO(int irq, struct irqaction *action),
87521+ TP_PROTO(int irq, const struct irqaction *action),
87522
87523 TP_ARGS(irq, action),
87524
87525@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
87526 */
87527 TRACE_EVENT(irq_handler_exit,
87528
87529- TP_PROTO(int irq, struct irqaction *action, int ret),
87530+ TP_PROTO(int irq, const struct irqaction *action, int ret),
87531
87532 TP_ARGS(irq, action, ret),
87533
87534diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
87535index 7caf44c..23c6f27 100644
87536--- a/include/uapi/linux/a.out.h
87537+++ b/include/uapi/linux/a.out.h
87538@@ -39,6 +39,14 @@ enum machine_type {
87539 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
87540 };
87541
87542+/* Constants for the N_FLAGS field */
87543+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
87544+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
87545+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
87546+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
87547+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
87548+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87549+
87550 #if !defined (N_MAGIC)
87551 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
87552 #endif
87553diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
87554index 22b6ad3..aeba37e 100644
87555--- a/include/uapi/linux/bcache.h
87556+++ b/include/uapi/linux/bcache.h
87557@@ -5,6 +5,7 @@
87558 * Bcache on disk data structures
87559 */
87560
87561+#include <linux/compiler.h>
87562 #include <asm/types.h>
87563
87564 #define BITMASK(name, type, field, offset, size) \
87565@@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
87566 /* Btree keys - all units are in sectors */
87567
87568 struct bkey {
87569- __u64 high;
87570- __u64 low;
87571+ __u64 high __intentional_overflow(-1);
87572+ __u64 low __intentional_overflow(-1);
87573 __u64 ptr[];
87574 };
87575
87576diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
87577index d876736..ccce5c0 100644
87578--- a/include/uapi/linux/byteorder/little_endian.h
87579+++ b/include/uapi/linux/byteorder/little_endian.h
87580@@ -42,51 +42,51 @@
87581
87582 static inline __le64 __cpu_to_le64p(const __u64 *p)
87583 {
87584- return (__force __le64)*p;
87585+ return (__force const __le64)*p;
87586 }
87587-static inline __u64 __le64_to_cpup(const __le64 *p)
87588+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
87589 {
87590- return (__force __u64)*p;
87591+ return (__force const __u64)*p;
87592 }
87593 static inline __le32 __cpu_to_le32p(const __u32 *p)
87594 {
87595- return (__force __le32)*p;
87596+ return (__force const __le32)*p;
87597 }
87598 static inline __u32 __le32_to_cpup(const __le32 *p)
87599 {
87600- return (__force __u32)*p;
87601+ return (__force const __u32)*p;
87602 }
87603 static inline __le16 __cpu_to_le16p(const __u16 *p)
87604 {
87605- return (__force __le16)*p;
87606+ return (__force const __le16)*p;
87607 }
87608 static inline __u16 __le16_to_cpup(const __le16 *p)
87609 {
87610- return (__force __u16)*p;
87611+ return (__force const __u16)*p;
87612 }
87613 static inline __be64 __cpu_to_be64p(const __u64 *p)
87614 {
87615- return (__force __be64)__swab64p(p);
87616+ return (__force const __be64)__swab64p(p);
87617 }
87618 static inline __u64 __be64_to_cpup(const __be64 *p)
87619 {
87620- return __swab64p((__u64 *)p);
87621+ return __swab64p((const __u64 *)p);
87622 }
87623 static inline __be32 __cpu_to_be32p(const __u32 *p)
87624 {
87625- return (__force __be32)__swab32p(p);
87626+ return (__force const __be32)__swab32p(p);
87627 }
87628-static inline __u32 __be32_to_cpup(const __be32 *p)
87629+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
87630 {
87631- return __swab32p((__u32 *)p);
87632+ return __swab32p((const __u32 *)p);
87633 }
87634 static inline __be16 __cpu_to_be16p(const __u16 *p)
87635 {
87636- return (__force __be16)__swab16p(p);
87637+ return (__force const __be16)__swab16p(p);
87638 }
87639 static inline __u16 __be16_to_cpup(const __be16 *p)
87640 {
87641- return __swab16p((__u16 *)p);
87642+ return __swab16p((const __u16 *)p);
87643 }
87644 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
87645 #define __le64_to_cpus(x) do { (void)(x); } while (0)
87646diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
87647index ef6103b..d4e65dd 100644
87648--- a/include/uapi/linux/elf.h
87649+++ b/include/uapi/linux/elf.h
87650@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
87651 #define PT_GNU_EH_FRAME 0x6474e550
87652
87653 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
87654+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
87655+
87656+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
87657+
87658+/* Constants for the e_flags field */
87659+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
87660+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
87661+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
87662+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
87663+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
87664+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87665
87666 /*
87667 * Extended Numbering
87668@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
87669 #define DT_DEBUG 21
87670 #define DT_TEXTREL 22
87671 #define DT_JMPREL 23
87672+#define DT_FLAGS 30
87673+ #define DF_TEXTREL 0x00000004
87674 #define DT_ENCODING 32
87675 #define OLD_DT_LOOS 0x60000000
87676 #define DT_LOOS 0x6000000d
87677@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
87678 #define PF_W 0x2
87679 #define PF_X 0x1
87680
87681+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
87682+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
87683+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
87684+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
87685+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
87686+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
87687+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
87688+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
87689+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
87690+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
87691+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
87692+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
87693+
87694 typedef struct elf32_phdr{
87695 Elf32_Word p_type;
87696 Elf32_Off p_offset;
87697@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
87698 #define EI_OSABI 7
87699 #define EI_PAD 8
87700
87701+#define EI_PAX 14
87702+
87703 #define ELFMAG0 0x7f /* EI_MAG */
87704 #define ELFMAG1 'E'
87705 #define ELFMAG2 'L'
87706diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
87707index aa169c4..6a2771d 100644
87708--- a/include/uapi/linux/personality.h
87709+++ b/include/uapi/linux/personality.h
87710@@ -30,6 +30,7 @@ enum {
87711 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
87712 ADDR_NO_RANDOMIZE | \
87713 ADDR_COMPAT_LAYOUT | \
87714+ ADDR_LIMIT_3GB | \
87715 MMAP_PAGE_ZERO)
87716
87717 /*
87718diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
87719index 7530e74..e714828 100644
87720--- a/include/uapi/linux/screen_info.h
87721+++ b/include/uapi/linux/screen_info.h
87722@@ -43,7 +43,8 @@ struct screen_info {
87723 __u16 pages; /* 0x32 */
87724 __u16 vesa_attributes; /* 0x34 */
87725 __u32 capabilities; /* 0x36 */
87726- __u8 _reserved[6]; /* 0x3a */
87727+ __u16 vesapm_size; /* 0x3a */
87728+ __u8 _reserved[4]; /* 0x3c */
87729 } __attribute__((packed));
87730
87731 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
87732diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
87733index 0e011eb..82681b1 100644
87734--- a/include/uapi/linux/swab.h
87735+++ b/include/uapi/linux/swab.h
87736@@ -43,7 +43,7 @@
87737 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
87738 */
87739
87740-static inline __attribute_const__ __u16 __fswab16(__u16 val)
87741+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
87742 {
87743 #ifdef __HAVE_BUILTIN_BSWAP16__
87744 return __builtin_bswap16(val);
87745@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
87746 #endif
87747 }
87748
87749-static inline __attribute_const__ __u32 __fswab32(__u32 val)
87750+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
87751 {
87752 #ifdef __HAVE_BUILTIN_BSWAP32__
87753 return __builtin_bswap32(val);
87754@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
87755 #endif
87756 }
87757
87758-static inline __attribute_const__ __u64 __fswab64(__u64 val)
87759+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
87760 {
87761 #ifdef __HAVE_BUILTIN_BSWAP64__
87762 return __builtin_bswap64(val);
87763diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
87764index 43aaba1..1c30b48 100644
87765--- a/include/uapi/linux/sysctl.h
87766+++ b/include/uapi/linux/sysctl.h
87767@@ -155,8 +155,6 @@ enum
87768 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
87769 };
87770
87771-
87772-
87773 /* CTL_VM names: */
87774 enum
87775 {
87776diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
87777index 778a329..1416ffb 100644
87778--- a/include/uapi/linux/videodev2.h
87779+++ b/include/uapi/linux/videodev2.h
87780@@ -1285,7 +1285,7 @@ struct v4l2_ext_control {
87781 union {
87782 __s32 value;
87783 __s64 value64;
87784- char *string;
87785+ char __user *string;
87786 __u8 *p_u8;
87787 __u16 *p_u16;
87788 __u32 *p_u32;
87789diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
87790index 1590c49..5eab462 100644
87791--- a/include/uapi/linux/xattr.h
87792+++ b/include/uapi/linux/xattr.h
87793@@ -73,5 +73,9 @@
87794 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
87795 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
87796
87797+/* User namespace */
87798+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
87799+#define XATTR_PAX_FLAGS_SUFFIX "flags"
87800+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
87801
87802 #endif /* _UAPI_LINUX_XATTR_H */
87803diff --git a/include/video/udlfb.h b/include/video/udlfb.h
87804index f9466fa..f4e2b81 100644
87805--- a/include/video/udlfb.h
87806+++ b/include/video/udlfb.h
87807@@ -53,10 +53,10 @@ struct dlfb_data {
87808 u32 pseudo_palette[256];
87809 int blank_mode; /*one of FB_BLANK_ */
87810 /* blit-only rendering path metrics, exposed through sysfs */
87811- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87812- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
87813- atomic_t bytes_sent; /* to usb, after compression including overhead */
87814- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
87815+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87816+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
87817+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
87818+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
87819 };
87820
87821 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
87822diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
87823index 30f5362..8ed8ac9 100644
87824--- a/include/video/uvesafb.h
87825+++ b/include/video/uvesafb.h
87826@@ -122,6 +122,7 @@ struct uvesafb_par {
87827 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
87828 u8 pmi_setpal; /* PMI for palette changes */
87829 u16 *pmi_base; /* protected mode interface location */
87830+ u8 *pmi_code; /* protected mode code location */
87831 void *pmi_start;
87832 void *pmi_pal;
87833 u8 *vbe_state_orig; /*
87834diff --git a/init/Kconfig b/init/Kconfig
87835index 80a6907..baf7d53 100644
87836--- a/init/Kconfig
87837+++ b/init/Kconfig
87838@@ -1150,6 +1150,7 @@ endif # CGROUPS
87839
87840 config CHECKPOINT_RESTORE
87841 bool "Checkpoint/restore support" if EXPERT
87842+ depends on !GRKERNSEC
87843 default n
87844 help
87845 Enables additional kernel features in a sake of checkpoint/restore.
87846@@ -1635,7 +1636,7 @@ config SLUB_DEBUG
87847
87848 config COMPAT_BRK
87849 bool "Disable heap randomization"
87850- default y
87851+ default n
87852 help
87853 Randomizing heap placement makes heap exploits harder, but it
87854 also breaks ancient binaries (including anything libc5 based).
87855@@ -1923,7 +1924,7 @@ config INIT_ALL_POSSIBLE
87856 config STOP_MACHINE
87857 bool
87858 default y
87859- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
87860+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
87861 help
87862 Need stop_machine() primitive.
87863
87864diff --git a/init/Makefile b/init/Makefile
87865index 7bc47ee..6da2dc7 100644
87866--- a/init/Makefile
87867+++ b/init/Makefile
87868@@ -2,6 +2,9 @@
87869 # Makefile for the linux kernel.
87870 #
87871
87872+ccflags-y := $(GCC_PLUGINS_CFLAGS)
87873+asflags-y := $(GCC_PLUGINS_AFLAGS)
87874+
87875 obj-y := main.o version.o mounts.o
87876 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
87877 obj-y += noinitramfs.o
87878diff --git a/init/do_mounts.c b/init/do_mounts.c
87879index 82f2288..ea1430a 100644
87880--- a/init/do_mounts.c
87881+++ b/init/do_mounts.c
87882@@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
87883 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
87884 {
87885 struct super_block *s;
87886- int err = sys_mount(name, "/root", fs, flags, data);
87887+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
87888 if (err)
87889 return err;
87890
87891- sys_chdir("/root");
87892+ sys_chdir((const char __force_user *)"/root");
87893 s = current->fs->pwd.dentry->d_sb;
87894 ROOT_DEV = s->s_dev;
87895 printk(KERN_INFO
87896@@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
87897 va_start(args, fmt);
87898 vsprintf(buf, fmt, args);
87899 va_end(args);
87900- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
87901+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
87902 if (fd >= 0) {
87903 sys_ioctl(fd, FDEJECT, 0);
87904 sys_close(fd);
87905 }
87906 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
87907- fd = sys_open("/dev/console", O_RDWR, 0);
87908+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
87909 if (fd >= 0) {
87910 sys_ioctl(fd, TCGETS, (long)&termios);
87911 termios.c_lflag &= ~ICANON;
87912 sys_ioctl(fd, TCSETSF, (long)&termios);
87913- sys_read(fd, &c, 1);
87914+ sys_read(fd, (char __user *)&c, 1);
87915 termios.c_lflag |= ICANON;
87916 sys_ioctl(fd, TCSETSF, (long)&termios);
87917 sys_close(fd);
87918@@ -589,8 +589,8 @@ void __init prepare_namespace(void)
87919 mount_root();
87920 out:
87921 devtmpfs_mount("dev");
87922- sys_mount(".", "/", NULL, MS_MOVE, NULL);
87923- sys_chroot(".");
87924+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87925+ sys_chroot((const char __force_user *)".");
87926 }
87927
87928 static bool is_tmpfs;
87929diff --git a/init/do_mounts.h b/init/do_mounts.h
87930index f5b978a..69dbfe8 100644
87931--- a/init/do_mounts.h
87932+++ b/init/do_mounts.h
87933@@ -15,15 +15,15 @@ extern int root_mountflags;
87934
87935 static inline int create_dev(char *name, dev_t dev)
87936 {
87937- sys_unlink(name);
87938- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
87939+ sys_unlink((char __force_user *)name);
87940+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
87941 }
87942
87943 #if BITS_PER_LONG == 32
87944 static inline u32 bstat(char *name)
87945 {
87946 struct stat64 stat;
87947- if (sys_stat64(name, &stat) != 0)
87948+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
87949 return 0;
87950 if (!S_ISBLK(stat.st_mode))
87951 return 0;
87952@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
87953 static inline u32 bstat(char *name)
87954 {
87955 struct stat stat;
87956- if (sys_newstat(name, &stat) != 0)
87957+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
87958 return 0;
87959 if (!S_ISBLK(stat.st_mode))
87960 return 0;
87961diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
87962index 3e0878e..8a9d7a0 100644
87963--- a/init/do_mounts_initrd.c
87964+++ b/init/do_mounts_initrd.c
87965@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
87966 {
87967 sys_unshare(CLONE_FS | CLONE_FILES);
87968 /* stdin/stdout/stderr for /linuxrc */
87969- sys_open("/dev/console", O_RDWR, 0);
87970+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
87971 sys_dup(0);
87972 sys_dup(0);
87973 /* move initrd over / and chdir/chroot in initrd root */
87974- sys_chdir("/root");
87975- sys_mount(".", "/", NULL, MS_MOVE, NULL);
87976- sys_chroot(".");
87977+ sys_chdir((const char __force_user *)"/root");
87978+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87979+ sys_chroot((const char __force_user *)".");
87980 sys_setsid();
87981 return 0;
87982 }
87983@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
87984 create_dev("/dev/root.old", Root_RAM0);
87985 /* mount initrd on rootfs' /root */
87986 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
87987- sys_mkdir("/old", 0700);
87988- sys_chdir("/old");
87989+ sys_mkdir((const char __force_user *)"/old", 0700);
87990+ sys_chdir((const char __force_user *)"/old");
87991
87992 /* try loading default modules from initrd */
87993 load_default_modules();
87994@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
87995 current->flags &= ~PF_FREEZER_SKIP;
87996
87997 /* move initrd to rootfs' /old */
87998- sys_mount("..", ".", NULL, MS_MOVE, NULL);
87999+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
88000 /* switch root and cwd back to / of rootfs */
88001- sys_chroot("..");
88002+ sys_chroot((const char __force_user *)"..");
88003
88004 if (new_decode_dev(real_root_dev) == Root_RAM0) {
88005- sys_chdir("/old");
88006+ sys_chdir((const char __force_user *)"/old");
88007 return;
88008 }
88009
88010- sys_chdir("/");
88011+ sys_chdir((const char __force_user *)"/");
88012 ROOT_DEV = new_decode_dev(real_root_dev);
88013 mount_root();
88014
88015 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
88016- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
88017+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
88018 if (!error)
88019 printk("okay\n");
88020 else {
88021- int fd = sys_open("/dev/root.old", O_RDWR, 0);
88022+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
88023 if (error == -ENOENT)
88024 printk("/initrd does not exist. Ignored.\n");
88025 else
88026 printk("failed\n");
88027 printk(KERN_NOTICE "Unmounting old root\n");
88028- sys_umount("/old", MNT_DETACH);
88029+ sys_umount((char __force_user *)"/old", MNT_DETACH);
88030 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
88031 if (fd < 0) {
88032 error = fd;
88033@@ -127,11 +127,11 @@ int __init initrd_load(void)
88034 * mounted in the normal path.
88035 */
88036 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
88037- sys_unlink("/initrd.image");
88038+ sys_unlink((const char __force_user *)"/initrd.image");
88039 handle_initrd();
88040 return 1;
88041 }
88042 }
88043- sys_unlink("/initrd.image");
88044+ sys_unlink((const char __force_user *)"/initrd.image");
88045 return 0;
88046 }
88047diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
88048index 8cb6db5..d729f50 100644
88049--- a/init/do_mounts_md.c
88050+++ b/init/do_mounts_md.c
88051@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
88052 partitioned ? "_d" : "", minor,
88053 md_setup_args[ent].device_names);
88054
88055- fd = sys_open(name, 0, 0);
88056+ fd = sys_open((char __force_user *)name, 0, 0);
88057 if (fd < 0) {
88058 printk(KERN_ERR "md: open failed - cannot start "
88059 "array %s\n", name);
88060@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
88061 * array without it
88062 */
88063 sys_close(fd);
88064- fd = sys_open(name, 0, 0);
88065+ fd = sys_open((char __force_user *)name, 0, 0);
88066 sys_ioctl(fd, BLKRRPART, 0);
88067 }
88068 sys_close(fd);
88069@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
88070
88071 wait_for_device_probe();
88072
88073- fd = sys_open("/dev/md0", 0, 0);
88074+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
88075 if (fd >= 0) {
88076 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
88077 sys_close(fd);
88078diff --git a/init/init_task.c b/init/init_task.c
88079index ba0a7f36..2bcf1d5 100644
88080--- a/init/init_task.c
88081+++ b/init/init_task.c
88082@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
88083 * Initial thread structure. Alignment of this is handled by a special
88084 * linker map entry.
88085 */
88086+#ifdef CONFIG_X86
88087+union thread_union init_thread_union __init_task_data;
88088+#else
88089 union thread_union init_thread_union __init_task_data =
88090 { INIT_THREAD_INFO(init_task) };
88091+#endif
88092diff --git a/init/initramfs.c b/init/initramfs.c
88093index bece48c..e911bd8 100644
88094--- a/init/initramfs.c
88095+++ b/init/initramfs.c
88096@@ -25,7 +25,7 @@ static ssize_t __init xwrite(int fd, const char *p, size_t count)
88097
88098 /* sys_write only can write MAX_RW_COUNT aka 2G-4K bytes at most */
88099 while (count) {
88100- ssize_t rv = sys_write(fd, p, count);
88101+ ssize_t rv = sys_write(fd, (char __force_user *)p, count);
88102
88103 if (rv < 0) {
88104 if (rv == -EINTR || rv == -EAGAIN)
88105@@ -107,7 +107,7 @@ static void __init free_hash(void)
88106 }
88107 }
88108
88109-static long __init do_utime(char *filename, time_t mtime)
88110+static long __init do_utime(char __force_user *filename, time_t mtime)
88111 {
88112 struct timespec t[2];
88113
88114@@ -142,7 +142,7 @@ static void __init dir_utime(void)
88115 struct dir_entry *de, *tmp;
88116 list_for_each_entry_safe(de, tmp, &dir_list, list) {
88117 list_del(&de->list);
88118- do_utime(de->name, de->mtime);
88119+ do_utime((char __force_user *)de->name, de->mtime);
88120 kfree(de->name);
88121 kfree(de);
88122 }
88123@@ -304,7 +304,7 @@ static int __init maybe_link(void)
88124 if (nlink >= 2) {
88125 char *old = find_link(major, minor, ino, mode, collected);
88126 if (old)
88127- return (sys_link(old, collected) < 0) ? -1 : 1;
88128+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
88129 }
88130 return 0;
88131 }
88132@@ -313,11 +313,11 @@ static void __init clean_path(char *path, umode_t mode)
88133 {
88134 struct stat st;
88135
88136- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
88137+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
88138 if (S_ISDIR(st.st_mode))
88139- sys_rmdir(path);
88140+ sys_rmdir((char __force_user *)path);
88141 else
88142- sys_unlink(path);
88143+ sys_unlink((char __force_user *)path);
88144 }
88145 }
88146
88147@@ -338,7 +338,7 @@ static int __init do_name(void)
88148 int openflags = O_WRONLY|O_CREAT;
88149 if (ml != 1)
88150 openflags |= O_TRUNC;
88151- wfd = sys_open(collected, openflags, mode);
88152+ wfd = sys_open((char __force_user *)collected, openflags, mode);
88153
88154 if (wfd >= 0) {
88155 sys_fchown(wfd, uid, gid);
88156@@ -350,17 +350,17 @@ static int __init do_name(void)
88157 }
88158 }
88159 } else if (S_ISDIR(mode)) {
88160- sys_mkdir(collected, mode);
88161- sys_chown(collected, uid, gid);
88162- sys_chmod(collected, mode);
88163+ sys_mkdir((char __force_user *)collected, mode);
88164+ sys_chown((char __force_user *)collected, uid, gid);
88165+ sys_chmod((char __force_user *)collected, mode);
88166 dir_add(collected, mtime);
88167 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
88168 S_ISFIFO(mode) || S_ISSOCK(mode)) {
88169 if (maybe_link() == 0) {
88170- sys_mknod(collected, mode, rdev);
88171- sys_chown(collected, uid, gid);
88172- sys_chmod(collected, mode);
88173- do_utime(collected, mtime);
88174+ sys_mknod((char __force_user *)collected, mode, rdev);
88175+ sys_chown((char __force_user *)collected, uid, gid);
88176+ sys_chmod((char __force_user *)collected, mode);
88177+ do_utime((char __force_user *)collected, mtime);
88178 }
88179 }
88180 return 0;
88181@@ -372,7 +372,7 @@ static int __init do_copy(void)
88182 if (xwrite(wfd, victim, body_len) != body_len)
88183 error("write error");
88184 sys_close(wfd);
88185- do_utime(vcollected, mtime);
88186+ do_utime((char __force_user *)vcollected, mtime);
88187 kfree(vcollected);
88188 eat(body_len);
88189 state = SkipIt;
88190@@ -390,9 +390,9 @@ static int __init do_symlink(void)
88191 {
88192 collected[N_ALIGN(name_len) + body_len] = '\0';
88193 clean_path(collected, 0);
88194- sys_symlink(collected + N_ALIGN(name_len), collected);
88195- sys_lchown(collected, uid, gid);
88196- do_utime(collected, mtime);
88197+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
88198+ sys_lchown((char __force_user *)collected, uid, gid);
88199+ do_utime((char __force_user *)collected, mtime);
88200 state = SkipIt;
88201 next_state = Reset;
88202 return 0;
88203diff --git a/init/main.c b/init/main.c
88204index d0f4b59..0c4b184 100644
88205--- a/init/main.c
88206+++ b/init/main.c
88207@@ -98,6 +98,8 @@ extern void radix_tree_init(void);
88208 static inline void mark_rodata_ro(void) { }
88209 #endif
88210
88211+extern void grsecurity_init(void);
88212+
88213 /*
88214 * Debug helper: via this flag we know that we are in 'early bootup code'
88215 * where only the boot processor is running with IRQ disabled. This means
88216@@ -159,6 +161,75 @@ static int __init set_reset_devices(char *str)
88217
88218 __setup("reset_devices", set_reset_devices);
88219
88220+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
88221+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
88222+static int __init setup_grsec_proc_gid(char *str)
88223+{
88224+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
88225+ return 1;
88226+}
88227+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
88228+#endif
88229+
88230+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
88231+unsigned long pax_user_shadow_base __read_only;
88232+EXPORT_SYMBOL(pax_user_shadow_base);
88233+extern char pax_enter_kernel_user[];
88234+extern char pax_exit_kernel_user[];
88235+#endif
88236+
88237+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
88238+static int __init setup_pax_nouderef(char *str)
88239+{
88240+#ifdef CONFIG_X86_32
88241+ unsigned int cpu;
88242+ struct desc_struct *gdt;
88243+
88244+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
88245+ gdt = get_cpu_gdt_table(cpu);
88246+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
88247+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
88248+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
88249+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
88250+ }
88251+ loadsegment(ds, __KERNEL_DS);
88252+ loadsegment(es, __KERNEL_DS);
88253+ loadsegment(ss, __KERNEL_DS);
88254+#else
88255+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
88256+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
88257+ clone_pgd_mask = ~(pgdval_t)0UL;
88258+ pax_user_shadow_base = 0UL;
88259+ setup_clear_cpu_cap(X86_FEATURE_PCID);
88260+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
88261+#endif
88262+
88263+ return 0;
88264+}
88265+early_param("pax_nouderef", setup_pax_nouderef);
88266+
88267+#ifdef CONFIG_X86_64
88268+static int __init setup_pax_weakuderef(char *str)
88269+{
88270+ if (clone_pgd_mask != ~(pgdval_t)0UL)
88271+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
88272+ return 1;
88273+}
88274+__setup("pax_weakuderef", setup_pax_weakuderef);
88275+#endif
88276+#endif
88277+
88278+#ifdef CONFIG_PAX_SOFTMODE
88279+int pax_softmode;
88280+
88281+static int __init setup_pax_softmode(char *str)
88282+{
88283+ get_option(&str, &pax_softmode);
88284+ return 1;
88285+}
88286+__setup("pax_softmode=", setup_pax_softmode);
88287+#endif
88288+
88289 static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
88290 const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
88291 static const char *panic_later, *panic_param;
88292@@ -728,7 +799,7 @@ static bool __init_or_module initcall_blacklisted(initcall_t fn)
88293 struct blacklist_entry *entry;
88294 char *fn_name;
88295
88296- fn_name = kasprintf(GFP_KERNEL, "%pf", fn);
88297+ fn_name = kasprintf(GFP_KERNEL, "%pX", fn);
88298 if (!fn_name)
88299 return false;
88300
88301@@ -780,7 +851,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
88302 {
88303 int count = preempt_count();
88304 int ret;
88305- char msgbuf[64];
88306+ const char *msg1 = "", *msg2 = "";
88307
88308 if (initcall_blacklisted(fn))
88309 return -EPERM;
88310@@ -790,18 +861,17 @@ int __init_or_module do_one_initcall(initcall_t fn)
88311 else
88312 ret = fn();
88313
88314- msgbuf[0] = 0;
88315-
88316 if (preempt_count() != count) {
88317- sprintf(msgbuf, "preemption imbalance ");
88318+ msg1 = " preemption imbalance";
88319 preempt_count_set(count);
88320 }
88321 if (irqs_disabled()) {
88322- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
88323+ msg2 = " disabled interrupts";
88324 local_irq_enable();
88325 }
88326- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
88327+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
88328
88329+ add_latent_entropy();
88330 return ret;
88331 }
88332
88333@@ -908,8 +978,8 @@ static int run_init_process(const char *init_filename)
88334 {
88335 argv_init[0] = init_filename;
88336 return do_execve(getname_kernel(init_filename),
88337- (const char __user *const __user *)argv_init,
88338- (const char __user *const __user *)envp_init);
88339+ (const char __user *const __force_user *)argv_init,
88340+ (const char __user *const __force_user *)envp_init);
88341 }
88342
88343 static int try_to_run_init_process(const char *init_filename)
88344@@ -926,6 +996,10 @@ static int try_to_run_init_process(const char *init_filename)
88345 return ret;
88346 }
88347
88348+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
88349+extern int gr_init_ran;
88350+#endif
88351+
88352 static noinline void __init kernel_init_freeable(void);
88353
88354 static int __ref kernel_init(void *unused)
88355@@ -950,6 +1024,11 @@ static int __ref kernel_init(void *unused)
88356 ramdisk_execute_command, ret);
88357 }
88358
88359+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
88360+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
88361+ gr_init_ran = 1;
88362+#endif
88363+
88364 /*
88365 * We try each of these until one succeeds.
88366 *
88367@@ -1005,7 +1084,7 @@ static noinline void __init kernel_init_freeable(void)
88368 do_basic_setup();
88369
88370 /* Open the /dev/console on the rootfs, this should never fail */
88371- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
88372+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
88373 pr_err("Warning: unable to open an initial console.\n");
88374
88375 (void) sys_dup(0);
88376@@ -1018,11 +1097,13 @@ static noinline void __init kernel_init_freeable(void)
88377 if (!ramdisk_execute_command)
88378 ramdisk_execute_command = "/init";
88379
88380- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
88381+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
88382 ramdisk_execute_command = NULL;
88383 prepare_namespace();
88384 }
88385
88386+ grsecurity_init();
88387+
88388 /*
88389 * Ok, we have completed the initial bootup, and
88390 * we're essentially up and running. Get rid of the
88391diff --git a/ipc/compat.c b/ipc/compat.c
88392index b5ef4f7..ff31d87 100644
88393--- a/ipc/compat.c
88394+++ b/ipc/compat.c
88395@@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
88396 COMPAT_SHMLBA);
88397 if (err < 0)
88398 return err;
88399- return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
88400+ return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
88401 }
88402 case SHMDT:
88403 return sys_shmdt(compat_ptr(ptr));
88404diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
88405index e8075b2..76f2c6a 100644
88406--- a/ipc/ipc_sysctl.c
88407+++ b/ipc/ipc_sysctl.c
88408@@ -30,7 +30,7 @@ static void *get_ipc(struct ctl_table *table)
88409 static int proc_ipc_dointvec(struct ctl_table *table, int write,
88410 void __user *buffer, size_t *lenp, loff_t *ppos)
88411 {
88412- struct ctl_table ipc_table;
88413+ ctl_table_no_const ipc_table;
88414
88415 memcpy(&ipc_table, table, sizeof(ipc_table));
88416 ipc_table.data = get_ipc(table);
88417@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(struct ctl_table *table, int write,
88418 static int proc_ipc_dointvec_minmax(struct ctl_table *table, int write,
88419 void __user *buffer, size_t *lenp, loff_t *ppos)
88420 {
88421- struct ctl_table ipc_table;
88422+ ctl_table_no_const ipc_table;
88423
88424 memcpy(&ipc_table, table, sizeof(ipc_table));
88425 ipc_table.data = get_ipc(table);
88426@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
88427 static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
88428 void __user *buffer, size_t *lenp, loff_t *ppos)
88429 {
88430- struct ctl_table ipc_table;
88431+ ctl_table_no_const ipc_table;
88432 size_t lenp_bef = *lenp;
88433 int rc;
88434
88435@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
88436 static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
88437 void __user *buffer, size_t *lenp, loff_t *ppos)
88438 {
88439- struct ctl_table ipc_table;
88440+ ctl_table_no_const ipc_table;
88441 memcpy(&ipc_table, table, sizeof(ipc_table));
88442 ipc_table.data = get_ipc(table);
88443
88444@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
88445 static int proc_ipcauto_dointvec_minmax(struct ctl_table *table, int write,
88446 void __user *buffer, size_t *lenp, loff_t *ppos)
88447 {
88448- struct ctl_table ipc_table;
88449+ ctl_table_no_const ipc_table;
88450 int oldval;
88451 int rc;
88452
88453diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
88454index 68d4e95..1477ded 100644
88455--- a/ipc/mq_sysctl.c
88456+++ b/ipc/mq_sysctl.c
88457@@ -25,7 +25,7 @@ static void *get_mq(struct ctl_table *table)
88458 static int proc_mq_dointvec(struct ctl_table *table, int write,
88459 void __user *buffer, size_t *lenp, loff_t *ppos)
88460 {
88461- struct ctl_table mq_table;
88462+ ctl_table_no_const mq_table;
88463 memcpy(&mq_table, table, sizeof(mq_table));
88464 mq_table.data = get_mq(table);
88465
88466@@ -35,7 +35,7 @@ static int proc_mq_dointvec(struct ctl_table *table, int write,
88467 static int proc_mq_dointvec_minmax(struct ctl_table *table, int write,
88468 void __user *buffer, size_t *lenp, loff_t *ppos)
88469 {
88470- struct ctl_table mq_table;
88471+ ctl_table_no_const mq_table;
88472 memcpy(&mq_table, table, sizeof(mq_table));
88473 mq_table.data = get_mq(table);
88474
88475diff --git a/ipc/mqueue.c b/ipc/mqueue.c
88476index 4fcf39a..d3cc2ec 100644
88477--- a/ipc/mqueue.c
88478+++ b/ipc/mqueue.c
88479@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
88480 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
88481 info->attr.mq_msgsize);
88482
88483+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
88484 spin_lock(&mq_lock);
88485 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
88486 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
88487diff --git a/ipc/shm.c b/ipc/shm.c
88488index 7fc9f9f..95e201f 100644
88489--- a/ipc/shm.c
88490+++ b/ipc/shm.c
88491@@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
88492 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
88493 #endif
88494
88495+#ifdef CONFIG_GRKERNSEC
88496+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
88497+ const u64 shm_createtime, const kuid_t cuid,
88498+ const int shmid);
88499+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
88500+ const u64 shm_createtime);
88501+#endif
88502+
88503 void shm_init_ns(struct ipc_namespace *ns)
88504 {
88505 ns->shm_ctlmax = SHMMAX;
88506@@ -559,6 +567,9 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
88507 shp->shm_lprid = 0;
88508 shp->shm_atim = shp->shm_dtim = 0;
88509 shp->shm_ctim = get_seconds();
88510+#ifdef CONFIG_GRKERNSEC
88511+ shp->shm_createtime = ktime_get_ns();
88512+#endif
88513 shp->shm_segsz = size;
88514 shp->shm_nattch = 0;
88515 shp->shm_file = file;
88516@@ -1095,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88517 f_mode = FMODE_READ | FMODE_WRITE;
88518 }
88519 if (shmflg & SHM_EXEC) {
88520+
88521+#ifdef CONFIG_PAX_MPROTECT
88522+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
88523+ goto out;
88524+#endif
88525+
88526 prot |= PROT_EXEC;
88527 acc_mode |= S_IXUGO;
88528 }
88529@@ -1119,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88530 if (err)
88531 goto out_unlock;
88532
88533+#ifdef CONFIG_GRKERNSEC
88534+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
88535+ shp->shm_perm.cuid, shmid) ||
88536+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
88537+ err = -EACCES;
88538+ goto out_unlock;
88539+ }
88540+#endif
88541+
88542 ipc_lock_object(&shp->shm_perm);
88543
88544 /* check if shm_destroy() is tearing down shp */
88545@@ -1131,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88546 path = shp->shm_file->f_path;
88547 path_get(&path);
88548 shp->shm_nattch++;
88549+#ifdef CONFIG_GRKERNSEC
88550+ shp->shm_lapid = current->pid;
88551+#endif
88552 size = i_size_read(path.dentry->d_inode);
88553 ipc_unlock_object(&shp->shm_perm);
88554 rcu_read_unlock();
88555diff --git a/ipc/util.c b/ipc/util.c
88556index 27d74e6..8be0be2 100644
88557--- a/ipc/util.c
88558+++ b/ipc/util.c
88559@@ -71,6 +71,8 @@ struct ipc_proc_iface {
88560 int (*show)(struct seq_file *, void *);
88561 };
88562
88563+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
88564+
88565 static void ipc_memory_notifier(struct work_struct *work)
88566 {
88567 ipcns_notify(IPCNS_MEMCHANGED);
88568@@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
88569 granted_mode >>= 6;
88570 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
88571 granted_mode >>= 3;
88572+
88573+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
88574+ return -1;
88575+
88576 /* is there some bit set in requested_mode but not in granted_mode? */
88577 if ((requested_mode & ~granted_mode & 0007) &&
88578 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
88579diff --git a/kernel/audit.c b/kernel/audit.c
88580index 6726aa6..bb864a9 100644
88581--- a/kernel/audit.c
88582+++ b/kernel/audit.c
88583@@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
88584 3) suppressed due to audit_rate_limit
88585 4) suppressed due to audit_backlog_limit
88586 */
88587-static atomic_t audit_lost = ATOMIC_INIT(0);
88588+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
88589
88590 /* The netlink socket. */
88591 static struct sock *audit_sock;
88592@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
88593 unsigned long now;
88594 int print;
88595
88596- atomic_inc(&audit_lost);
88597+ atomic_inc_unchecked(&audit_lost);
88598
88599 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
88600
88601@@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
88602 if (print) {
88603 if (printk_ratelimit())
88604 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
88605- atomic_read(&audit_lost),
88606+ atomic_read_unchecked(&audit_lost),
88607 audit_rate_limit,
88608 audit_backlog_limit);
88609 audit_panic(message);
88610@@ -840,7 +840,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
88611 s.pid = audit_pid;
88612 s.rate_limit = audit_rate_limit;
88613 s.backlog_limit = audit_backlog_limit;
88614- s.lost = atomic_read(&audit_lost);
88615+ s.lost = atomic_read_unchecked(&audit_lost);
88616 s.backlog = skb_queue_len(&audit_skb_queue);
88617 s.version = AUDIT_VERSION_LATEST;
88618 s.backlog_wait_time = audit_backlog_wait_time;
88619diff --git a/kernel/auditsc.c b/kernel/auditsc.c
88620index 21eae3c..66db239 100644
88621--- a/kernel/auditsc.c
88622+++ b/kernel/auditsc.c
88623@@ -2023,7 +2023,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
88624 }
88625
88626 /* global counter which is incremented every time something logs in */
88627-static atomic_t session_id = ATOMIC_INIT(0);
88628+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
88629
88630 static int audit_set_loginuid_perm(kuid_t loginuid)
88631 {
88632@@ -2090,7 +2090,7 @@ int audit_set_loginuid(kuid_t loginuid)
88633
88634 /* are we setting or clearing? */
88635 if (uid_valid(loginuid))
88636- sessionid = (unsigned int)atomic_inc_return(&session_id);
88637+ sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
88638
88639 task->sessionid = sessionid;
88640 task->loginuid = loginuid;
88641diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
88642index 7f0dbcb..b54bb2c 100644
88643--- a/kernel/bpf/core.c
88644+++ b/kernel/bpf/core.c
88645@@ -22,6 +22,7 @@
88646 */
88647 #include <linux/filter.h>
88648 #include <linux/skbuff.h>
88649+#include <linux/vmalloc.h>
88650 #include <asm/unaligned.h>
88651
88652 /* Registers */
88653@@ -63,6 +64,67 @@ void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, int k, uns
88654 return NULL;
88655 }
88656
88657+struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags)
88658+{
88659+ gfp_t gfp_flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO |
88660+ gfp_extra_flags;
88661+ struct bpf_work_struct *ws;
88662+ struct bpf_prog *fp;
88663+
88664+ size = round_up(size, PAGE_SIZE);
88665+ fp = __vmalloc(size, gfp_flags, PAGE_KERNEL);
88666+ if (fp == NULL)
88667+ return NULL;
88668+
88669+ ws = kmalloc(sizeof(*ws), GFP_KERNEL | gfp_extra_flags);
88670+ if (ws == NULL) {
88671+ vfree(fp);
88672+ return NULL;
88673+ }
88674+
88675+ fp->pages = size / PAGE_SIZE;
88676+ fp->work = ws;
88677+
88678+ return fp;
88679+}
88680+EXPORT_SYMBOL_GPL(bpf_prog_alloc);
88681+
88682+struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size,
88683+ gfp_t gfp_extra_flags)
88684+{
88685+ gfp_t gfp_flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO |
88686+ gfp_extra_flags;
88687+ struct bpf_prog *fp;
88688+
88689+ BUG_ON(fp_old == NULL);
88690+
88691+ size = round_up(size, PAGE_SIZE);
88692+ if (size <= fp_old->pages * PAGE_SIZE)
88693+ return fp_old;
88694+
88695+ fp = __vmalloc(size, gfp_flags, PAGE_KERNEL);
88696+ if (fp != NULL) {
88697+ memcpy(fp, fp_old, fp_old->pages * PAGE_SIZE);
88698+ fp->pages = size / PAGE_SIZE;
88699+
88700+ /* We keep fp->work from fp_old around in the new
88701+ * reallocated structure.
88702+ */
88703+ fp_old->work = NULL;
88704+ __bpf_prog_free(fp_old);
88705+ }
88706+
88707+ return fp;
88708+}
88709+EXPORT_SYMBOL_GPL(bpf_prog_realloc);
88710+
88711+void __bpf_prog_free(struct bpf_prog *fp)
88712+{
88713+ kfree(fp->work);
88714+ vfree(fp);
88715+}
88716+EXPORT_SYMBOL_GPL(__bpf_prog_free);
88717+
88718 /* Base function for offset calculation. Needs to go into .text section,
88719 * therefore keeping it non-static as well; will also be used by JITs
88720 * anyway later on, so do not let the compiler omit it.
88721@@ -523,12 +585,26 @@ void bpf_prog_select_runtime(struct bpf_prog *fp)
88722
88723 /* Probe if internal BPF can be JITed */
88724 bpf_int_jit_compile(fp);
88725+ /* Lock whole bpf_prog as read-only */
88726+ bpf_prog_lock_ro(fp);
88727 }
88728 EXPORT_SYMBOL_GPL(bpf_prog_select_runtime);
88729
88730-/* free internal BPF program */
88731+static void bpf_prog_free_deferred(struct work_struct *work)
88732+{
88733+ struct bpf_work_struct *ws;
88734+
88735+ ws = container_of(work, struct bpf_work_struct, work);
88736+ bpf_jit_free(ws->prog);
88737+}
88738+
88739+/* Free internal BPF program */
88740 void bpf_prog_free(struct bpf_prog *fp)
88741 {
88742- bpf_jit_free(fp);
88743+ struct bpf_work_struct *ws = fp->work;
88744+
88745+ INIT_WORK(&ws->work, bpf_prog_free_deferred);
88746+ ws->prog = fp;
88747+ schedule_work(&ws->work);
88748 }
88749 EXPORT_SYMBOL_GPL(bpf_prog_free);
88750diff --git a/kernel/capability.c b/kernel/capability.c
88751index 989f5bf..d317ca0 100644
88752--- a/kernel/capability.c
88753+++ b/kernel/capability.c
88754@@ -192,6 +192,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
88755 * before modification is attempted and the application
88756 * fails.
88757 */
88758+ if (tocopy > ARRAY_SIZE(kdata))
88759+ return -EFAULT;
88760+
88761 if (copy_to_user(dataptr, kdata, tocopy
88762 * sizeof(struct __user_cap_data_struct))) {
88763 return -EFAULT;
88764@@ -297,10 +300,11 @@ bool has_ns_capability(struct task_struct *t,
88765 int ret;
88766
88767 rcu_read_lock();
88768- ret = security_capable(__task_cred(t), ns, cap);
88769+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
88770+ gr_task_is_capable(t, __task_cred(t), cap);
88771 rcu_read_unlock();
88772
88773- return (ret == 0);
88774+ return ret;
88775 }
88776
88777 /**
88778@@ -337,10 +341,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
88779 int ret;
88780
88781 rcu_read_lock();
88782- ret = security_capable_noaudit(__task_cred(t), ns, cap);
88783+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
88784 rcu_read_unlock();
88785
88786- return (ret == 0);
88787+ return ret;
88788 }
88789
88790 /**
88791@@ -378,7 +382,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
88792 BUG();
88793 }
88794
88795- if (security_capable(current_cred(), ns, cap) == 0) {
88796+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
88797 current->flags |= PF_SUPERPRIV;
88798 return true;
88799 }
88800@@ -386,6 +390,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
88801 }
88802 EXPORT_SYMBOL(ns_capable);
88803
88804+bool ns_capable_nolog(struct user_namespace *ns, int cap)
88805+{
88806+ if (unlikely(!cap_valid(cap))) {
88807+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
88808+ BUG();
88809+ }
88810+
88811+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
88812+ current->flags |= PF_SUPERPRIV;
88813+ return true;
88814+ }
88815+ return false;
88816+}
88817+EXPORT_SYMBOL(ns_capable_nolog);
88818+
88819 /**
88820 * file_ns_capable - Determine if the file's opener had a capability in effect
88821 * @file: The file we want to check
88822@@ -427,6 +446,12 @@ bool capable(int cap)
88823 }
88824 EXPORT_SYMBOL(capable);
88825
88826+bool capable_nolog(int cap)
88827+{
88828+ return ns_capable_nolog(&init_user_ns, cap);
88829+}
88830+EXPORT_SYMBOL(capable_nolog);
88831+
88832 /**
88833 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
88834 * @inode: The inode in question
88835@@ -444,3 +469,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
88836 kgid_has_mapping(ns, inode->i_gid);
88837 }
88838 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
88839+
88840+bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
88841+{
88842+ struct user_namespace *ns = current_user_ns();
88843+
88844+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
88845+ kgid_has_mapping(ns, inode->i_gid);
88846+}
88847+EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
88848diff --git a/kernel/cgroup.c b/kernel/cgroup.c
88849index 3a73f99..4f29fea 100644
88850--- a/kernel/cgroup.c
88851+++ b/kernel/cgroup.c
88852@@ -5341,6 +5341,14 @@ static void cgroup_release_agent(struct work_struct *work)
88853 release_list);
88854 list_del_init(&cgrp->release_list);
88855 raw_spin_unlock(&release_list_lock);
88856+
88857+ /*
88858+ * don't bother calling call_usermodehelper if we haven't
88859+ * configured a binary to execute
88860+ */
88861+ if (cgrp->root->release_agent_path[0] == '\0')
88862+ goto continue_free;
88863+
88864 pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
88865 if (!pathbuf)
88866 goto continue_free;
88867@@ -5539,7 +5547,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
88868 struct task_struct *task;
88869 int count = 0;
88870
88871- seq_printf(seq, "css_set %p\n", cset);
88872+ seq_printf(seq, "css_set %pK\n", cset);
88873
88874 list_for_each_entry(task, &cset->tasks, cg_list) {
88875 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
88876diff --git a/kernel/compat.c b/kernel/compat.c
88877index ebb3c36..1df606e 100644
88878--- a/kernel/compat.c
88879+++ b/kernel/compat.c
88880@@ -13,6 +13,7 @@
88881
88882 #include <linux/linkage.h>
88883 #include <linux/compat.h>
88884+#include <linux/module.h>
88885 #include <linux/errno.h>
88886 #include <linux/time.h>
88887 #include <linux/signal.h>
88888@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
88889 mm_segment_t oldfs;
88890 long ret;
88891
88892- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
88893+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
88894 oldfs = get_fs();
88895 set_fs(KERNEL_DS);
88896 ret = hrtimer_nanosleep_restart(restart);
88897@@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
88898 oldfs = get_fs();
88899 set_fs(KERNEL_DS);
88900 ret = hrtimer_nanosleep(&tu,
88901- rmtp ? (struct timespec __user *)&rmt : NULL,
88902+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
88903 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
88904 set_fs(oldfs);
88905
88906@@ -379,7 +380,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
88907 mm_segment_t old_fs = get_fs();
88908
88909 set_fs(KERNEL_DS);
88910- ret = sys_sigpending((old_sigset_t __user *) &s);
88911+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
88912 set_fs(old_fs);
88913 if (ret == 0)
88914 ret = put_user(s, set);
88915@@ -469,7 +470,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
88916 mm_segment_t old_fs = get_fs();
88917
88918 set_fs(KERNEL_DS);
88919- ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
88920+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
88921 set_fs(old_fs);
88922
88923 if (!ret) {
88924@@ -551,8 +552,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
88925 set_fs (KERNEL_DS);
88926 ret = sys_wait4(pid,
88927 (stat_addr ?
88928- (unsigned int __user *) &status : NULL),
88929- options, (struct rusage __user *) &r);
88930+ (unsigned int __force_user *) &status : NULL),
88931+ options, (struct rusage __force_user *) &r);
88932 set_fs (old_fs);
88933
88934 if (ret > 0) {
88935@@ -578,8 +579,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
88936 memset(&info, 0, sizeof(info));
88937
88938 set_fs(KERNEL_DS);
88939- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
88940- uru ? (struct rusage __user *)&ru : NULL);
88941+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
88942+ uru ? (struct rusage __force_user *)&ru : NULL);
88943 set_fs(old_fs);
88944
88945 if ((ret < 0) || (info.si_signo == 0))
88946@@ -713,8 +714,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
88947 oldfs = get_fs();
88948 set_fs(KERNEL_DS);
88949 err = sys_timer_settime(timer_id, flags,
88950- (struct itimerspec __user *) &newts,
88951- (struct itimerspec __user *) &oldts);
88952+ (struct itimerspec __force_user *) &newts,
88953+ (struct itimerspec __force_user *) &oldts);
88954 set_fs(oldfs);
88955 if (!err && old && put_compat_itimerspec(old, &oldts))
88956 return -EFAULT;
88957@@ -731,7 +732,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
88958 oldfs = get_fs();
88959 set_fs(KERNEL_DS);
88960 err = sys_timer_gettime(timer_id,
88961- (struct itimerspec __user *) &ts);
88962+ (struct itimerspec __force_user *) &ts);
88963 set_fs(oldfs);
88964 if (!err && put_compat_itimerspec(setting, &ts))
88965 return -EFAULT;
88966@@ -750,7 +751,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
88967 oldfs = get_fs();
88968 set_fs(KERNEL_DS);
88969 err = sys_clock_settime(which_clock,
88970- (struct timespec __user *) &ts);
88971+ (struct timespec __force_user *) &ts);
88972 set_fs(oldfs);
88973 return err;
88974 }
88975@@ -765,7 +766,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
88976 oldfs = get_fs();
88977 set_fs(KERNEL_DS);
88978 err = sys_clock_gettime(which_clock,
88979- (struct timespec __user *) &ts);
88980+ (struct timespec __force_user *) &ts);
88981 set_fs(oldfs);
88982 if (!err && compat_put_timespec(&ts, tp))
88983 return -EFAULT;
88984@@ -785,7 +786,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
88985
88986 oldfs = get_fs();
88987 set_fs(KERNEL_DS);
88988- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
88989+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
88990 set_fs(oldfs);
88991
88992 err = compat_put_timex(utp, &txc);
88993@@ -805,7 +806,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
88994 oldfs = get_fs();
88995 set_fs(KERNEL_DS);
88996 err = sys_clock_getres(which_clock,
88997- (struct timespec __user *) &ts);
88998+ (struct timespec __force_user *) &ts);
88999 set_fs(oldfs);
89000 if (!err && tp && compat_put_timespec(&ts, tp))
89001 return -EFAULT;
89002@@ -819,7 +820,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
89003 struct timespec tu;
89004 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
89005
89006- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
89007+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
89008 oldfs = get_fs();
89009 set_fs(KERNEL_DS);
89010 err = clock_nanosleep_restart(restart);
89011@@ -851,8 +852,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
89012 oldfs = get_fs();
89013 set_fs(KERNEL_DS);
89014 err = sys_clock_nanosleep(which_clock, flags,
89015- (struct timespec __user *) &in,
89016- (struct timespec __user *) &out);
89017+ (struct timespec __force_user *) &in,
89018+ (struct timespec __force_user *) &out);
89019 set_fs(oldfs);
89020
89021 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
89022@@ -1146,7 +1147,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
89023 mm_segment_t old_fs = get_fs();
89024
89025 set_fs(KERNEL_DS);
89026- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
89027+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
89028 set_fs(old_fs);
89029 if (compat_put_timespec(&t, interval))
89030 return -EFAULT;
89031diff --git a/kernel/configs.c b/kernel/configs.c
89032index c18b1f1..b9a0132 100644
89033--- a/kernel/configs.c
89034+++ b/kernel/configs.c
89035@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
89036 struct proc_dir_entry *entry;
89037
89038 /* create the current config file */
89039+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
89040+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
89041+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
89042+ &ikconfig_file_ops);
89043+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
89044+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
89045+ &ikconfig_file_ops);
89046+#endif
89047+#else
89048 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
89049 &ikconfig_file_ops);
89050+#endif
89051+
89052 if (!entry)
89053 return -ENOMEM;
89054
89055diff --git a/kernel/cred.c b/kernel/cred.c
89056index e0573a4..26c0fd3 100644
89057--- a/kernel/cred.c
89058+++ b/kernel/cred.c
89059@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
89060 validate_creds(cred);
89061 alter_cred_subscribers(cred, -1);
89062 put_cred(cred);
89063+
89064+#ifdef CONFIG_GRKERNSEC_SETXID
89065+ cred = (struct cred *) tsk->delayed_cred;
89066+ if (cred != NULL) {
89067+ tsk->delayed_cred = NULL;
89068+ validate_creds(cred);
89069+ alter_cred_subscribers(cred, -1);
89070+ put_cred(cred);
89071+ }
89072+#endif
89073 }
89074
89075 /**
89076@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
89077 * Always returns 0 thus allowing this function to be tail-called at the end
89078 * of, say, sys_setgid().
89079 */
89080-int commit_creds(struct cred *new)
89081+static int __commit_creds(struct cred *new)
89082 {
89083 struct task_struct *task = current;
89084 const struct cred *old = task->real_cred;
89085@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
89086
89087 get_cred(new); /* we will require a ref for the subj creds too */
89088
89089+ gr_set_role_label(task, new->uid, new->gid);
89090+
89091 /* dumpability changes */
89092 if (!uid_eq(old->euid, new->euid) ||
89093 !gid_eq(old->egid, new->egid) ||
89094@@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
89095 put_cred(old);
89096 return 0;
89097 }
89098+#ifdef CONFIG_GRKERNSEC_SETXID
89099+extern int set_user(struct cred *new);
89100+
89101+void gr_delayed_cred_worker(void)
89102+{
89103+ const struct cred *new = current->delayed_cred;
89104+ struct cred *ncred;
89105+
89106+ current->delayed_cred = NULL;
89107+
89108+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
89109+ // from doing get_cred on it when queueing this
89110+ put_cred(new);
89111+ return;
89112+ } else if (new == NULL)
89113+ return;
89114+
89115+ ncred = prepare_creds();
89116+ if (!ncred)
89117+ goto die;
89118+ // uids
89119+ ncred->uid = new->uid;
89120+ ncred->euid = new->euid;
89121+ ncred->suid = new->suid;
89122+ ncred->fsuid = new->fsuid;
89123+ // gids
89124+ ncred->gid = new->gid;
89125+ ncred->egid = new->egid;
89126+ ncred->sgid = new->sgid;
89127+ ncred->fsgid = new->fsgid;
89128+ // groups
89129+ set_groups(ncred, new->group_info);
89130+ // caps
89131+ ncred->securebits = new->securebits;
89132+ ncred->cap_inheritable = new->cap_inheritable;
89133+ ncred->cap_permitted = new->cap_permitted;
89134+ ncred->cap_effective = new->cap_effective;
89135+ ncred->cap_bset = new->cap_bset;
89136+
89137+ if (set_user(ncred)) {
89138+ abort_creds(ncred);
89139+ goto die;
89140+ }
89141+
89142+ // from doing get_cred on it when queueing this
89143+ put_cred(new);
89144+
89145+ __commit_creds(ncred);
89146+ return;
89147+die:
89148+ // from doing get_cred on it when queueing this
89149+ put_cred(new);
89150+ do_group_exit(SIGKILL);
89151+}
89152+#endif
89153+
89154+int commit_creds(struct cred *new)
89155+{
89156+#ifdef CONFIG_GRKERNSEC_SETXID
89157+ int ret;
89158+ int schedule_it = 0;
89159+ struct task_struct *t;
89160+ unsigned oldsecurebits = current_cred()->securebits;
89161+
89162+ /* we won't get called with tasklist_lock held for writing
89163+ and interrupts disabled as the cred struct in that case is
89164+ init_cred
89165+ */
89166+ if (grsec_enable_setxid && !current_is_single_threaded() &&
89167+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
89168+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
89169+ schedule_it = 1;
89170+ }
89171+ ret = __commit_creds(new);
89172+ if (schedule_it) {
89173+ rcu_read_lock();
89174+ read_lock(&tasklist_lock);
89175+ for (t = next_thread(current); t != current;
89176+ t = next_thread(t)) {
89177+ /* we'll check if the thread has uid 0 in
89178+ * the delayed worker routine
89179+ */
89180+ if (task_securebits(t) == oldsecurebits &&
89181+ t->delayed_cred == NULL) {
89182+ t->delayed_cred = get_cred(new);
89183+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
89184+ set_tsk_need_resched(t);
89185+ }
89186+ }
89187+ read_unlock(&tasklist_lock);
89188+ rcu_read_unlock();
89189+ }
89190+
89191+ return ret;
89192+#else
89193+ return __commit_creds(new);
89194+#endif
89195+}
89196+
89197 EXPORT_SYMBOL(commit_creds);
89198
89199 /**
89200diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
89201index 1adf62b..7736e06 100644
89202--- a/kernel/debug/debug_core.c
89203+++ b/kernel/debug/debug_core.c
89204@@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
89205 */
89206 static atomic_t masters_in_kgdb;
89207 static atomic_t slaves_in_kgdb;
89208-static atomic_t kgdb_break_tasklet_var;
89209+static atomic_unchecked_t kgdb_break_tasklet_var;
89210 atomic_t kgdb_setting_breakpoint;
89211
89212 struct task_struct *kgdb_usethread;
89213@@ -134,7 +134,7 @@ int kgdb_single_step;
89214 static pid_t kgdb_sstep_pid;
89215
89216 /* to keep track of the CPU which is doing the single stepping*/
89217-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
89218+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
89219
89220 /*
89221 * If you are debugging a problem where roundup (the collection of
89222@@ -549,7 +549,7 @@ return_normal:
89223 * kernel will only try for the value of sstep_tries before
89224 * giving up and continuing on.
89225 */
89226- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
89227+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
89228 (kgdb_info[cpu].task &&
89229 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
89230 atomic_set(&kgdb_active, -1);
89231@@ -647,8 +647,8 @@ cpu_master_loop:
89232 }
89233
89234 kgdb_restore:
89235- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
89236- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
89237+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
89238+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
89239 if (kgdb_info[sstep_cpu].task)
89240 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
89241 else
89242@@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
89243 static void kgdb_tasklet_bpt(unsigned long ing)
89244 {
89245 kgdb_breakpoint();
89246- atomic_set(&kgdb_break_tasklet_var, 0);
89247+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
89248 }
89249
89250 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
89251
89252 void kgdb_schedule_breakpoint(void)
89253 {
89254- if (atomic_read(&kgdb_break_tasklet_var) ||
89255+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
89256 atomic_read(&kgdb_active) != -1 ||
89257 atomic_read(&kgdb_setting_breakpoint))
89258 return;
89259- atomic_inc(&kgdb_break_tasklet_var);
89260+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
89261 tasklet_schedule(&kgdb_tasklet_breakpoint);
89262 }
89263 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
89264diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
89265index 379650b..30c5180 100644
89266--- a/kernel/debug/kdb/kdb_main.c
89267+++ b/kernel/debug/kdb/kdb_main.c
89268@@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
89269 continue;
89270
89271 kdb_printf("%-20s%8u 0x%p ", mod->name,
89272- mod->core_size, (void *)mod);
89273+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
89274 #ifdef CONFIG_MODULE_UNLOAD
89275 kdb_printf("%4ld ", module_refcount(mod));
89276 #endif
89277@@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
89278 kdb_printf(" (Loading)");
89279 else
89280 kdb_printf(" (Live)");
89281- kdb_printf(" 0x%p", mod->module_core);
89282+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
89283
89284 #ifdef CONFIG_MODULE_UNLOAD
89285 {
89286diff --git a/kernel/events/core.c b/kernel/events/core.c
89287index 658f232..32e9595 100644
89288--- a/kernel/events/core.c
89289+++ b/kernel/events/core.c
89290@@ -161,8 +161,15 @@ static struct srcu_struct pmus_srcu;
89291 * 0 - disallow raw tracepoint access for unpriv
89292 * 1 - disallow cpu events for unpriv
89293 * 2 - disallow kernel profiling for unpriv
89294+ * 3 - disallow all unpriv perf event use
89295 */
89296-int sysctl_perf_event_paranoid __read_mostly = 1;
89297+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89298+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
89299+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
89300+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
89301+#else
89302+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
89303+#endif
89304
89305 /* Minimum for 512 kiB + 1 user control page */
89306 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
89307@@ -188,7 +195,7 @@ void update_perf_cpu_limits(void)
89308
89309 tmp *= sysctl_perf_cpu_time_max_percent;
89310 do_div(tmp, 100);
89311- ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
89312+ ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
89313 }
89314
89315 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
89316@@ -294,7 +301,7 @@ void perf_sample_event_took(u64 sample_len_ns)
89317 }
89318 }
89319
89320-static atomic64_t perf_event_id;
89321+static atomic64_unchecked_t perf_event_id;
89322
89323 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
89324 enum event_type_t event_type);
89325@@ -3051,7 +3058,7 @@ static void __perf_event_read(void *info)
89326
89327 static inline u64 perf_event_count(struct perf_event *event)
89328 {
89329- return local64_read(&event->count) + atomic64_read(&event->child_count);
89330+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
89331 }
89332
89333 static u64 perf_event_read(struct perf_event *event)
89334@@ -3430,9 +3437,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
89335 mutex_lock(&event->child_mutex);
89336 total += perf_event_read(event);
89337 *enabled += event->total_time_enabled +
89338- atomic64_read(&event->child_total_time_enabled);
89339+ atomic64_read_unchecked(&event->child_total_time_enabled);
89340 *running += event->total_time_running +
89341- atomic64_read(&event->child_total_time_running);
89342+ atomic64_read_unchecked(&event->child_total_time_running);
89343
89344 list_for_each_entry(child, &event->child_list, child_list) {
89345 total += perf_event_read(child);
89346@@ -3881,10 +3888,10 @@ void perf_event_update_userpage(struct perf_event *event)
89347 userpg->offset -= local64_read(&event->hw.prev_count);
89348
89349 userpg->time_enabled = enabled +
89350- atomic64_read(&event->child_total_time_enabled);
89351+ atomic64_read_unchecked(&event->child_total_time_enabled);
89352
89353 userpg->time_running = running +
89354- atomic64_read(&event->child_total_time_running);
89355+ atomic64_read_unchecked(&event->child_total_time_running);
89356
89357 arch_perf_update_userpage(userpg, now);
89358
89359@@ -4448,7 +4455,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
89360
89361 /* Data. */
89362 sp = perf_user_stack_pointer(regs);
89363- rem = __output_copy_user(handle, (void *) sp, dump_size);
89364+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
89365 dyn_size = dump_size - rem;
89366
89367 perf_output_skip(handle, rem);
89368@@ -4539,11 +4546,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
89369 values[n++] = perf_event_count(event);
89370 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
89371 values[n++] = enabled +
89372- atomic64_read(&event->child_total_time_enabled);
89373+ atomic64_read_unchecked(&event->child_total_time_enabled);
89374 }
89375 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
89376 values[n++] = running +
89377- atomic64_read(&event->child_total_time_running);
89378+ atomic64_read_unchecked(&event->child_total_time_running);
89379 }
89380 if (read_format & PERF_FORMAT_ID)
89381 values[n++] = primary_event_id(event);
89382@@ -6858,7 +6865,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
89383 event->parent = parent_event;
89384
89385 event->ns = get_pid_ns(task_active_pid_ns(current));
89386- event->id = atomic64_inc_return(&perf_event_id);
89387+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
89388
89389 event->state = PERF_EVENT_STATE_INACTIVE;
89390
89391@@ -7137,6 +7144,11 @@ SYSCALL_DEFINE5(perf_event_open,
89392 if (flags & ~PERF_FLAG_ALL)
89393 return -EINVAL;
89394
89395+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89396+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
89397+ return -EACCES;
89398+#endif
89399+
89400 err = perf_copy_attr(attr_uptr, &attr);
89401 if (err)
89402 return err;
89403@@ -7489,10 +7501,10 @@ static void sync_child_event(struct perf_event *child_event,
89404 /*
89405 * Add back the child's count to the parent's count:
89406 */
89407- atomic64_add(child_val, &parent_event->child_count);
89408- atomic64_add(child_event->total_time_enabled,
89409+ atomic64_add_unchecked(child_val, &parent_event->child_count);
89410+ atomic64_add_unchecked(child_event->total_time_enabled,
89411 &parent_event->child_total_time_enabled);
89412- atomic64_add(child_event->total_time_running,
89413+ atomic64_add_unchecked(child_event->total_time_running,
89414 &parent_event->child_total_time_running);
89415
89416 /*
89417diff --git a/kernel/events/internal.h b/kernel/events/internal.h
89418index 569b2187..19940d9 100644
89419--- a/kernel/events/internal.h
89420+++ b/kernel/events/internal.h
89421@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
89422 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
89423 }
89424
89425-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
89426+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
89427 static inline unsigned long \
89428 func_name(struct perf_output_handle *handle, \
89429- const void *buf, unsigned long len) \
89430+ const void user *buf, unsigned long len) \
89431 { \
89432 unsigned long size, written; \
89433 \
89434@@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
89435 return 0;
89436 }
89437
89438-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
89439+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
89440
89441 static inline unsigned long
89442 memcpy_skip(void *dst, const void *src, unsigned long n)
89443@@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
89444 return 0;
89445 }
89446
89447-DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
89448+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
89449
89450 #ifndef arch_perf_out_copy_user
89451 #define arch_perf_out_copy_user arch_perf_out_copy_user
89452@@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
89453 }
89454 #endif
89455
89456-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
89457+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
89458
89459 /* Callchain handling */
89460 extern struct perf_callchain_entry *
89461diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
89462index ed8f2cd..fe8030c 100644
89463--- a/kernel/events/uprobes.c
89464+++ b/kernel/events/uprobes.c
89465@@ -1670,7 +1670,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
89466 {
89467 struct page *page;
89468 uprobe_opcode_t opcode;
89469- int result;
89470+ long result;
89471
89472 pagefault_disable();
89473 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
89474diff --git a/kernel/exit.c b/kernel/exit.c
89475index 32c58f7..9eb6907 100644
89476--- a/kernel/exit.c
89477+++ b/kernel/exit.c
89478@@ -173,6 +173,10 @@ void release_task(struct task_struct *p)
89479 struct task_struct *leader;
89480 int zap_leader;
89481 repeat:
89482+#ifdef CONFIG_NET
89483+ gr_del_task_from_ip_table(p);
89484+#endif
89485+
89486 /* don't need to get the RCU readlock here - the process is dead and
89487 * can't be modifying its own credentials. But shut RCU-lockdep up */
89488 rcu_read_lock();
89489@@ -668,6 +672,8 @@ void do_exit(long code)
89490 struct task_struct *tsk = current;
89491 int group_dead;
89492
89493+ set_fs(USER_DS);
89494+
89495 profile_task_exit(tsk);
89496
89497 WARN_ON(blk_needs_flush_plug(tsk));
89498@@ -684,7 +690,6 @@ void do_exit(long code)
89499 * mm_release()->clear_child_tid() from writing to a user-controlled
89500 * kernel address.
89501 */
89502- set_fs(USER_DS);
89503
89504 ptrace_event(PTRACE_EVENT_EXIT, code);
89505
89506@@ -742,6 +747,9 @@ void do_exit(long code)
89507 tsk->exit_code = code;
89508 taskstats_exit(tsk, group_dead);
89509
89510+ gr_acl_handle_psacct(tsk, code);
89511+ gr_acl_handle_exit();
89512+
89513 exit_mm(tsk);
89514
89515 if (group_dead)
89516@@ -859,7 +867,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
89517 * Take down every thread in the group. This is called by fatal signals
89518 * as well as by sys_exit_group (below).
89519 */
89520-void
89521+__noreturn void
89522 do_group_exit(int exit_code)
89523 {
89524 struct signal_struct *sig = current->signal;
89525diff --git a/kernel/fork.c b/kernel/fork.c
89526index a91e47d..71c9064 100644
89527--- a/kernel/fork.c
89528+++ b/kernel/fork.c
89529@@ -183,6 +183,48 @@ void thread_info_cache_init(void)
89530 # endif
89531 #endif
89532
89533+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89534+static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
89535+ int node, void **lowmem_stack)
89536+{
89537+ struct page *pages[THREAD_SIZE / PAGE_SIZE];
89538+ void *ret = NULL;
89539+ unsigned int i;
89540+
89541+ *lowmem_stack = alloc_thread_info_node(tsk, node);
89542+ if (*lowmem_stack == NULL)
89543+ goto out;
89544+
89545+ for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
89546+ pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
89547+
89548+ /* use VM_IOREMAP to gain THREAD_SIZE alignment */
89549+ ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
89550+ if (ret == NULL) {
89551+ free_thread_info(*lowmem_stack);
89552+ *lowmem_stack = NULL;
89553+ }
89554+
89555+out:
89556+ return ret;
89557+}
89558+
89559+static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
89560+{
89561+ unmap_process_stacks(tsk);
89562+}
89563+#else
89564+static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
89565+ int node, void **lowmem_stack)
89566+{
89567+ return alloc_thread_info_node(tsk, node);
89568+}
89569+static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
89570+{
89571+ free_thread_info(ti);
89572+}
89573+#endif
89574+
89575 /* SLAB cache for signal_struct structures (tsk->signal) */
89576 static struct kmem_cache *signal_cachep;
89577
89578@@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
89579 /* SLAB cache for mm_struct structures (tsk->mm) */
89580 static struct kmem_cache *mm_cachep;
89581
89582-static void account_kernel_stack(struct thread_info *ti, int account)
89583+static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
89584 {
89585+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89586+ struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
89587+#else
89588 struct zone *zone = page_zone(virt_to_page(ti));
89589+#endif
89590
89591 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
89592 }
89593
89594 void free_task(struct task_struct *tsk)
89595 {
89596- account_kernel_stack(tsk->stack, -1);
89597+ account_kernel_stack(tsk, tsk->stack, -1);
89598 arch_release_thread_info(tsk->stack);
89599- free_thread_info(tsk->stack);
89600+ gr_free_thread_info(tsk, tsk->stack);
89601 rt_mutex_debug_task_free(tsk);
89602 ftrace_graph_exit_task(tsk);
89603 put_seccomp_filter(tsk);
89604@@ -299,6 +345,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89605 struct task_struct *tsk;
89606 struct thread_info *ti;
89607 unsigned long *stackend;
89608+ void *lowmem_stack;
89609 int node = tsk_fork_get_node(orig);
89610 int err;
89611
89612@@ -306,7 +353,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89613 if (!tsk)
89614 return NULL;
89615
89616- ti = alloc_thread_info_node(tsk, node);
89617+ ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
89618 if (!ti)
89619 goto free_tsk;
89620
89621@@ -315,6 +362,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89622 goto free_ti;
89623
89624 tsk->stack = ti;
89625+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89626+ tsk->lowmem_stack = lowmem_stack;
89627+#endif
89628 #ifdef CONFIG_SECCOMP
89629 /*
89630 * We must handle setting up seccomp filters once we're under
89631@@ -332,7 +382,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89632 *stackend = STACK_END_MAGIC; /* for overflow detection */
89633
89634 #ifdef CONFIG_CC_STACKPROTECTOR
89635- tsk->stack_canary = get_random_int();
89636+ tsk->stack_canary = pax_get_random_long();
89637 #endif
89638
89639 /*
89640@@ -346,24 +396,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89641 tsk->splice_pipe = NULL;
89642 tsk->task_frag.page = NULL;
89643
89644- account_kernel_stack(ti, 1);
89645+ account_kernel_stack(tsk, ti, 1);
89646
89647 return tsk;
89648
89649 free_ti:
89650- free_thread_info(ti);
89651+ gr_free_thread_info(tsk, ti);
89652 free_tsk:
89653 free_task_struct(tsk);
89654 return NULL;
89655 }
89656
89657 #ifdef CONFIG_MMU
89658-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89659+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
89660+{
89661+ struct vm_area_struct *tmp;
89662+ unsigned long charge;
89663+ struct file *file;
89664+ int retval;
89665+
89666+ charge = 0;
89667+ if (mpnt->vm_flags & VM_ACCOUNT) {
89668+ unsigned long len = vma_pages(mpnt);
89669+
89670+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89671+ goto fail_nomem;
89672+ charge = len;
89673+ }
89674+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89675+ if (!tmp)
89676+ goto fail_nomem;
89677+ *tmp = *mpnt;
89678+ tmp->vm_mm = mm;
89679+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
89680+ retval = vma_dup_policy(mpnt, tmp);
89681+ if (retval)
89682+ goto fail_nomem_policy;
89683+ if (anon_vma_fork(tmp, mpnt))
89684+ goto fail_nomem_anon_vma_fork;
89685+ tmp->vm_flags &= ~VM_LOCKED;
89686+ tmp->vm_next = tmp->vm_prev = NULL;
89687+ tmp->vm_mirror = NULL;
89688+ file = tmp->vm_file;
89689+ if (file) {
89690+ struct inode *inode = file_inode(file);
89691+ struct address_space *mapping = file->f_mapping;
89692+
89693+ get_file(file);
89694+ if (tmp->vm_flags & VM_DENYWRITE)
89695+ atomic_dec(&inode->i_writecount);
89696+ mutex_lock(&mapping->i_mmap_mutex);
89697+ if (tmp->vm_flags & VM_SHARED)
89698+ atomic_inc(&mapping->i_mmap_writable);
89699+ flush_dcache_mmap_lock(mapping);
89700+ /* insert tmp into the share list, just after mpnt */
89701+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89702+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
89703+ else
89704+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
89705+ flush_dcache_mmap_unlock(mapping);
89706+ mutex_unlock(&mapping->i_mmap_mutex);
89707+ }
89708+
89709+ /*
89710+ * Clear hugetlb-related page reserves for children. This only
89711+ * affects MAP_PRIVATE mappings. Faults generated by the child
89712+ * are not guaranteed to succeed, even if read-only
89713+ */
89714+ if (is_vm_hugetlb_page(tmp))
89715+ reset_vma_resv_huge_pages(tmp);
89716+
89717+ return tmp;
89718+
89719+fail_nomem_anon_vma_fork:
89720+ mpol_put(vma_policy(tmp));
89721+fail_nomem_policy:
89722+ kmem_cache_free(vm_area_cachep, tmp);
89723+fail_nomem:
89724+ vm_unacct_memory(charge);
89725+ return NULL;
89726+}
89727+
89728+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89729 {
89730 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
89731 struct rb_node **rb_link, *rb_parent;
89732 int retval;
89733- unsigned long charge;
89734
89735 uprobe_start_dup_mmap();
89736 down_write(&oldmm->mmap_sem);
89737@@ -391,55 +509,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89738
89739 prev = NULL;
89740 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
89741- struct file *file;
89742-
89743 if (mpnt->vm_flags & VM_DONTCOPY) {
89744 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
89745 -vma_pages(mpnt));
89746 continue;
89747 }
89748- charge = 0;
89749- if (mpnt->vm_flags & VM_ACCOUNT) {
89750- unsigned long len = vma_pages(mpnt);
89751-
89752- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89753- goto fail_nomem;
89754- charge = len;
89755- }
89756- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89757- if (!tmp)
89758- goto fail_nomem;
89759- *tmp = *mpnt;
89760- INIT_LIST_HEAD(&tmp->anon_vma_chain);
89761- retval = vma_dup_policy(mpnt, tmp);
89762- if (retval)
89763- goto fail_nomem_policy;
89764- tmp->vm_mm = mm;
89765- if (anon_vma_fork(tmp, mpnt))
89766- goto fail_nomem_anon_vma_fork;
89767- tmp->vm_flags &= ~VM_LOCKED;
89768- tmp->vm_next = tmp->vm_prev = NULL;
89769- file = tmp->vm_file;
89770- if (file) {
89771- struct inode *inode = file_inode(file);
89772- struct address_space *mapping = file->f_mapping;
89773-
89774- get_file(file);
89775- if (tmp->vm_flags & VM_DENYWRITE)
89776- atomic_dec(&inode->i_writecount);
89777- mutex_lock(&mapping->i_mmap_mutex);
89778- if (tmp->vm_flags & VM_SHARED)
89779- atomic_inc(&mapping->i_mmap_writable);
89780- flush_dcache_mmap_lock(mapping);
89781- /* insert tmp into the share list, just after mpnt */
89782- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89783- vma_nonlinear_insert(tmp,
89784- &mapping->i_mmap_nonlinear);
89785- else
89786- vma_interval_tree_insert_after(tmp, mpnt,
89787- &mapping->i_mmap);
89788- flush_dcache_mmap_unlock(mapping);
89789- mutex_unlock(&mapping->i_mmap_mutex);
89790+ tmp = dup_vma(mm, oldmm, mpnt);
89791+ if (!tmp) {
89792+ retval = -ENOMEM;
89793+ goto out;
89794 }
89795
89796 /*
89797@@ -471,6 +549,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89798 if (retval)
89799 goto out;
89800 }
89801+
89802+#ifdef CONFIG_PAX_SEGMEXEC
89803+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
89804+ struct vm_area_struct *mpnt_m;
89805+
89806+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
89807+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
89808+
89809+ if (!mpnt->vm_mirror)
89810+ continue;
89811+
89812+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
89813+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
89814+ mpnt->vm_mirror = mpnt_m;
89815+ } else {
89816+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
89817+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
89818+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
89819+ mpnt->vm_mirror->vm_mirror = mpnt;
89820+ }
89821+ }
89822+ BUG_ON(mpnt_m);
89823+ }
89824+#endif
89825+
89826 /* a new mm has just been created */
89827 arch_dup_mmap(oldmm, mm);
89828 retval = 0;
89829@@ -480,14 +583,6 @@ out:
89830 up_write(&oldmm->mmap_sem);
89831 uprobe_end_dup_mmap();
89832 return retval;
89833-fail_nomem_anon_vma_fork:
89834- mpol_put(vma_policy(tmp));
89835-fail_nomem_policy:
89836- kmem_cache_free(vm_area_cachep, tmp);
89837-fail_nomem:
89838- retval = -ENOMEM;
89839- vm_unacct_memory(charge);
89840- goto out;
89841 }
89842
89843 static inline int mm_alloc_pgd(struct mm_struct *mm)
89844@@ -729,8 +824,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
89845 return ERR_PTR(err);
89846
89847 mm = get_task_mm(task);
89848- if (mm && mm != current->mm &&
89849- !ptrace_may_access(task, mode)) {
89850+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
89851+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
89852 mmput(mm);
89853 mm = ERR_PTR(-EACCES);
89854 }
89855@@ -933,13 +1028,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
89856 spin_unlock(&fs->lock);
89857 return -EAGAIN;
89858 }
89859- fs->users++;
89860+ atomic_inc(&fs->users);
89861 spin_unlock(&fs->lock);
89862 return 0;
89863 }
89864 tsk->fs = copy_fs_struct(fs);
89865 if (!tsk->fs)
89866 return -ENOMEM;
89867+ /* Carry through gr_chroot_dentry and is_chrooted instead
89868+ of recomputing it here. Already copied when the task struct
89869+ is duplicated. This allows pivot_root to not be treated as
89870+ a chroot
89871+ */
89872+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
89873+
89874 return 0;
89875 }
89876
89877@@ -1173,7 +1275,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
89878 * parts of the process environment (as per the clone
89879 * flags). The actual kick-off is left to the caller.
89880 */
89881-static struct task_struct *copy_process(unsigned long clone_flags,
89882+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
89883 unsigned long stack_start,
89884 unsigned long stack_size,
89885 int __user *child_tidptr,
89886@@ -1244,6 +1346,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89887 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
89888 #endif
89889 retval = -EAGAIN;
89890+
89891+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
89892+
89893 if (atomic_read(&p->real_cred->user->processes) >=
89894 task_rlimit(p, RLIMIT_NPROC)) {
89895 if (p->real_cred->user != INIT_USER &&
89896@@ -1493,6 +1598,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89897 goto bad_fork_free_pid;
89898 }
89899
89900+ /* synchronizes with gr_set_acls()
89901+ we need to call this past the point of no return for fork()
89902+ */
89903+ gr_copy_label(p);
89904+
89905 if (likely(p->pid)) {
89906 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
89907
89908@@ -1583,6 +1693,8 @@ bad_fork_cleanup_count:
89909 bad_fork_free:
89910 free_task(p);
89911 fork_out:
89912+ gr_log_forkfail(retval);
89913+
89914 return ERR_PTR(retval);
89915 }
89916
89917@@ -1644,6 +1756,7 @@ long do_fork(unsigned long clone_flags,
89918
89919 p = copy_process(clone_flags, stack_start, stack_size,
89920 child_tidptr, NULL, trace);
89921+ add_latent_entropy();
89922 /*
89923 * Do this prior waking up the new thread - the thread pointer
89924 * might get invalid after that point, if the thread exits quickly.
89925@@ -1660,6 +1773,8 @@ long do_fork(unsigned long clone_flags,
89926 if (clone_flags & CLONE_PARENT_SETTID)
89927 put_user(nr, parent_tidptr);
89928
89929+ gr_handle_brute_check();
89930+
89931 if (clone_flags & CLONE_VFORK) {
89932 p->vfork_done = &vfork;
89933 init_completion(&vfork);
89934@@ -1778,7 +1893,7 @@ void __init proc_caches_init(void)
89935 mm_cachep = kmem_cache_create("mm_struct",
89936 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
89937 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
89938- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
89939+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
89940 mmap_init();
89941 nsproxy_cache_init();
89942 }
89943@@ -1818,7 +1933,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
89944 return 0;
89945
89946 /* don't need lock here; in the worst case we'll do useless copy */
89947- if (fs->users == 1)
89948+ if (atomic_read(&fs->users) == 1)
89949 return 0;
89950
89951 *new_fsp = copy_fs_struct(fs);
89952@@ -1930,7 +2045,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
89953 fs = current->fs;
89954 spin_lock(&fs->lock);
89955 current->fs = new_fs;
89956- if (--fs->users)
89957+ gr_set_chroot_entries(current, &current->fs->root);
89958+ if (atomic_dec_return(&fs->users))
89959 new_fs = NULL;
89960 else
89961 new_fs = fs;
89962diff --git a/kernel/futex.c b/kernel/futex.c
89963index 22b3f1b..6820bc0 100644
89964--- a/kernel/futex.c
89965+++ b/kernel/futex.c
89966@@ -202,7 +202,7 @@ struct futex_pi_state {
89967 atomic_t refcount;
89968
89969 union futex_key key;
89970-};
89971+} __randomize_layout;
89972
89973 /**
89974 * struct futex_q - The hashed futex queue entry, one per waiting task
89975@@ -236,7 +236,7 @@ struct futex_q {
89976 struct rt_mutex_waiter *rt_waiter;
89977 union futex_key *requeue_pi_key;
89978 u32 bitset;
89979-};
89980+} __randomize_layout;
89981
89982 static const struct futex_q futex_q_init = {
89983 /* list gets initialized in queue_me()*/
89984@@ -396,6 +396,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
89985 struct page *page, *page_head;
89986 int err, ro = 0;
89987
89988+#ifdef CONFIG_PAX_SEGMEXEC
89989+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
89990+ return -EFAULT;
89991+#endif
89992+
89993 /*
89994 * The futex address must be "naturally" aligned.
89995 */
89996@@ -595,7 +600,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
89997
89998 static int get_futex_value_locked(u32 *dest, u32 __user *from)
89999 {
90000- int ret;
90001+ unsigned long ret;
90002
90003 pagefault_disable();
90004 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
90005@@ -3000,6 +3005,7 @@ static void __init futex_detect_cmpxchg(void)
90006 {
90007 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
90008 u32 curval;
90009+ mm_segment_t oldfs;
90010
90011 /*
90012 * This will fail and we want it. Some arch implementations do
90013@@ -3011,8 +3017,11 @@ static void __init futex_detect_cmpxchg(void)
90014 * implementation, the non-functional ones will return
90015 * -ENOSYS.
90016 */
90017+ oldfs = get_fs();
90018+ set_fs(USER_DS);
90019 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
90020 futex_cmpxchg_enabled = 1;
90021+ set_fs(oldfs);
90022 #endif
90023 }
90024
90025diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
90026index 55c8c93..9ba7ad6 100644
90027--- a/kernel/futex_compat.c
90028+++ b/kernel/futex_compat.c
90029@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
90030 return 0;
90031 }
90032
90033-static void __user *futex_uaddr(struct robust_list __user *entry,
90034+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
90035 compat_long_t futex_offset)
90036 {
90037 compat_uptr_t base = ptr_to_compat(entry);
90038diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
90039index b358a80..fc25240 100644
90040--- a/kernel/gcov/base.c
90041+++ b/kernel/gcov/base.c
90042@@ -114,11 +114,6 @@ void gcov_enable_events(void)
90043 }
90044
90045 #ifdef CONFIG_MODULES
90046-static inline int within(void *addr, void *start, unsigned long size)
90047-{
90048- return ((addr >= start) && (addr < start + size));
90049-}
90050-
90051 /* Update list and generate events when modules are unloaded. */
90052 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
90053 void *data)
90054@@ -133,7 +128,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
90055
90056 /* Remove entries located in module from linked list. */
90057 while ((info = gcov_info_next(info))) {
90058- if (within(info, mod->module_core, mod->core_size)) {
90059+ if (within_module_core_rw((unsigned long)info, mod)) {
90060 gcov_info_unlink(prev, info);
90061 if (gcov_events_enabled)
90062 gcov_event(GCOV_REMOVE, info);
90063diff --git a/kernel/jump_label.c b/kernel/jump_label.c
90064index 9019f15..9a3c42e 100644
90065--- a/kernel/jump_label.c
90066+++ b/kernel/jump_label.c
90067@@ -14,6 +14,7 @@
90068 #include <linux/err.h>
90069 #include <linux/static_key.h>
90070 #include <linux/jump_label_ratelimit.h>
90071+#include <linux/mm.h>
90072
90073 #ifdef HAVE_JUMP_LABEL
90074
90075@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
90076
90077 size = (((unsigned long)stop - (unsigned long)start)
90078 / sizeof(struct jump_entry));
90079+ pax_open_kernel();
90080 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
90081+ pax_close_kernel();
90082 }
90083
90084 static void jump_label_update(struct static_key *key, int enable);
90085@@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
90086 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
90087 struct jump_entry *iter;
90088
90089+ pax_open_kernel();
90090 for (iter = iter_start; iter < iter_stop; iter++) {
90091 if (within_module_init(iter->code, mod))
90092 iter->code = 0;
90093 }
90094+ pax_close_kernel();
90095 }
90096
90097 static int
90098diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
90099index ae51670..c1a9796 100644
90100--- a/kernel/kallsyms.c
90101+++ b/kernel/kallsyms.c
90102@@ -11,6 +11,9 @@
90103 * Changed the compression method from stem compression to "table lookup"
90104 * compression (see scripts/kallsyms.c for a more complete description)
90105 */
90106+#ifdef CONFIG_GRKERNSEC_HIDESYM
90107+#define __INCLUDED_BY_HIDESYM 1
90108+#endif
90109 #include <linux/kallsyms.h>
90110 #include <linux/module.h>
90111 #include <linux/init.h>
90112@@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
90113
90114 static inline int is_kernel_inittext(unsigned long addr)
90115 {
90116+ if (system_state != SYSTEM_BOOTING)
90117+ return 0;
90118+
90119 if (addr >= (unsigned long)_sinittext
90120 && addr <= (unsigned long)_einittext)
90121 return 1;
90122 return 0;
90123 }
90124
90125+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90126+#ifdef CONFIG_MODULES
90127+static inline int is_module_text(unsigned long addr)
90128+{
90129+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
90130+ return 1;
90131+
90132+ addr = ktla_ktva(addr);
90133+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
90134+}
90135+#else
90136+static inline int is_module_text(unsigned long addr)
90137+{
90138+ return 0;
90139+}
90140+#endif
90141+#endif
90142+
90143 static inline int is_kernel_text(unsigned long addr)
90144 {
90145 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
90146@@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
90147
90148 static inline int is_kernel(unsigned long addr)
90149 {
90150+
90151+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90152+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
90153+ return 1;
90154+
90155+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
90156+#else
90157 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
90158+#endif
90159+
90160 return 1;
90161 return in_gate_area_no_mm(addr);
90162 }
90163
90164 static int is_ksym_addr(unsigned long addr)
90165 {
90166+
90167+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90168+ if (is_module_text(addr))
90169+ return 0;
90170+#endif
90171+
90172 if (all_var)
90173 return is_kernel(addr);
90174
90175@@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
90176
90177 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
90178 {
90179- iter->name[0] = '\0';
90180 iter->nameoff = get_symbol_offset(new_pos);
90181 iter->pos = new_pos;
90182 }
90183@@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
90184 {
90185 struct kallsym_iter *iter = m->private;
90186
90187+#ifdef CONFIG_GRKERNSEC_HIDESYM
90188+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
90189+ return 0;
90190+#endif
90191+
90192 /* Some debugging symbols have no name. Ignore them. */
90193 if (!iter->name[0])
90194 return 0;
90195@@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
90196 */
90197 type = iter->exported ? toupper(iter->type) :
90198 tolower(iter->type);
90199+
90200 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
90201 type, iter->name, iter->module_name);
90202 } else
90203@@ -567,7 +611,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
90204 struct kallsym_iter *iter;
90205 int ret;
90206
90207- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
90208+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
90209 if (!iter)
90210 return -ENOMEM;
90211 reset_iter(iter, 0);
90212diff --git a/kernel/kcmp.c b/kernel/kcmp.c
90213index 0aa69ea..a7fcafb 100644
90214--- a/kernel/kcmp.c
90215+++ b/kernel/kcmp.c
90216@@ -100,6 +100,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
90217 struct task_struct *task1, *task2;
90218 int ret;
90219
90220+#ifdef CONFIG_GRKERNSEC
90221+ return -ENOSYS;
90222+#endif
90223+
90224 rcu_read_lock();
90225
90226 /*
90227diff --git a/kernel/kexec.c b/kernel/kexec.c
90228index 2bee072..8979af8 100644
90229--- a/kernel/kexec.c
90230+++ b/kernel/kexec.c
90231@@ -1349,7 +1349,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
90232 compat_ulong_t, flags)
90233 {
90234 struct compat_kexec_segment in;
90235- struct kexec_segment out, __user *ksegments;
90236+ struct kexec_segment out;
90237+ struct kexec_segment __user *ksegments;
90238 unsigned long i, result;
90239
90240 /* Don't allow clients that don't understand the native
90241diff --git a/kernel/kmod.c b/kernel/kmod.c
90242index 8637e04..8b1d0d8 100644
90243--- a/kernel/kmod.c
90244+++ b/kernel/kmod.c
90245@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
90246 kfree(info->argv);
90247 }
90248
90249-static int call_modprobe(char *module_name, int wait)
90250+static int call_modprobe(char *module_name, char *module_param, int wait)
90251 {
90252 struct subprocess_info *info;
90253 static char *envp[] = {
90254@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
90255 NULL
90256 };
90257
90258- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
90259+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
90260 if (!argv)
90261 goto out;
90262
90263@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
90264 argv[1] = "-q";
90265 argv[2] = "--";
90266 argv[3] = module_name; /* check free_modprobe_argv() */
90267- argv[4] = NULL;
90268+ argv[4] = module_param;
90269+ argv[5] = NULL;
90270
90271 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
90272 NULL, free_modprobe_argv, NULL);
90273@@ -129,9 +130,8 @@ out:
90274 * If module auto-loading support is disabled then this function
90275 * becomes a no-operation.
90276 */
90277-int __request_module(bool wait, const char *fmt, ...)
90278+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
90279 {
90280- va_list args;
90281 char module_name[MODULE_NAME_LEN];
90282 unsigned int max_modprobes;
90283 int ret;
90284@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
90285 if (!modprobe_path[0])
90286 return 0;
90287
90288- va_start(args, fmt);
90289- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
90290- va_end(args);
90291+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
90292 if (ret >= MODULE_NAME_LEN)
90293 return -ENAMETOOLONG;
90294
90295@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
90296 if (ret)
90297 return ret;
90298
90299+#ifdef CONFIG_GRKERNSEC_MODHARDEN
90300+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
90301+ /* hack to workaround consolekit/udisks stupidity */
90302+ read_lock(&tasklist_lock);
90303+ if (!strcmp(current->comm, "mount") &&
90304+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
90305+ read_unlock(&tasklist_lock);
90306+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
90307+ return -EPERM;
90308+ }
90309+ read_unlock(&tasklist_lock);
90310+ }
90311+#endif
90312+
90313 /* If modprobe needs a service that is in a module, we get a recursive
90314 * loop. Limit the number of running kmod threads to max_threads/2 or
90315 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
90316@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
90317
90318 trace_module_request(module_name, wait, _RET_IP_);
90319
90320- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
90321+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
90322
90323 atomic_dec(&kmod_concurrent);
90324 return ret;
90325 }
90326+
90327+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
90328+{
90329+ va_list args;
90330+ int ret;
90331+
90332+ va_start(args, fmt);
90333+ ret = ____request_module(wait, module_param, fmt, args);
90334+ va_end(args);
90335+
90336+ return ret;
90337+}
90338+
90339+int __request_module(bool wait, const char *fmt, ...)
90340+{
90341+ va_list args;
90342+ int ret;
90343+
90344+#ifdef CONFIG_GRKERNSEC_MODHARDEN
90345+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
90346+ char module_param[MODULE_NAME_LEN];
90347+
90348+ memset(module_param, 0, sizeof(module_param));
90349+
90350+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
90351+
90352+ va_start(args, fmt);
90353+ ret = ____request_module(wait, module_param, fmt, args);
90354+ va_end(args);
90355+
90356+ return ret;
90357+ }
90358+#endif
90359+
90360+ va_start(args, fmt);
90361+ ret = ____request_module(wait, NULL, fmt, args);
90362+ va_end(args);
90363+
90364+ return ret;
90365+}
90366+
90367 EXPORT_SYMBOL(__request_module);
90368 #endif /* CONFIG_MODULES */
90369
90370@@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
90371 */
90372 set_user_nice(current, 0);
90373
90374+#ifdef CONFIG_GRKERNSEC
90375+ /* this is race-free as far as userland is concerned as we copied
90376+ out the path to be used prior to this point and are now operating
90377+ on that copy
90378+ */
90379+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
90380+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
90381+ strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
90382+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
90383+ retval = -EPERM;
90384+ goto fail;
90385+ }
90386+#endif
90387+
90388 retval = -ENOMEM;
90389 new = prepare_kernel_cred(current);
90390 if (!new)
90391@@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
90392 commit_creds(new);
90393
90394 retval = do_execve(getname_kernel(sub_info->path),
90395- (const char __user *const __user *)sub_info->argv,
90396- (const char __user *const __user *)sub_info->envp);
90397+ (const char __user *const __force_user *)sub_info->argv,
90398+ (const char __user *const __force_user *)sub_info->envp);
90399 if (!retval)
90400 return 0;
90401
90402@@ -260,6 +327,10 @@ static int call_helper(void *data)
90403
90404 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
90405 {
90406+#ifdef CONFIG_GRKERNSEC
90407+ kfree(info->path);
90408+ info->path = info->origpath;
90409+#endif
90410 if (info->cleanup)
90411 (*info->cleanup)(info);
90412 kfree(info);
90413@@ -300,7 +371,7 @@ static int wait_for_helper(void *data)
90414 *
90415 * Thus the __user pointer cast is valid here.
90416 */
90417- sys_wait4(pid, (int __user *)&ret, 0, NULL);
90418+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
90419
90420 /*
90421 * If ret is 0, either ____call_usermodehelper failed and the
90422@@ -539,7 +610,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
90423 goto out;
90424
90425 INIT_WORK(&sub_info->work, __call_usermodehelper);
90426+#ifdef CONFIG_GRKERNSEC
90427+ sub_info->origpath = path;
90428+ sub_info->path = kstrdup(path, gfp_mask);
90429+#else
90430 sub_info->path = path;
90431+#endif
90432 sub_info->argv = argv;
90433 sub_info->envp = envp;
90434
90435@@ -647,7 +723,7 @@ EXPORT_SYMBOL(call_usermodehelper);
90436 static int proc_cap_handler(struct ctl_table *table, int write,
90437 void __user *buffer, size_t *lenp, loff_t *ppos)
90438 {
90439- struct ctl_table t;
90440+ ctl_table_no_const t;
90441 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
90442 kernel_cap_t new_cap;
90443 int err, i;
90444diff --git a/kernel/kprobes.c b/kernel/kprobes.c
90445index 3995f54..e247879 100644
90446--- a/kernel/kprobes.c
90447+++ b/kernel/kprobes.c
90448@@ -31,6 +31,9 @@
90449 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
90450 * <prasanna@in.ibm.com> added function-return probes.
90451 */
90452+#ifdef CONFIG_GRKERNSEC_HIDESYM
90453+#define __INCLUDED_BY_HIDESYM 1
90454+#endif
90455 #include <linux/kprobes.h>
90456 #include <linux/hash.h>
90457 #include <linux/init.h>
90458@@ -122,12 +125,12 @@ enum kprobe_slot_state {
90459
90460 static void *alloc_insn_page(void)
90461 {
90462- return module_alloc(PAGE_SIZE);
90463+ return module_alloc_exec(PAGE_SIZE);
90464 }
90465
90466 static void free_insn_page(void *page)
90467 {
90468- module_free(NULL, page);
90469+ module_free_exec(NULL, page);
90470 }
90471
90472 struct kprobe_insn_cache kprobe_insn_slots = {
90473@@ -2187,11 +2190,11 @@ static void report_probe(struct seq_file *pi, struct kprobe *p,
90474 kprobe_type = "k";
90475
90476 if (sym)
90477- seq_printf(pi, "%p %s %s+0x%x %s ",
90478+ seq_printf(pi, "%pK %s %s+0x%x %s ",
90479 p->addr, kprobe_type, sym, offset,
90480 (modname ? modname : " "));
90481 else
90482- seq_printf(pi, "%p %s %p ",
90483+ seq_printf(pi, "%pK %s %pK ",
90484 p->addr, kprobe_type, p->addr);
90485
90486 if (!pp)
90487diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
90488index 6683cce..daf8999 100644
90489--- a/kernel/ksysfs.c
90490+++ b/kernel/ksysfs.c
90491@@ -50,6 +50,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
90492 {
90493 if (count+1 > UEVENT_HELPER_PATH_LEN)
90494 return -ENOENT;
90495+ if (!capable(CAP_SYS_ADMIN))
90496+ return -EPERM;
90497 memcpy(uevent_helper, buf, count);
90498 uevent_helper[count] = '\0';
90499 if (count && uevent_helper[count-1] == '\n')
90500@@ -176,7 +178,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
90501 return count;
90502 }
90503
90504-static struct bin_attribute notes_attr = {
90505+static bin_attribute_no_const notes_attr __read_only = {
90506 .attr = {
90507 .name = "notes",
90508 .mode = S_IRUGO,
90509diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
90510index 88d0d44..e9ce0ee 100644
90511--- a/kernel/locking/lockdep.c
90512+++ b/kernel/locking/lockdep.c
90513@@ -599,6 +599,10 @@ static int static_obj(void *obj)
90514 end = (unsigned long) &_end,
90515 addr = (unsigned long) obj;
90516
90517+#ifdef CONFIG_PAX_KERNEXEC
90518+ start = ktla_ktva(start);
90519+#endif
90520+
90521 /*
90522 * static variable?
90523 */
90524@@ -740,6 +744,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
90525 if (!static_obj(lock->key)) {
90526 debug_locks_off();
90527 printk("INFO: trying to register non-static key.\n");
90528+ printk("lock:%pS key:%pS.\n", lock, lock->key);
90529 printk("the code is fine but needs lockdep annotation.\n");
90530 printk("turning off the locking correctness validator.\n");
90531 dump_stack();
90532@@ -3081,7 +3086,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
90533 if (!class)
90534 return 0;
90535 }
90536- atomic_inc((atomic_t *)&class->ops);
90537+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
90538 if (very_verbose(class)) {
90539 printk("\nacquire class [%p] %s", class->key, class->name);
90540 if (class->name_version > 1)
90541diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
90542index ef43ac4..2720dfa 100644
90543--- a/kernel/locking/lockdep_proc.c
90544+++ b/kernel/locking/lockdep_proc.c
90545@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
90546 return 0;
90547 }
90548
90549- seq_printf(m, "%p", class->key);
90550+ seq_printf(m, "%pK", class->key);
90551 #ifdef CONFIG_DEBUG_LOCKDEP
90552 seq_printf(m, " OPS:%8ld", class->ops);
90553 #endif
90554@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
90555
90556 list_for_each_entry(entry, &class->locks_after, entry) {
90557 if (entry->distance == 1) {
90558- seq_printf(m, " -> [%p] ", entry->class->key);
90559+ seq_printf(m, " -> [%pK] ", entry->class->key);
90560 print_name(m, entry->class);
90561 seq_puts(m, "\n");
90562 }
90563@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
90564 if (!class->key)
90565 continue;
90566
90567- seq_printf(m, "[%p] ", class->key);
90568+ seq_printf(m, "[%pK] ", class->key);
90569 print_name(m, class);
90570 seq_puts(m, "\n");
90571 }
90572@@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
90573 if (!i)
90574 seq_line(m, '-', 40-namelen, namelen);
90575
90576- snprintf(ip, sizeof(ip), "[<%p>]",
90577+ snprintf(ip, sizeof(ip), "[<%pK>]",
90578 (void *)class->contention_point[i]);
90579 seq_printf(m, "%40s %14lu %29s %pS\n",
90580 name, stats->contention_point[i],
90581@@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
90582 if (!i)
90583 seq_line(m, '-', 40-namelen, namelen);
90584
90585- snprintf(ip, sizeof(ip), "[<%p>]",
90586+ snprintf(ip, sizeof(ip), "[<%pK>]",
90587 (void *)class->contending_point[i]);
90588 seq_printf(m, "%40s %14lu %29s %pS\n",
90589 name, stats->contending_point[i],
90590diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
90591index 9887a90..0cd2b1d 100644
90592--- a/kernel/locking/mcs_spinlock.c
90593+++ b/kernel/locking/mcs_spinlock.c
90594@@ -100,7 +100,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
90595
90596 prev = decode_cpu(old);
90597 node->prev = prev;
90598- ACCESS_ONCE(prev->next) = node;
90599+ ACCESS_ONCE_RW(prev->next) = node;
90600
90601 /*
90602 * Normally @prev is untouchable after the above store; because at that
90603@@ -172,8 +172,8 @@ unqueue:
90604 * it will wait in Step-A.
90605 */
90606
90607- ACCESS_ONCE(next->prev) = prev;
90608- ACCESS_ONCE(prev->next) = next;
90609+ ACCESS_ONCE_RW(next->prev) = prev;
90610+ ACCESS_ONCE_RW(prev->next) = next;
90611
90612 return false;
90613 }
90614@@ -195,13 +195,13 @@ void osq_unlock(struct optimistic_spin_queue *lock)
90615 node = this_cpu_ptr(&osq_node);
90616 next = xchg(&node->next, NULL);
90617 if (next) {
90618- ACCESS_ONCE(next->locked) = 1;
90619+ ACCESS_ONCE_RW(next->locked) = 1;
90620 return;
90621 }
90622
90623 next = osq_wait_next(lock, node, NULL);
90624 if (next)
90625- ACCESS_ONCE(next->locked) = 1;
90626+ ACCESS_ONCE_RW(next->locked) = 1;
90627 }
90628
90629 #endif
90630diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
90631index 23e89c5..8558eac 100644
90632--- a/kernel/locking/mcs_spinlock.h
90633+++ b/kernel/locking/mcs_spinlock.h
90634@@ -81,7 +81,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
90635 */
90636 return;
90637 }
90638- ACCESS_ONCE(prev->next) = node;
90639+ ACCESS_ONCE_RW(prev->next) = node;
90640
90641 /* Wait until the lock holder passes the lock down. */
90642 arch_mcs_spin_lock_contended(&node->locked);
90643diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
90644index 5cf6731..ce3bc5a 100644
90645--- a/kernel/locking/mutex-debug.c
90646+++ b/kernel/locking/mutex-debug.c
90647@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
90648 }
90649
90650 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90651- struct thread_info *ti)
90652+ struct task_struct *task)
90653 {
90654 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
90655
90656 /* Mark the current thread as blocked on the lock: */
90657- ti->task->blocked_on = waiter;
90658+ task->blocked_on = waiter;
90659 }
90660
90661 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90662- struct thread_info *ti)
90663+ struct task_struct *task)
90664 {
90665 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
90666- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
90667- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
90668- ti->task->blocked_on = NULL;
90669+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
90670+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
90671+ task->blocked_on = NULL;
90672
90673 list_del_init(&waiter->list);
90674 waiter->task = NULL;
90675diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
90676index 0799fd3..d06ae3b 100644
90677--- a/kernel/locking/mutex-debug.h
90678+++ b/kernel/locking/mutex-debug.h
90679@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
90680 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
90681 extern void debug_mutex_add_waiter(struct mutex *lock,
90682 struct mutex_waiter *waiter,
90683- struct thread_info *ti);
90684+ struct task_struct *task);
90685 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90686- struct thread_info *ti);
90687+ struct task_struct *task);
90688 extern void debug_mutex_unlock(struct mutex *lock);
90689 extern void debug_mutex_init(struct mutex *lock, const char *name,
90690 struct lock_class_key *key);
90691diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
90692index ae712b2..d0d4a41 100644
90693--- a/kernel/locking/mutex.c
90694+++ b/kernel/locking/mutex.c
90695@@ -486,7 +486,7 @@ slowpath:
90696 goto skip_wait;
90697
90698 debug_mutex_lock_common(lock, &waiter);
90699- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
90700+ debug_mutex_add_waiter(lock, &waiter, task);
90701
90702 /* add waiting tasks to the end of the waitqueue (FIFO): */
90703 list_add_tail(&waiter.list, &lock->wait_list);
90704@@ -531,7 +531,7 @@ slowpath:
90705 schedule_preempt_disabled();
90706 spin_lock_mutex(&lock->wait_lock, flags);
90707 }
90708- mutex_remove_waiter(lock, &waiter, current_thread_info());
90709+ mutex_remove_waiter(lock, &waiter, task);
90710 /* set it to 0 if there are no waiters left: */
90711 if (likely(list_empty(&lock->wait_list)))
90712 atomic_set(&lock->count, 0);
90713@@ -568,7 +568,7 @@ skip_wait:
90714 return 0;
90715
90716 err:
90717- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
90718+ mutex_remove_waiter(lock, &waiter, task);
90719 spin_unlock_mutex(&lock->wait_lock, flags);
90720 debug_mutex_free_waiter(&waiter);
90721 mutex_release(&lock->dep_map, 1, ip);
90722diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
90723index 1d96dd0..994ff19 100644
90724--- a/kernel/locking/rtmutex-tester.c
90725+++ b/kernel/locking/rtmutex-tester.c
90726@@ -22,7 +22,7 @@
90727 #define MAX_RT_TEST_MUTEXES 8
90728
90729 static spinlock_t rttest_lock;
90730-static atomic_t rttest_event;
90731+static atomic_unchecked_t rttest_event;
90732
90733 struct test_thread_data {
90734 int opcode;
90735@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90736
90737 case RTTEST_LOCKCONT:
90738 td->mutexes[td->opdata] = 1;
90739- td->event = atomic_add_return(1, &rttest_event);
90740+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90741 return 0;
90742
90743 case RTTEST_RESET:
90744@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90745 return 0;
90746
90747 case RTTEST_RESETEVENT:
90748- atomic_set(&rttest_event, 0);
90749+ atomic_set_unchecked(&rttest_event, 0);
90750 return 0;
90751
90752 default:
90753@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90754 return ret;
90755
90756 td->mutexes[id] = 1;
90757- td->event = atomic_add_return(1, &rttest_event);
90758+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90759 rt_mutex_lock(&mutexes[id]);
90760- td->event = atomic_add_return(1, &rttest_event);
90761+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90762 td->mutexes[id] = 4;
90763 return 0;
90764
90765@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90766 return ret;
90767
90768 td->mutexes[id] = 1;
90769- td->event = atomic_add_return(1, &rttest_event);
90770+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90771 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
90772- td->event = atomic_add_return(1, &rttest_event);
90773+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90774 td->mutexes[id] = ret ? 0 : 4;
90775 return ret ? -EINTR : 0;
90776
90777@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90778 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
90779 return ret;
90780
90781- td->event = atomic_add_return(1, &rttest_event);
90782+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90783 rt_mutex_unlock(&mutexes[id]);
90784- td->event = atomic_add_return(1, &rttest_event);
90785+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90786 td->mutexes[id] = 0;
90787 return 0;
90788
90789@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90790 break;
90791
90792 td->mutexes[dat] = 2;
90793- td->event = atomic_add_return(1, &rttest_event);
90794+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90795 break;
90796
90797 default:
90798@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90799 return;
90800
90801 td->mutexes[dat] = 3;
90802- td->event = atomic_add_return(1, &rttest_event);
90803+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90804 break;
90805
90806 case RTTEST_LOCKNOWAIT:
90807@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90808 return;
90809
90810 td->mutexes[dat] = 1;
90811- td->event = atomic_add_return(1, &rttest_event);
90812+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90813 return;
90814
90815 default:
90816diff --git a/kernel/module.c b/kernel/module.c
90817index 1c47139..6242887 100644
90818--- a/kernel/module.c
90819+++ b/kernel/module.c
90820@@ -60,6 +60,7 @@
90821 #include <linux/jump_label.h>
90822 #include <linux/pfn.h>
90823 #include <linux/bsearch.h>
90824+#include <linux/grsecurity.h>
90825 #include <uapi/linux/module.h>
90826 #include "module-internal.h"
90827
90828@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
90829
90830 /* Bounds of module allocation, for speeding __module_address.
90831 * Protected by module_mutex. */
90832-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
90833+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
90834+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
90835
90836 int register_module_notifier(struct notifier_block * nb)
90837 {
90838@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90839 return true;
90840
90841 list_for_each_entry_rcu(mod, &modules, list) {
90842- struct symsearch arr[] = {
90843+ struct symsearch modarr[] = {
90844 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
90845 NOT_GPL_ONLY, false },
90846 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
90847@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90848 if (mod->state == MODULE_STATE_UNFORMED)
90849 continue;
90850
90851- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
90852+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
90853 return true;
90854 }
90855 return false;
90856@@ -488,7 +490,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
90857 if (!pcpusec->sh_size)
90858 return 0;
90859
90860- if (align > PAGE_SIZE) {
90861+ if (align-1 >= PAGE_SIZE) {
90862 pr_warn("%s: per-cpu alignment %li > %li\n",
90863 mod->name, align, PAGE_SIZE);
90864 align = PAGE_SIZE;
90865@@ -1060,7 +1062,7 @@ struct module_attribute module_uevent =
90866 static ssize_t show_coresize(struct module_attribute *mattr,
90867 struct module_kobject *mk, char *buffer)
90868 {
90869- return sprintf(buffer, "%u\n", mk->mod->core_size);
90870+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
90871 }
90872
90873 static struct module_attribute modinfo_coresize =
90874@@ -1069,7 +1071,7 @@ static struct module_attribute modinfo_coresize =
90875 static ssize_t show_initsize(struct module_attribute *mattr,
90876 struct module_kobject *mk, char *buffer)
90877 {
90878- return sprintf(buffer, "%u\n", mk->mod->init_size);
90879+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
90880 }
90881
90882 static struct module_attribute modinfo_initsize =
90883@@ -1161,12 +1163,29 @@ static int check_version(Elf_Shdr *sechdrs,
90884 goto bad_version;
90885 }
90886
90887+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90888+ /*
90889+ * avoid potentially printing jibberish on attempted load
90890+ * of a module randomized with a different seed
90891+ */
90892+ pr_warn("no symbol version for %s\n", symname);
90893+#else
90894 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
90895+#endif
90896 return 0;
90897
90898 bad_version:
90899+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90900+ /*
90901+ * avoid potentially printing jibberish on attempted load
90902+ * of a module randomized with a different seed
90903+ */
90904+ printk("attempted module disagrees about version of symbol %s\n",
90905+ symname);
90906+#else
90907 printk("%s: disagrees about version of symbol %s\n",
90908 mod->name, symname);
90909+#endif
90910 return 0;
90911 }
90912
90913@@ -1282,7 +1301,7 @@ resolve_symbol_wait(struct module *mod,
90914 */
90915 #ifdef CONFIG_SYSFS
90916
90917-#ifdef CONFIG_KALLSYMS
90918+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
90919 static inline bool sect_empty(const Elf_Shdr *sect)
90920 {
90921 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
90922@@ -1422,7 +1441,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
90923 {
90924 unsigned int notes, loaded, i;
90925 struct module_notes_attrs *notes_attrs;
90926- struct bin_attribute *nattr;
90927+ bin_attribute_no_const *nattr;
90928
90929 /* failed to create section attributes, so can't create notes */
90930 if (!mod->sect_attrs)
90931@@ -1534,7 +1553,7 @@ static void del_usage_links(struct module *mod)
90932 static int module_add_modinfo_attrs(struct module *mod)
90933 {
90934 struct module_attribute *attr;
90935- struct module_attribute *temp_attr;
90936+ module_attribute_no_const *temp_attr;
90937 int error = 0;
90938 int i;
90939
90940@@ -1755,21 +1774,21 @@ static void set_section_ro_nx(void *base,
90941
90942 static void unset_module_core_ro_nx(struct module *mod)
90943 {
90944- set_page_attributes(mod->module_core + mod->core_text_size,
90945- mod->module_core + mod->core_size,
90946+ set_page_attributes(mod->module_core_rw,
90947+ mod->module_core_rw + mod->core_size_rw,
90948 set_memory_x);
90949- set_page_attributes(mod->module_core,
90950- mod->module_core + mod->core_ro_size,
90951+ set_page_attributes(mod->module_core_rx,
90952+ mod->module_core_rx + mod->core_size_rx,
90953 set_memory_rw);
90954 }
90955
90956 static void unset_module_init_ro_nx(struct module *mod)
90957 {
90958- set_page_attributes(mod->module_init + mod->init_text_size,
90959- mod->module_init + mod->init_size,
90960+ set_page_attributes(mod->module_init_rw,
90961+ mod->module_init_rw + mod->init_size_rw,
90962 set_memory_x);
90963- set_page_attributes(mod->module_init,
90964- mod->module_init + mod->init_ro_size,
90965+ set_page_attributes(mod->module_init_rx,
90966+ mod->module_init_rx + mod->init_size_rx,
90967 set_memory_rw);
90968 }
90969
90970@@ -1782,14 +1801,14 @@ void set_all_modules_text_rw(void)
90971 list_for_each_entry_rcu(mod, &modules, list) {
90972 if (mod->state == MODULE_STATE_UNFORMED)
90973 continue;
90974- if ((mod->module_core) && (mod->core_text_size)) {
90975- set_page_attributes(mod->module_core,
90976- mod->module_core + mod->core_text_size,
90977+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
90978+ set_page_attributes(mod->module_core_rx,
90979+ mod->module_core_rx + mod->core_size_rx,
90980 set_memory_rw);
90981 }
90982- if ((mod->module_init) && (mod->init_text_size)) {
90983- set_page_attributes(mod->module_init,
90984- mod->module_init + mod->init_text_size,
90985+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
90986+ set_page_attributes(mod->module_init_rx,
90987+ mod->module_init_rx + mod->init_size_rx,
90988 set_memory_rw);
90989 }
90990 }
90991@@ -1805,14 +1824,14 @@ void set_all_modules_text_ro(void)
90992 list_for_each_entry_rcu(mod, &modules, list) {
90993 if (mod->state == MODULE_STATE_UNFORMED)
90994 continue;
90995- if ((mod->module_core) && (mod->core_text_size)) {
90996- set_page_attributes(mod->module_core,
90997- mod->module_core + mod->core_text_size,
90998+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
90999+ set_page_attributes(mod->module_core_rx,
91000+ mod->module_core_rx + mod->core_size_rx,
91001 set_memory_ro);
91002 }
91003- if ((mod->module_init) && (mod->init_text_size)) {
91004- set_page_attributes(mod->module_init,
91005- mod->module_init + mod->init_text_size,
91006+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
91007+ set_page_attributes(mod->module_init_rx,
91008+ mod->module_init_rx + mod->init_size_rx,
91009 set_memory_ro);
91010 }
91011 }
91012@@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
91013
91014 /* This may be NULL, but that's OK */
91015 unset_module_init_ro_nx(mod);
91016- module_free(mod, mod->module_init);
91017+ module_free(mod, mod->module_init_rw);
91018+ module_free_exec(mod, mod->module_init_rx);
91019 kfree(mod->args);
91020 percpu_modfree(mod);
91021
91022 /* Free lock-classes: */
91023- lockdep_free_key_range(mod->module_core, mod->core_size);
91024+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
91025+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
91026
91027 /* Finally, free the core (containing the module structure) */
91028 unset_module_core_ro_nx(mod);
91029- module_free(mod, mod->module_core);
91030+ module_free_exec(mod, mod->module_core_rx);
91031+ module_free(mod, mod->module_core_rw);
91032
91033 #ifdef CONFIG_MPU
91034 update_protections(current->mm);
91035@@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
91036 int ret = 0;
91037 const struct kernel_symbol *ksym;
91038
91039+#ifdef CONFIG_GRKERNSEC_MODHARDEN
91040+ int is_fs_load = 0;
91041+ int register_filesystem_found = 0;
91042+ char *p;
91043+
91044+ p = strstr(mod->args, "grsec_modharden_fs");
91045+ if (p) {
91046+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
91047+ /* copy \0 as well */
91048+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
91049+ is_fs_load = 1;
91050+ }
91051+#endif
91052+
91053 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
91054 const char *name = info->strtab + sym[i].st_name;
91055
91056+#ifdef CONFIG_GRKERNSEC_MODHARDEN
91057+ /* it's a real shame this will never get ripped and copied
91058+ upstream! ;(
91059+ */
91060+ if (is_fs_load && !strcmp(name, "register_filesystem"))
91061+ register_filesystem_found = 1;
91062+#endif
91063+
91064 switch (sym[i].st_shndx) {
91065 case SHN_COMMON:
91066 /* Ignore common symbols */
91067@@ -1970,7 +2014,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
91068 ksym = resolve_symbol_wait(mod, info, name);
91069 /* Ok if resolved. */
91070 if (ksym && !IS_ERR(ksym)) {
91071+ pax_open_kernel();
91072 sym[i].st_value = ksym->value;
91073+ pax_close_kernel();
91074 break;
91075 }
91076
91077@@ -1989,11 +2035,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
91078 secbase = (unsigned long)mod_percpu(mod);
91079 else
91080 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
91081+ pax_open_kernel();
91082 sym[i].st_value += secbase;
91083+ pax_close_kernel();
91084 break;
91085 }
91086 }
91087
91088+#ifdef CONFIG_GRKERNSEC_MODHARDEN
91089+ if (is_fs_load && !register_filesystem_found) {
91090+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
91091+ ret = -EPERM;
91092+ }
91093+#endif
91094+
91095 return ret;
91096 }
91097
91098@@ -2077,22 +2132,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
91099 || s->sh_entsize != ~0UL
91100 || strstarts(sname, ".init"))
91101 continue;
91102- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
91103+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
91104+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
91105+ else
91106+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
91107 pr_debug("\t%s\n", sname);
91108 }
91109- switch (m) {
91110- case 0: /* executable */
91111- mod->core_size = debug_align(mod->core_size);
91112- mod->core_text_size = mod->core_size;
91113- break;
91114- case 1: /* RO: text and ro-data */
91115- mod->core_size = debug_align(mod->core_size);
91116- mod->core_ro_size = mod->core_size;
91117- break;
91118- case 3: /* whole core */
91119- mod->core_size = debug_align(mod->core_size);
91120- break;
91121- }
91122 }
91123
91124 pr_debug("Init section allocation order:\n");
91125@@ -2106,23 +2151,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
91126 || s->sh_entsize != ~0UL
91127 || !strstarts(sname, ".init"))
91128 continue;
91129- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
91130- | INIT_OFFSET_MASK);
91131+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
91132+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
91133+ else
91134+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
91135+ s->sh_entsize |= INIT_OFFSET_MASK;
91136 pr_debug("\t%s\n", sname);
91137 }
91138- switch (m) {
91139- case 0: /* executable */
91140- mod->init_size = debug_align(mod->init_size);
91141- mod->init_text_size = mod->init_size;
91142- break;
91143- case 1: /* RO: text and ro-data */
91144- mod->init_size = debug_align(mod->init_size);
91145- mod->init_ro_size = mod->init_size;
91146- break;
91147- case 3: /* whole init */
91148- mod->init_size = debug_align(mod->init_size);
91149- break;
91150- }
91151 }
91152 }
91153
91154@@ -2295,7 +2330,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
91155
91156 /* Put symbol section at end of init part of module. */
91157 symsect->sh_flags |= SHF_ALLOC;
91158- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
91159+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
91160 info->index.sym) | INIT_OFFSET_MASK;
91161 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
91162
91163@@ -2312,13 +2347,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
91164 }
91165
91166 /* Append room for core symbols at end of core part. */
91167- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
91168- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
91169- mod->core_size += strtab_size;
91170+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
91171+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
91172+ mod->core_size_rx += strtab_size;
91173
91174 /* Put string table section at end of init part of module. */
91175 strsect->sh_flags |= SHF_ALLOC;
91176- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
91177+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
91178 info->index.str) | INIT_OFFSET_MASK;
91179 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
91180 }
91181@@ -2336,12 +2371,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
91182 /* Make sure we get permanent strtab: don't use info->strtab. */
91183 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
91184
91185+ pax_open_kernel();
91186+
91187 /* Set types up while we still have access to sections. */
91188 for (i = 0; i < mod->num_symtab; i++)
91189 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
91190
91191- mod->core_symtab = dst = mod->module_core + info->symoffs;
91192- mod->core_strtab = s = mod->module_core + info->stroffs;
91193+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
91194+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
91195 src = mod->symtab;
91196 for (ndst = i = 0; i < mod->num_symtab; i++) {
91197 if (i == 0 ||
91198@@ -2353,6 +2390,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
91199 }
91200 }
91201 mod->core_num_syms = ndst;
91202+
91203+ pax_close_kernel();
91204 }
91205 #else
91206 static inline void layout_symtab(struct module *mod, struct load_info *info)
91207@@ -2386,17 +2425,33 @@ void * __weak module_alloc(unsigned long size)
91208 return vmalloc_exec(size);
91209 }
91210
91211-static void *module_alloc_update_bounds(unsigned long size)
91212+static void *module_alloc_update_bounds_rw(unsigned long size)
91213 {
91214 void *ret = module_alloc(size);
91215
91216 if (ret) {
91217 mutex_lock(&module_mutex);
91218 /* Update module bounds. */
91219- if ((unsigned long)ret < module_addr_min)
91220- module_addr_min = (unsigned long)ret;
91221- if ((unsigned long)ret + size > module_addr_max)
91222- module_addr_max = (unsigned long)ret + size;
91223+ if ((unsigned long)ret < module_addr_min_rw)
91224+ module_addr_min_rw = (unsigned long)ret;
91225+ if ((unsigned long)ret + size > module_addr_max_rw)
91226+ module_addr_max_rw = (unsigned long)ret + size;
91227+ mutex_unlock(&module_mutex);
91228+ }
91229+ return ret;
91230+}
91231+
91232+static void *module_alloc_update_bounds_rx(unsigned long size)
91233+{
91234+ void *ret = module_alloc_exec(size);
91235+
91236+ if (ret) {
91237+ mutex_lock(&module_mutex);
91238+ /* Update module bounds. */
91239+ if ((unsigned long)ret < module_addr_min_rx)
91240+ module_addr_min_rx = (unsigned long)ret;
91241+ if ((unsigned long)ret + size > module_addr_max_rx)
91242+ module_addr_max_rx = (unsigned long)ret + size;
91243 mutex_unlock(&module_mutex);
91244 }
91245 return ret;
91246@@ -2650,7 +2705,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
91247 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
91248
91249 if (info->index.sym == 0) {
91250+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
91251+ /*
91252+ * avoid potentially printing jibberish on attempted load
91253+ * of a module randomized with a different seed
91254+ */
91255+ pr_warn("module has no symbols (stripped?)\n");
91256+#else
91257 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
91258+#endif
91259 return ERR_PTR(-ENOEXEC);
91260 }
91261
91262@@ -2666,8 +2729,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
91263 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
91264 {
91265 const char *modmagic = get_modinfo(info, "vermagic");
91266+ const char *license = get_modinfo(info, "license");
91267 int err;
91268
91269+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
91270+ if (!license || !license_is_gpl_compatible(license))
91271+ return -ENOEXEC;
91272+#endif
91273+
91274 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
91275 modmagic = NULL;
91276
91277@@ -2692,7 +2761,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
91278 }
91279
91280 /* Set up license info based on the info section */
91281- set_license(mod, get_modinfo(info, "license"));
91282+ set_license(mod, license);
91283
91284 return 0;
91285 }
91286@@ -2786,7 +2855,7 @@ static int move_module(struct module *mod, struct load_info *info)
91287 void *ptr;
91288
91289 /* Do the allocs. */
91290- ptr = module_alloc_update_bounds(mod->core_size);
91291+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
91292 /*
91293 * The pointer to this block is stored in the module structure
91294 * which is inside the block. Just mark it as not being a
91295@@ -2796,11 +2865,11 @@ static int move_module(struct module *mod, struct load_info *info)
91296 if (!ptr)
91297 return -ENOMEM;
91298
91299- memset(ptr, 0, mod->core_size);
91300- mod->module_core = ptr;
91301+ memset(ptr, 0, mod->core_size_rw);
91302+ mod->module_core_rw = ptr;
91303
91304- if (mod->init_size) {
91305- ptr = module_alloc_update_bounds(mod->init_size);
91306+ if (mod->init_size_rw) {
91307+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
91308 /*
91309 * The pointer to this block is stored in the module structure
91310 * which is inside the block. This block doesn't need to be
91311@@ -2809,13 +2878,45 @@ static int move_module(struct module *mod, struct load_info *info)
91312 */
91313 kmemleak_ignore(ptr);
91314 if (!ptr) {
91315- module_free(mod, mod->module_core);
91316+ module_free(mod, mod->module_core_rw);
91317 return -ENOMEM;
91318 }
91319- memset(ptr, 0, mod->init_size);
91320- mod->module_init = ptr;
91321+ memset(ptr, 0, mod->init_size_rw);
91322+ mod->module_init_rw = ptr;
91323 } else
91324- mod->module_init = NULL;
91325+ mod->module_init_rw = NULL;
91326+
91327+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
91328+ kmemleak_not_leak(ptr);
91329+ if (!ptr) {
91330+ if (mod->module_init_rw)
91331+ module_free(mod, mod->module_init_rw);
91332+ module_free(mod, mod->module_core_rw);
91333+ return -ENOMEM;
91334+ }
91335+
91336+ pax_open_kernel();
91337+ memset(ptr, 0, mod->core_size_rx);
91338+ pax_close_kernel();
91339+ mod->module_core_rx = ptr;
91340+
91341+ if (mod->init_size_rx) {
91342+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
91343+ kmemleak_ignore(ptr);
91344+ if (!ptr && mod->init_size_rx) {
91345+ module_free_exec(mod, mod->module_core_rx);
91346+ if (mod->module_init_rw)
91347+ module_free(mod, mod->module_init_rw);
91348+ module_free(mod, mod->module_core_rw);
91349+ return -ENOMEM;
91350+ }
91351+
91352+ pax_open_kernel();
91353+ memset(ptr, 0, mod->init_size_rx);
91354+ pax_close_kernel();
91355+ mod->module_init_rx = ptr;
91356+ } else
91357+ mod->module_init_rx = NULL;
91358
91359 /* Transfer each section which specifies SHF_ALLOC */
91360 pr_debug("final section addresses:\n");
91361@@ -2826,16 +2927,45 @@ static int move_module(struct module *mod, struct load_info *info)
91362 if (!(shdr->sh_flags & SHF_ALLOC))
91363 continue;
91364
91365- if (shdr->sh_entsize & INIT_OFFSET_MASK)
91366- dest = mod->module_init
91367- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
91368- else
91369- dest = mod->module_core + shdr->sh_entsize;
91370+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
91371+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
91372+ dest = mod->module_init_rw
91373+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
91374+ else
91375+ dest = mod->module_init_rx
91376+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
91377+ } else {
91378+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
91379+ dest = mod->module_core_rw + shdr->sh_entsize;
91380+ else
91381+ dest = mod->module_core_rx + shdr->sh_entsize;
91382+ }
91383+
91384+ if (shdr->sh_type != SHT_NOBITS) {
91385+
91386+#ifdef CONFIG_PAX_KERNEXEC
91387+#ifdef CONFIG_X86_64
91388+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
91389+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
91390+#endif
91391+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
91392+ pax_open_kernel();
91393+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
91394+ pax_close_kernel();
91395+ } else
91396+#endif
91397
91398- if (shdr->sh_type != SHT_NOBITS)
91399 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
91400+ }
91401 /* Update sh_addr to point to copy in image. */
91402- shdr->sh_addr = (unsigned long)dest;
91403+
91404+#ifdef CONFIG_PAX_KERNEXEC
91405+ if (shdr->sh_flags & SHF_EXECINSTR)
91406+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
91407+ else
91408+#endif
91409+
91410+ shdr->sh_addr = (unsigned long)dest;
91411 pr_debug("\t0x%lx %s\n",
91412 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
91413 }
91414@@ -2892,12 +3022,12 @@ static void flush_module_icache(const struct module *mod)
91415 * Do it before processing of module parameters, so the module
91416 * can provide parameter accessor functions of its own.
91417 */
91418- if (mod->module_init)
91419- flush_icache_range((unsigned long)mod->module_init,
91420- (unsigned long)mod->module_init
91421- + mod->init_size);
91422- flush_icache_range((unsigned long)mod->module_core,
91423- (unsigned long)mod->module_core + mod->core_size);
91424+ if (mod->module_init_rx)
91425+ flush_icache_range((unsigned long)mod->module_init_rx,
91426+ (unsigned long)mod->module_init_rx
91427+ + mod->init_size_rx);
91428+ flush_icache_range((unsigned long)mod->module_core_rx,
91429+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
91430
91431 set_fs(old_fs);
91432 }
91433@@ -2954,8 +3084,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
91434 static void module_deallocate(struct module *mod, struct load_info *info)
91435 {
91436 percpu_modfree(mod);
91437- module_free(mod, mod->module_init);
91438- module_free(mod, mod->module_core);
91439+ module_free_exec(mod, mod->module_init_rx);
91440+ module_free_exec(mod, mod->module_core_rx);
91441+ module_free(mod, mod->module_init_rw);
91442+ module_free(mod, mod->module_core_rw);
91443 }
91444
91445 int __weak module_finalize(const Elf_Ehdr *hdr,
91446@@ -2968,7 +3100,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
91447 static int post_relocation(struct module *mod, const struct load_info *info)
91448 {
91449 /* Sort exception table now relocations are done. */
91450+ pax_open_kernel();
91451 sort_extable(mod->extable, mod->extable + mod->num_exentries);
91452+ pax_close_kernel();
91453
91454 /* Copy relocated percpu area over. */
91455 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
91456@@ -3077,11 +3211,12 @@ static int do_init_module(struct module *mod)
91457 mod->strtab = mod->core_strtab;
91458 #endif
91459 unset_module_init_ro_nx(mod);
91460- module_free(mod, mod->module_init);
91461- mod->module_init = NULL;
91462- mod->init_size = 0;
91463- mod->init_ro_size = 0;
91464- mod->init_text_size = 0;
91465+ module_free(mod, mod->module_init_rw);
91466+ module_free_exec(mod, mod->module_init_rx);
91467+ mod->module_init_rw = NULL;
91468+ mod->module_init_rx = NULL;
91469+ mod->init_size_rw = 0;
91470+ mod->init_size_rx = 0;
91471 mutex_unlock(&module_mutex);
91472 wake_up_all(&module_wq);
91473
91474@@ -3149,16 +3284,16 @@ static int complete_formation(struct module *mod, struct load_info *info)
91475 module_bug_finalize(info->hdr, info->sechdrs, mod);
91476
91477 /* Set RO and NX regions for core */
91478- set_section_ro_nx(mod->module_core,
91479- mod->core_text_size,
91480- mod->core_ro_size,
91481- mod->core_size);
91482+ set_section_ro_nx(mod->module_core_rx,
91483+ mod->core_size_rx,
91484+ mod->core_size_rx,
91485+ mod->core_size_rx);
91486
91487 /* Set RO and NX regions for init */
91488- set_section_ro_nx(mod->module_init,
91489- mod->init_text_size,
91490- mod->init_ro_size,
91491- mod->init_size);
91492+ set_section_ro_nx(mod->module_init_rx,
91493+ mod->init_size_rx,
91494+ mod->init_size_rx,
91495+ mod->init_size_rx);
91496
91497 /* Mark state as coming so strong_try_module_get() ignores us,
91498 * but kallsyms etc. can see us. */
91499@@ -3242,9 +3377,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
91500 if (err)
91501 goto free_unload;
91502
91503+ /* Now copy in args */
91504+ mod->args = strndup_user(uargs, ~0UL >> 1);
91505+ if (IS_ERR(mod->args)) {
91506+ err = PTR_ERR(mod->args);
91507+ goto free_unload;
91508+ }
91509+
91510 /* Set up MODINFO_ATTR fields */
91511 setup_modinfo(mod, info);
91512
91513+#ifdef CONFIG_GRKERNSEC_MODHARDEN
91514+ {
91515+ char *p, *p2;
91516+
91517+ if (strstr(mod->args, "grsec_modharden_netdev")) {
91518+ 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);
91519+ err = -EPERM;
91520+ goto free_modinfo;
91521+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
91522+ p += sizeof("grsec_modharden_normal") - 1;
91523+ p2 = strstr(p, "_");
91524+ if (p2) {
91525+ *p2 = '\0';
91526+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
91527+ *p2 = '_';
91528+ }
91529+ err = -EPERM;
91530+ goto free_modinfo;
91531+ }
91532+ }
91533+#endif
91534+
91535 /* Fix up syms, so that st_value is a pointer to location. */
91536 err = simplify_symbols(mod, info);
91537 if (err < 0)
91538@@ -3260,13 +3424,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
91539
91540 flush_module_icache(mod);
91541
91542- /* Now copy in args */
91543- mod->args = strndup_user(uargs, ~0UL >> 1);
91544- if (IS_ERR(mod->args)) {
91545- err = PTR_ERR(mod->args);
91546- goto free_arch_cleanup;
91547- }
91548-
91549 dynamic_debug_setup(info->debug, info->num_debug);
91550
91551 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
91552@@ -3314,11 +3471,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
91553 ddebug_cleanup:
91554 dynamic_debug_remove(info->debug);
91555 synchronize_sched();
91556- kfree(mod->args);
91557- free_arch_cleanup:
91558 module_arch_cleanup(mod);
91559 free_modinfo:
91560 free_modinfo(mod);
91561+ kfree(mod->args);
91562 free_unload:
91563 module_unload_free(mod);
91564 unlink_mod:
91565@@ -3403,10 +3559,16 @@ static const char *get_ksymbol(struct module *mod,
91566 unsigned long nextval;
91567
91568 /* At worse, next value is at end of module */
91569- if (within_module_init(addr, mod))
91570- nextval = (unsigned long)mod->module_init+mod->init_text_size;
91571+ if (within_module_init_rx(addr, mod))
91572+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
91573+ else if (within_module_init_rw(addr, mod))
91574+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
91575+ else if (within_module_core_rx(addr, mod))
91576+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
91577+ else if (within_module_core_rw(addr, mod))
91578+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
91579 else
91580- nextval = (unsigned long)mod->module_core+mod->core_text_size;
91581+ return NULL;
91582
91583 /* Scan for closest preceding symbol, and next symbol. (ELF
91584 starts real symbols at 1). */
91585@@ -3654,7 +3816,7 @@ static int m_show(struct seq_file *m, void *p)
91586 return 0;
91587
91588 seq_printf(m, "%s %u",
91589- mod->name, mod->init_size + mod->core_size);
91590+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
91591 print_unload_info(m, mod);
91592
91593 /* Informative for users. */
91594@@ -3663,7 +3825,7 @@ static int m_show(struct seq_file *m, void *p)
91595 mod->state == MODULE_STATE_COMING ? "Loading":
91596 "Live");
91597 /* Used by oprofile and other similar tools. */
91598- seq_printf(m, " 0x%pK", mod->module_core);
91599+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
91600
91601 /* Taints info */
91602 if (mod->taints)
91603@@ -3699,7 +3861,17 @@ static const struct file_operations proc_modules_operations = {
91604
91605 static int __init proc_modules_init(void)
91606 {
91607+#ifndef CONFIG_GRKERNSEC_HIDESYM
91608+#ifdef CONFIG_GRKERNSEC_PROC_USER
91609+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
91610+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
91611+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
91612+#else
91613 proc_create("modules", 0, NULL, &proc_modules_operations);
91614+#endif
91615+#else
91616+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
91617+#endif
91618 return 0;
91619 }
91620 module_init(proc_modules_init);
91621@@ -3760,7 +3932,8 @@ struct module *__module_address(unsigned long addr)
91622 {
91623 struct module *mod;
91624
91625- if (addr < module_addr_min || addr > module_addr_max)
91626+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
91627+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
91628 return NULL;
91629
91630 list_for_each_entry_rcu(mod, &modules, list) {
91631@@ -3801,11 +3974,20 @@ bool is_module_text_address(unsigned long addr)
91632 */
91633 struct module *__module_text_address(unsigned long addr)
91634 {
91635- struct module *mod = __module_address(addr);
91636+ struct module *mod;
91637+
91638+#ifdef CONFIG_X86_32
91639+ addr = ktla_ktva(addr);
91640+#endif
91641+
91642+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
91643+ return NULL;
91644+
91645+ mod = __module_address(addr);
91646+
91647 if (mod) {
91648 /* Make sure it's within the text section. */
91649- if (!within(addr, mod->module_init, mod->init_text_size)
91650- && !within(addr, mod->module_core, mod->core_text_size))
91651+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
91652 mod = NULL;
91653 }
91654 return mod;
91655diff --git a/kernel/notifier.c b/kernel/notifier.c
91656index 4803da6..1c5eea6 100644
91657--- a/kernel/notifier.c
91658+++ b/kernel/notifier.c
91659@@ -5,6 +5,7 @@
91660 #include <linux/rcupdate.h>
91661 #include <linux/vmalloc.h>
91662 #include <linux/reboot.h>
91663+#include <linux/mm.h>
91664
91665 /*
91666 * Notifier list for kernel code which wants to be called
91667@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
91668 while ((*nl) != NULL) {
91669 if (n->priority > (*nl)->priority)
91670 break;
91671- nl = &((*nl)->next);
91672+ nl = (struct notifier_block **)&((*nl)->next);
91673 }
91674- n->next = *nl;
91675+ pax_open_kernel();
91676+ *(const void **)&n->next = *nl;
91677 rcu_assign_pointer(*nl, n);
91678+ pax_close_kernel();
91679 return 0;
91680 }
91681
91682@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
91683 return 0;
91684 if (n->priority > (*nl)->priority)
91685 break;
91686- nl = &((*nl)->next);
91687+ nl = (struct notifier_block **)&((*nl)->next);
91688 }
91689- n->next = *nl;
91690+ pax_open_kernel();
91691+ *(const void **)&n->next = *nl;
91692 rcu_assign_pointer(*nl, n);
91693+ pax_close_kernel();
91694 return 0;
91695 }
91696
91697@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
91698 {
91699 while ((*nl) != NULL) {
91700 if ((*nl) == n) {
91701+ pax_open_kernel();
91702 rcu_assign_pointer(*nl, n->next);
91703+ pax_close_kernel();
91704 return 0;
91705 }
91706- nl = &((*nl)->next);
91707+ nl = (struct notifier_block **)&((*nl)->next);
91708 }
91709 return -ENOENT;
91710 }
91711diff --git a/kernel/padata.c b/kernel/padata.c
91712index 161402f..598814c 100644
91713--- a/kernel/padata.c
91714+++ b/kernel/padata.c
91715@@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
91716 * seq_nr mod. number of cpus in use.
91717 */
91718
91719- seq_nr = atomic_inc_return(&pd->seq_nr);
91720+ seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
91721 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
91722
91723 return padata_index_to_cpu(pd, cpu_index);
91724@@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
91725 padata_init_pqueues(pd);
91726 padata_init_squeues(pd);
91727 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
91728- atomic_set(&pd->seq_nr, -1);
91729+ atomic_set_unchecked(&pd->seq_nr, -1);
91730 atomic_set(&pd->reorder_objects, 0);
91731 atomic_set(&pd->refcnt, 0);
91732 pd->pinst = pinst;
91733diff --git a/kernel/panic.c b/kernel/panic.c
91734index d09dc5c..9abbdff 100644
91735--- a/kernel/panic.c
91736+++ b/kernel/panic.c
91737@@ -53,7 +53,7 @@ EXPORT_SYMBOL(panic_blink);
91738 /*
91739 * Stop ourself in panic -- architecture code may override this
91740 */
91741-void __weak panic_smp_self_stop(void)
91742+void __weak __noreturn panic_smp_self_stop(void)
91743 {
91744 while (1)
91745 cpu_relax();
91746@@ -421,7 +421,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
91747 disable_trace_on_warning();
91748
91749 pr_warn("------------[ cut here ]------------\n");
91750- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
91751+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
91752 raw_smp_processor_id(), current->pid, file, line, caller);
91753
91754 if (args)
91755@@ -475,7 +475,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
91756 */
91757 __visible void __stack_chk_fail(void)
91758 {
91759- panic("stack-protector: Kernel stack is corrupted in: %p\n",
91760+ dump_stack();
91761+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
91762 __builtin_return_address(0));
91763 }
91764 EXPORT_SYMBOL(__stack_chk_fail);
91765diff --git a/kernel/pid.c b/kernel/pid.c
91766index 9b9a266..c20ef80 100644
91767--- a/kernel/pid.c
91768+++ b/kernel/pid.c
91769@@ -33,6 +33,7 @@
91770 #include <linux/rculist.h>
91771 #include <linux/bootmem.h>
91772 #include <linux/hash.h>
91773+#include <linux/security.h>
91774 #include <linux/pid_namespace.h>
91775 #include <linux/init_task.h>
91776 #include <linux/syscalls.h>
91777@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
91778
91779 int pid_max = PID_MAX_DEFAULT;
91780
91781-#define RESERVED_PIDS 300
91782+#define RESERVED_PIDS 500
91783
91784 int pid_max_min = RESERVED_PIDS + 1;
91785 int pid_max_max = PID_MAX_LIMIT;
91786@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
91787 */
91788 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
91789 {
91790+ struct task_struct *task;
91791+
91792 rcu_lockdep_assert(rcu_read_lock_held(),
91793 "find_task_by_pid_ns() needs rcu_read_lock()"
91794 " protection");
91795- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91796+
91797+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91798+
91799+ if (gr_pid_is_chrooted(task))
91800+ return NULL;
91801+
91802+ return task;
91803 }
91804
91805 struct task_struct *find_task_by_vpid(pid_t vnr)
91806@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
91807 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
91808 }
91809
91810+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
91811+{
91812+ rcu_lockdep_assert(rcu_read_lock_held(),
91813+ "find_task_by_pid_ns() needs rcu_read_lock()"
91814+ " protection");
91815+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
91816+}
91817+
91818 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
91819 {
91820 struct pid *pid;
91821diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
91822index db95d8e..a0ca23f 100644
91823--- a/kernel/pid_namespace.c
91824+++ b/kernel/pid_namespace.c
91825@@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
91826 void __user *buffer, size_t *lenp, loff_t *ppos)
91827 {
91828 struct pid_namespace *pid_ns = task_active_pid_ns(current);
91829- struct ctl_table tmp = *table;
91830+ ctl_table_no_const tmp = *table;
91831
91832 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
91833 return -EPERM;
91834diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
91835index e4e4121..71faf14 100644
91836--- a/kernel/power/Kconfig
91837+++ b/kernel/power/Kconfig
91838@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
91839 config HIBERNATION
91840 bool "Hibernation (aka 'suspend to disk')"
91841 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
91842+ depends on !GRKERNSEC_KMEM
91843+ depends on !PAX_MEMORY_SANITIZE
91844 select HIBERNATE_CALLBACKS
91845 select LZO_COMPRESS
91846 select LZO_DECOMPRESS
91847diff --git a/kernel/power/process.c b/kernel/power/process.c
91848index 7a37cf3..3e4c1c8 100644
91849--- a/kernel/power/process.c
91850+++ b/kernel/power/process.c
91851@@ -35,6 +35,7 @@ static int try_to_freeze_tasks(bool user_only)
91852 unsigned int elapsed_msecs;
91853 bool wakeup = false;
91854 int sleep_usecs = USEC_PER_MSEC;
91855+ bool timedout = false;
91856
91857 do_gettimeofday(&start);
91858
91859@@ -45,13 +46,20 @@ static int try_to_freeze_tasks(bool user_only)
91860
91861 while (true) {
91862 todo = 0;
91863+ if (time_after(jiffies, end_time))
91864+ timedout = true;
91865 read_lock(&tasklist_lock);
91866 do_each_thread(g, p) {
91867 if (p == current || !freeze_task(p))
91868 continue;
91869
91870- if (!freezer_should_skip(p))
91871+ if (!freezer_should_skip(p)) {
91872 todo++;
91873+ if (timedout) {
91874+ printk(KERN_ERR "Task refusing to freeze:\n");
91875+ sched_show_task(p);
91876+ }
91877+ }
91878 } while_each_thread(g, p);
91879 read_unlock(&tasklist_lock);
91880
91881@@ -60,7 +68,7 @@ static int try_to_freeze_tasks(bool user_only)
91882 todo += wq_busy;
91883 }
91884
91885- if (!todo || time_after(jiffies, end_time))
91886+ if (!todo || timedout)
91887 break;
91888
91889 if (pm_wakeup_pending()) {
91890diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
91891index 1ce7706..3b07c49 100644
91892--- a/kernel/printk/printk.c
91893+++ b/kernel/printk/printk.c
91894@@ -490,6 +490,11 @@ static int check_syslog_permissions(int type, bool from_file)
91895 if (from_file && type != SYSLOG_ACTION_OPEN)
91896 return 0;
91897
91898+#ifdef CONFIG_GRKERNSEC_DMESG
91899+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
91900+ return -EPERM;
91901+#endif
91902+
91903 if (syslog_action_restricted(type)) {
91904 if (capable(CAP_SYSLOG))
91905 return 0;
91906diff --git a/kernel/profile.c b/kernel/profile.c
91907index 54bf5ba..df6e0a2 100644
91908--- a/kernel/profile.c
91909+++ b/kernel/profile.c
91910@@ -37,7 +37,7 @@ struct profile_hit {
91911 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
91912 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
91913
91914-static atomic_t *prof_buffer;
91915+static atomic_unchecked_t *prof_buffer;
91916 static unsigned long prof_len, prof_shift;
91917
91918 int prof_on __read_mostly;
91919@@ -256,7 +256,7 @@ static void profile_flip_buffers(void)
91920 hits[i].pc = 0;
91921 continue;
91922 }
91923- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91924+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91925 hits[i].hits = hits[i].pc = 0;
91926 }
91927 }
91928@@ -317,9 +317,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91929 * Add the current hit(s) and flush the write-queue out
91930 * to the global buffer:
91931 */
91932- atomic_add(nr_hits, &prof_buffer[pc]);
91933+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
91934 for (i = 0; i < NR_PROFILE_HIT; ++i) {
91935- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91936+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91937 hits[i].pc = hits[i].hits = 0;
91938 }
91939 out:
91940@@ -394,7 +394,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91941 {
91942 unsigned long pc;
91943 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
91944- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91945+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91946 }
91947 #endif /* !CONFIG_SMP */
91948
91949@@ -490,7 +490,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
91950 return -EFAULT;
91951 buf++; p++; count--; read++;
91952 }
91953- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
91954+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
91955 if (copy_to_user(buf, (void *)pnt, count))
91956 return -EFAULT;
91957 read += count;
91958@@ -521,7 +521,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
91959 }
91960 #endif
91961 profile_discard_flip_buffers();
91962- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
91963+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
91964 return count;
91965 }
91966
91967diff --git a/kernel/ptrace.c b/kernel/ptrace.c
91968index 54e7522..5b82dd6 100644
91969--- a/kernel/ptrace.c
91970+++ b/kernel/ptrace.c
91971@@ -321,7 +321,7 @@ static int ptrace_attach(struct task_struct *task, long request,
91972 if (seize)
91973 flags |= PT_SEIZED;
91974 rcu_read_lock();
91975- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91976+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91977 flags |= PT_PTRACE_CAP;
91978 rcu_read_unlock();
91979 task->ptrace = flags;
91980@@ -532,7 +532,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
91981 break;
91982 return -EIO;
91983 }
91984- if (copy_to_user(dst, buf, retval))
91985+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
91986 return -EFAULT;
91987 copied += retval;
91988 src += retval;
91989@@ -800,7 +800,7 @@ int ptrace_request(struct task_struct *child, long request,
91990 bool seized = child->ptrace & PT_SEIZED;
91991 int ret = -EIO;
91992 siginfo_t siginfo, *si;
91993- void __user *datavp = (void __user *) data;
91994+ void __user *datavp = (__force void __user *) data;
91995 unsigned long __user *datalp = datavp;
91996 unsigned long flags;
91997
91998@@ -1046,14 +1046,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
91999 goto out;
92000 }
92001
92002+ if (gr_handle_ptrace(child, request)) {
92003+ ret = -EPERM;
92004+ goto out_put_task_struct;
92005+ }
92006+
92007 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
92008 ret = ptrace_attach(child, request, addr, data);
92009 /*
92010 * Some architectures need to do book-keeping after
92011 * a ptrace attach.
92012 */
92013- if (!ret)
92014+ if (!ret) {
92015 arch_ptrace_attach(child);
92016+ gr_audit_ptrace(child);
92017+ }
92018 goto out_put_task_struct;
92019 }
92020
92021@@ -1081,7 +1088,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
92022 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
92023 if (copied != sizeof(tmp))
92024 return -EIO;
92025- return put_user(tmp, (unsigned long __user *)data);
92026+ return put_user(tmp, (__force unsigned long __user *)data);
92027 }
92028
92029 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
92030@@ -1175,7 +1182,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
92031 }
92032
92033 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
92034- compat_long_t, addr, compat_long_t, data)
92035+ compat_ulong_t, addr, compat_ulong_t, data)
92036 {
92037 struct task_struct *child;
92038 long ret;
92039@@ -1191,14 +1198,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
92040 goto out;
92041 }
92042
92043+ if (gr_handle_ptrace(child, request)) {
92044+ ret = -EPERM;
92045+ goto out_put_task_struct;
92046+ }
92047+
92048 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
92049 ret = ptrace_attach(child, request, addr, data);
92050 /*
92051 * Some architectures need to do book-keeping after
92052 * a ptrace attach.
92053 */
92054- if (!ret)
92055+ if (!ret) {
92056 arch_ptrace_attach(child);
92057+ gr_audit_ptrace(child);
92058+ }
92059 goto out_put_task_struct;
92060 }
92061
92062diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
92063index 948a769..5ca842b 100644
92064--- a/kernel/rcu/rcutorture.c
92065+++ b/kernel/rcu/rcutorture.c
92066@@ -124,12 +124,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
92067 rcu_torture_count) = { 0 };
92068 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
92069 rcu_torture_batch) = { 0 };
92070-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
92071-static atomic_t n_rcu_torture_alloc;
92072-static atomic_t n_rcu_torture_alloc_fail;
92073-static atomic_t n_rcu_torture_free;
92074-static atomic_t n_rcu_torture_mberror;
92075-static atomic_t n_rcu_torture_error;
92076+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
92077+static atomic_unchecked_t n_rcu_torture_alloc;
92078+static atomic_unchecked_t n_rcu_torture_alloc_fail;
92079+static atomic_unchecked_t n_rcu_torture_free;
92080+static atomic_unchecked_t n_rcu_torture_mberror;
92081+static atomic_unchecked_t n_rcu_torture_error;
92082 static long n_rcu_torture_barrier_error;
92083 static long n_rcu_torture_boost_ktrerror;
92084 static long n_rcu_torture_boost_rterror;
92085@@ -200,11 +200,11 @@ rcu_torture_alloc(void)
92086
92087 spin_lock_bh(&rcu_torture_lock);
92088 if (list_empty(&rcu_torture_freelist)) {
92089- atomic_inc(&n_rcu_torture_alloc_fail);
92090+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
92091 spin_unlock_bh(&rcu_torture_lock);
92092 return NULL;
92093 }
92094- atomic_inc(&n_rcu_torture_alloc);
92095+ atomic_inc_unchecked(&n_rcu_torture_alloc);
92096 p = rcu_torture_freelist.next;
92097 list_del_init(p);
92098 spin_unlock_bh(&rcu_torture_lock);
92099@@ -217,7 +217,7 @@ rcu_torture_alloc(void)
92100 static void
92101 rcu_torture_free(struct rcu_torture *p)
92102 {
92103- atomic_inc(&n_rcu_torture_free);
92104+ atomic_inc_unchecked(&n_rcu_torture_free);
92105 spin_lock_bh(&rcu_torture_lock);
92106 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
92107 spin_unlock_bh(&rcu_torture_lock);
92108@@ -301,7 +301,7 @@ rcu_torture_pipe_update_one(struct rcu_torture *rp)
92109 i = rp->rtort_pipe_count;
92110 if (i > RCU_TORTURE_PIPE_LEN)
92111 i = RCU_TORTURE_PIPE_LEN;
92112- atomic_inc(&rcu_torture_wcount[i]);
92113+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
92114 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
92115 rp->rtort_mbtest = 0;
92116 return true;
92117@@ -808,7 +808,7 @@ rcu_torture_writer(void *arg)
92118 i = old_rp->rtort_pipe_count;
92119 if (i > RCU_TORTURE_PIPE_LEN)
92120 i = RCU_TORTURE_PIPE_LEN;
92121- atomic_inc(&rcu_torture_wcount[i]);
92122+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
92123 old_rp->rtort_pipe_count++;
92124 switch (synctype[torture_random(&rand) % nsynctypes]) {
92125 case RTWS_DEF_FREE:
92126@@ -926,7 +926,7 @@ static void rcu_torture_timer(unsigned long unused)
92127 return;
92128 }
92129 if (p->rtort_mbtest == 0)
92130- atomic_inc(&n_rcu_torture_mberror);
92131+ atomic_inc_unchecked(&n_rcu_torture_mberror);
92132 spin_lock(&rand_lock);
92133 cur_ops->read_delay(&rand);
92134 n_rcu_torture_timers++;
92135@@ -996,7 +996,7 @@ rcu_torture_reader(void *arg)
92136 continue;
92137 }
92138 if (p->rtort_mbtest == 0)
92139- atomic_inc(&n_rcu_torture_mberror);
92140+ atomic_inc_unchecked(&n_rcu_torture_mberror);
92141 cur_ops->read_delay(&rand);
92142 preempt_disable();
92143 pipe_count = p->rtort_pipe_count;
92144@@ -1054,15 +1054,15 @@ rcu_torture_printk(char *page)
92145 }
92146 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
92147 page += sprintf(page,
92148- "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
92149+ "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
92150 rcu_torture_current,
92151 rcu_torture_current_version,
92152 list_empty(&rcu_torture_freelist),
92153- atomic_read(&n_rcu_torture_alloc),
92154- atomic_read(&n_rcu_torture_alloc_fail),
92155- atomic_read(&n_rcu_torture_free));
92156+ atomic_read_unchecked(&n_rcu_torture_alloc),
92157+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
92158+ atomic_read_unchecked(&n_rcu_torture_free));
92159 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
92160- atomic_read(&n_rcu_torture_mberror),
92161+ atomic_read_unchecked(&n_rcu_torture_mberror),
92162 n_rcu_torture_boost_ktrerror,
92163 n_rcu_torture_boost_rterror);
92164 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
92165@@ -1075,14 +1075,14 @@ rcu_torture_printk(char *page)
92166 n_barrier_attempts,
92167 n_rcu_torture_barrier_error);
92168 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
92169- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
92170+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
92171 n_rcu_torture_barrier_error != 0 ||
92172 n_rcu_torture_boost_ktrerror != 0 ||
92173 n_rcu_torture_boost_rterror != 0 ||
92174 n_rcu_torture_boost_failure != 0 ||
92175 i > 1) {
92176 page += sprintf(page, "!!! ");
92177- atomic_inc(&n_rcu_torture_error);
92178+ atomic_inc_unchecked(&n_rcu_torture_error);
92179 WARN_ON_ONCE(1);
92180 }
92181 page += sprintf(page, "Reader Pipe: ");
92182@@ -1096,7 +1096,7 @@ rcu_torture_printk(char *page)
92183 page += sprintf(page, "Free-Block Circulation: ");
92184 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
92185 page += sprintf(page, " %d",
92186- atomic_read(&rcu_torture_wcount[i]));
92187+ atomic_read_unchecked(&rcu_torture_wcount[i]));
92188 }
92189 page += sprintf(page, "\n");
92190 if (cur_ops->stats)
92191@@ -1461,7 +1461,7 @@ rcu_torture_cleanup(void)
92192
92193 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
92194
92195- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
92196+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
92197 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
92198 else if (torture_onoff_failures())
92199 rcu_torture_print_module_parms(cur_ops,
92200@@ -1584,18 +1584,18 @@ rcu_torture_init(void)
92201
92202 rcu_torture_current = NULL;
92203 rcu_torture_current_version = 0;
92204- atomic_set(&n_rcu_torture_alloc, 0);
92205- atomic_set(&n_rcu_torture_alloc_fail, 0);
92206- atomic_set(&n_rcu_torture_free, 0);
92207- atomic_set(&n_rcu_torture_mberror, 0);
92208- atomic_set(&n_rcu_torture_error, 0);
92209+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
92210+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
92211+ atomic_set_unchecked(&n_rcu_torture_free, 0);
92212+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
92213+ atomic_set_unchecked(&n_rcu_torture_error, 0);
92214 n_rcu_torture_barrier_error = 0;
92215 n_rcu_torture_boost_ktrerror = 0;
92216 n_rcu_torture_boost_rterror = 0;
92217 n_rcu_torture_boost_failure = 0;
92218 n_rcu_torture_boosts = 0;
92219 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
92220- atomic_set(&rcu_torture_wcount[i], 0);
92221+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
92222 for_each_possible_cpu(cpu) {
92223 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
92224 per_cpu(rcu_torture_count, cpu)[i] = 0;
92225diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
92226index d9efcc1..ea543e9 100644
92227--- a/kernel/rcu/tiny.c
92228+++ b/kernel/rcu/tiny.c
92229@@ -42,7 +42,7 @@
92230 /* Forward declarations for tiny_plugin.h. */
92231 struct rcu_ctrlblk;
92232 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
92233-static void rcu_process_callbacks(struct softirq_action *unused);
92234+static void rcu_process_callbacks(void);
92235 static void __call_rcu(struct rcu_head *head,
92236 void (*func)(struct rcu_head *rcu),
92237 struct rcu_ctrlblk *rcp);
92238@@ -308,7 +308,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
92239 false));
92240 }
92241
92242-static void rcu_process_callbacks(struct softirq_action *unused)
92243+static __latent_entropy void rcu_process_callbacks(void)
92244 {
92245 __rcu_process_callbacks(&rcu_sched_ctrlblk);
92246 __rcu_process_callbacks(&rcu_bh_ctrlblk);
92247diff --git a/kernel/rcu/tiny_plugin.h b/kernel/rcu/tiny_plugin.h
92248index 858c565..7efd915 100644
92249--- a/kernel/rcu/tiny_plugin.h
92250+++ b/kernel/rcu/tiny_plugin.h
92251@@ -152,17 +152,17 @@ static void check_cpu_stall(struct rcu_ctrlblk *rcp)
92252 dump_stack();
92253 }
92254 if (*rcp->curtail && ULONG_CMP_GE(j, js))
92255- ACCESS_ONCE(rcp->jiffies_stall) = jiffies +
92256+ ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies +
92257 3 * rcu_jiffies_till_stall_check() + 3;
92258 else if (ULONG_CMP_GE(j, js))
92259- ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
92260+ ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
92261 }
92262
92263 static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
92264 {
92265 rcp->ticks_this_gp = 0;
92266 rcp->gp_start = jiffies;
92267- ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
92268+ ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
92269 }
92270
92271 static void check_cpu_stalls(void)
92272diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
92273index 89a404a..f42a019 100644
92274--- a/kernel/rcu/tree.c
92275+++ b/kernel/rcu/tree.c
92276@@ -263,7 +263,7 @@ static void rcu_momentary_dyntick_idle(void)
92277 */
92278 rdtp = this_cpu_ptr(&rcu_dynticks);
92279 smp_mb__before_atomic(); /* Earlier stuff before QS. */
92280- atomic_add(2, &rdtp->dynticks); /* QS. */
92281+ atomic_add_unchecked(2, &rdtp->dynticks); /* QS. */
92282 smp_mb__after_atomic(); /* Later stuff after QS. */
92283 break;
92284 }
92285@@ -523,9 +523,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
92286 rcu_prepare_for_idle(smp_processor_id());
92287 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
92288 smp_mb__before_atomic(); /* See above. */
92289- atomic_inc(&rdtp->dynticks);
92290+ atomic_inc_unchecked(&rdtp->dynticks);
92291 smp_mb__after_atomic(); /* Force ordering with next sojourn. */
92292- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
92293+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
92294
92295 /*
92296 * It is illegal to enter an extended quiescent state while
92297@@ -643,10 +643,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
92298 int user)
92299 {
92300 smp_mb__before_atomic(); /* Force ordering w/previous sojourn. */
92301- atomic_inc(&rdtp->dynticks);
92302+ atomic_inc_unchecked(&rdtp->dynticks);
92303 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
92304 smp_mb__after_atomic(); /* See above. */
92305- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
92306+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
92307 rcu_cleanup_after_idle(smp_processor_id());
92308 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
92309 if (!user && !is_idle_task(current)) {
92310@@ -767,14 +767,14 @@ void rcu_nmi_enter(void)
92311 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
92312
92313 if (rdtp->dynticks_nmi_nesting == 0 &&
92314- (atomic_read(&rdtp->dynticks) & 0x1))
92315+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
92316 return;
92317 rdtp->dynticks_nmi_nesting++;
92318 smp_mb__before_atomic(); /* Force delay from prior write. */
92319- atomic_inc(&rdtp->dynticks);
92320+ atomic_inc_unchecked(&rdtp->dynticks);
92321 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
92322 smp_mb__after_atomic(); /* See above. */
92323- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
92324+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
92325 }
92326
92327 /**
92328@@ -793,9 +793,9 @@ void rcu_nmi_exit(void)
92329 return;
92330 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
92331 smp_mb__before_atomic(); /* See above. */
92332- atomic_inc(&rdtp->dynticks);
92333+ atomic_inc_unchecked(&rdtp->dynticks);
92334 smp_mb__after_atomic(); /* Force delay to next write. */
92335- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
92336+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
92337 }
92338
92339 /**
92340@@ -808,7 +808,7 @@ void rcu_nmi_exit(void)
92341 */
92342 bool notrace __rcu_is_watching(void)
92343 {
92344- return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
92345+ return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
92346 }
92347
92348 /**
92349@@ -891,7 +891,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
92350 static int dyntick_save_progress_counter(struct rcu_data *rdp,
92351 bool *isidle, unsigned long *maxj)
92352 {
92353- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
92354+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
92355 rcu_sysidle_check_cpu(rdp, isidle, maxj);
92356 if ((rdp->dynticks_snap & 0x1) == 0) {
92357 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti"));
92358@@ -920,7 +920,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
92359 int *rcrmp;
92360 unsigned int snap;
92361
92362- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
92363+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
92364 snap = (unsigned int)rdp->dynticks_snap;
92365
92366 /*
92367@@ -983,10 +983,10 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
92368 rdp->rsp->gp_start + jiffies_till_sched_qs) ||
92369 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
92370 if (!(ACCESS_ONCE(*rcrmp) & rdp->rsp->flavor_mask)) {
92371- ACCESS_ONCE(rdp->cond_resched_completed) =
92372+ ACCESS_ONCE_RW(rdp->cond_resched_completed) =
92373 ACCESS_ONCE(rdp->mynode->completed);
92374 smp_mb(); /* ->cond_resched_completed before *rcrmp. */
92375- ACCESS_ONCE(*rcrmp) =
92376+ ACCESS_ONCE_RW(*rcrmp) =
92377 ACCESS_ONCE(*rcrmp) + rdp->rsp->flavor_mask;
92378 resched_cpu(rdp->cpu); /* Force CPU into scheduler. */
92379 rdp->rsp->jiffies_resched += 5; /* Enable beating. */
92380@@ -1008,7 +1008,7 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
92381 rsp->gp_start = j;
92382 smp_wmb(); /* Record start time before stall time. */
92383 j1 = rcu_jiffies_till_stall_check();
92384- ACCESS_ONCE(rsp->jiffies_stall) = j + j1;
92385+ ACCESS_ONCE_RW(rsp->jiffies_stall) = j + j1;
92386 rsp->jiffies_resched = j + j1 / 2;
92387 }
92388
92389@@ -1049,7 +1049,7 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
92390 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92391 return;
92392 }
92393- ACCESS_ONCE(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
92394+ ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
92395 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92396
92397 /*
92398@@ -1126,7 +1126,7 @@ static void print_cpu_stall(struct rcu_state *rsp)
92399
92400 raw_spin_lock_irqsave(&rnp->lock, flags);
92401 if (ULONG_CMP_GE(jiffies, ACCESS_ONCE(rsp->jiffies_stall)))
92402- ACCESS_ONCE(rsp->jiffies_stall) = jiffies +
92403+ ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies +
92404 3 * rcu_jiffies_till_stall_check() + 3;
92405 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92406
92407@@ -1210,7 +1210,7 @@ void rcu_cpu_stall_reset(void)
92408 struct rcu_state *rsp;
92409
92410 for_each_rcu_flavor(rsp)
92411- ACCESS_ONCE(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
92412+ ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
92413 }
92414
92415 /*
92416@@ -1596,7 +1596,7 @@ static int rcu_gp_init(struct rcu_state *rsp)
92417 raw_spin_unlock_irq(&rnp->lock);
92418 return 0;
92419 }
92420- ACCESS_ONCE(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
92421+ ACCESS_ONCE_RW(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
92422
92423 if (WARN_ON_ONCE(rcu_gp_in_progress(rsp))) {
92424 /*
92425@@ -1637,9 +1637,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
92426 rdp = this_cpu_ptr(rsp->rda);
92427 rcu_preempt_check_blocked_tasks(rnp);
92428 rnp->qsmask = rnp->qsmaskinit;
92429- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
92430+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
92431 WARN_ON_ONCE(rnp->completed != rsp->completed);
92432- ACCESS_ONCE(rnp->completed) = rsp->completed;
92433+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
92434 if (rnp == rdp->mynode)
92435 (void)__note_gp_changes(rsp, rnp, rdp);
92436 rcu_preempt_boost_start_gp(rnp);
92437@@ -1684,7 +1684,7 @@ static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
92438 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
92439 raw_spin_lock_irq(&rnp->lock);
92440 smp_mb__after_unlock_lock();
92441- ACCESS_ONCE(rsp->gp_flags) &= ~RCU_GP_FLAG_FQS;
92442+ ACCESS_ONCE_RW(rsp->gp_flags) &= ~RCU_GP_FLAG_FQS;
92443 raw_spin_unlock_irq(&rnp->lock);
92444 }
92445 return fqs_state;
92446@@ -1729,7 +1729,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
92447 rcu_for_each_node_breadth_first(rsp, rnp) {
92448 raw_spin_lock_irq(&rnp->lock);
92449 smp_mb__after_unlock_lock();
92450- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
92451+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
92452 rdp = this_cpu_ptr(rsp->rda);
92453 if (rnp == rdp->mynode)
92454 needgp = __note_gp_changes(rsp, rnp, rdp) || needgp;
92455@@ -1744,14 +1744,14 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
92456 rcu_nocb_gp_set(rnp, nocb);
92457
92458 /* Declare grace period done. */
92459- ACCESS_ONCE(rsp->completed) = rsp->gpnum;
92460+ ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
92461 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
92462 rsp->fqs_state = RCU_GP_IDLE;
92463 rdp = this_cpu_ptr(rsp->rda);
92464 /* Advance CBs to reduce false positives below. */
92465 needgp = rcu_advance_cbs(rsp, rnp, rdp) || needgp;
92466 if (needgp || cpu_needs_another_gp(rsp, rdp)) {
92467- ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92468+ ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92469 trace_rcu_grace_period(rsp->name,
92470 ACCESS_ONCE(rsp->gpnum),
92471 TPS("newreq"));
92472@@ -1876,7 +1876,7 @@ rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
92473 */
92474 return false;
92475 }
92476- ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92477+ ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92478 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum),
92479 TPS("newreq"));
92480
92481@@ -2097,7 +2097,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
92482 rsp->qlen += rdp->qlen;
92483 rdp->n_cbs_orphaned += rdp->qlen;
92484 rdp->qlen_lazy = 0;
92485- ACCESS_ONCE(rdp->qlen) = 0;
92486+ ACCESS_ONCE_RW(rdp->qlen) = 0;
92487 }
92488
92489 /*
92490@@ -2344,7 +2344,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
92491 }
92492 smp_mb(); /* List handling before counting for rcu_barrier(). */
92493 rdp->qlen_lazy -= count_lazy;
92494- ACCESS_ONCE(rdp->qlen) = rdp->qlen - count;
92495+ ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen - count;
92496 rdp->n_cbs_invoked += count;
92497
92498 /* Reinstate batch limit if we have worked down the excess. */
92499@@ -2505,7 +2505,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
92500 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
92501 return; /* Someone beat us to it. */
92502 }
92503- ACCESS_ONCE(rsp->gp_flags) |= RCU_GP_FLAG_FQS;
92504+ ACCESS_ONCE_RW(rsp->gp_flags) |= RCU_GP_FLAG_FQS;
92505 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
92506 rcu_gp_kthread_wake(rsp);
92507 }
92508@@ -2550,7 +2550,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
92509 /*
92510 * Do RCU core processing for the current CPU.
92511 */
92512-static void rcu_process_callbacks(struct softirq_action *unused)
92513+static void rcu_process_callbacks(void)
92514 {
92515 struct rcu_state *rsp;
92516
92517@@ -2662,7 +2662,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
92518 WARN_ON_ONCE((unsigned long)head & 0x1); /* Misaligned rcu_head! */
92519 if (debug_rcu_head_queue(head)) {
92520 /* Probable double call_rcu(), so leak the callback. */
92521- ACCESS_ONCE(head->func) = rcu_leak_callback;
92522+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
92523 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
92524 return;
92525 }
92526@@ -2690,7 +2690,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
92527 local_irq_restore(flags);
92528 return;
92529 }
92530- ACCESS_ONCE(rdp->qlen) = rdp->qlen + 1;
92531+ ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen + 1;
92532 if (lazy)
92533 rdp->qlen_lazy++;
92534 else
92535@@ -2965,11 +2965,11 @@ void synchronize_sched_expedited(void)
92536 * counter wrap on a 32-bit system. Quite a few more CPUs would of
92537 * course be required on a 64-bit system.
92538 */
92539- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
92540+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
92541 (ulong)atomic_long_read(&rsp->expedited_done) +
92542 ULONG_MAX / 8)) {
92543 synchronize_sched();
92544- atomic_long_inc(&rsp->expedited_wrap);
92545+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
92546 return;
92547 }
92548
92549@@ -2977,7 +2977,7 @@ void synchronize_sched_expedited(void)
92550 * Take a ticket. Note that atomic_inc_return() implies a
92551 * full memory barrier.
92552 */
92553- snap = atomic_long_inc_return(&rsp->expedited_start);
92554+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
92555 firstsnap = snap;
92556 get_online_cpus();
92557 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
92558@@ -2990,14 +2990,14 @@ void synchronize_sched_expedited(void)
92559 synchronize_sched_expedited_cpu_stop,
92560 NULL) == -EAGAIN) {
92561 put_online_cpus();
92562- atomic_long_inc(&rsp->expedited_tryfail);
92563+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
92564
92565 /* Check to see if someone else did our work for us. */
92566 s = atomic_long_read(&rsp->expedited_done);
92567 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
92568 /* ensure test happens before caller kfree */
92569 smp_mb__before_atomic(); /* ^^^ */
92570- atomic_long_inc(&rsp->expedited_workdone1);
92571+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
92572 return;
92573 }
92574
92575@@ -3006,7 +3006,7 @@ void synchronize_sched_expedited(void)
92576 udelay(trycount * num_online_cpus());
92577 } else {
92578 wait_rcu_gp(call_rcu_sched);
92579- atomic_long_inc(&rsp->expedited_normal);
92580+ atomic_long_inc_unchecked(&rsp->expedited_normal);
92581 return;
92582 }
92583
92584@@ -3015,7 +3015,7 @@ void synchronize_sched_expedited(void)
92585 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
92586 /* ensure test happens before caller kfree */
92587 smp_mb__before_atomic(); /* ^^^ */
92588- atomic_long_inc(&rsp->expedited_workdone2);
92589+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
92590 return;
92591 }
92592
92593@@ -3027,10 +3027,10 @@ void synchronize_sched_expedited(void)
92594 * period works for us.
92595 */
92596 get_online_cpus();
92597- snap = atomic_long_read(&rsp->expedited_start);
92598+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
92599 smp_mb(); /* ensure read is before try_stop_cpus(). */
92600 }
92601- atomic_long_inc(&rsp->expedited_stoppedcpus);
92602+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
92603
92604 /*
92605 * Everyone up to our most recent fetch is covered by our grace
92606@@ -3039,16 +3039,16 @@ void synchronize_sched_expedited(void)
92607 * than we did already did their update.
92608 */
92609 do {
92610- atomic_long_inc(&rsp->expedited_done_tries);
92611+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
92612 s = atomic_long_read(&rsp->expedited_done);
92613 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
92614 /* ensure test happens before caller kfree */
92615 smp_mb__before_atomic(); /* ^^^ */
92616- atomic_long_inc(&rsp->expedited_done_lost);
92617+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
92618 break;
92619 }
92620 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
92621- atomic_long_inc(&rsp->expedited_done_exit);
92622+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
92623
92624 put_online_cpus();
92625 }
92626@@ -3254,7 +3254,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
92627 * ACCESS_ONCE() to prevent the compiler from speculating
92628 * the increment to precede the early-exit check.
92629 */
92630- ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92631+ ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92632 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
92633 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
92634 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
92635@@ -3304,7 +3304,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
92636
92637 /* Increment ->n_barrier_done to prevent duplicate work. */
92638 smp_mb(); /* Keep increment after above mechanism. */
92639- ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92640+ ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92641 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
92642 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
92643 smp_mb(); /* Keep increment before caller's subsequent code. */
92644@@ -3349,10 +3349,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
92645 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
92646 init_callback_list(rdp);
92647 rdp->qlen_lazy = 0;
92648- ACCESS_ONCE(rdp->qlen) = 0;
92649+ ACCESS_ONCE_RW(rdp->qlen) = 0;
92650 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
92651 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
92652- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
92653+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
92654 rdp->cpu = cpu;
92655 rdp->rsp = rsp;
92656 rcu_boot_init_nocb_percpu_data(rdp);
92657@@ -3385,8 +3385,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
92658 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
92659 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
92660 rcu_sysidle_init_percpu_data(rdp->dynticks);
92661- atomic_set(&rdp->dynticks->dynticks,
92662- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
92663+ atomic_set_unchecked(&rdp->dynticks->dynticks,
92664+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
92665 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
92666
92667 /* Add CPU to rcu_node bitmasks. */
92668diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
92669index 6a86eb7..022b506 100644
92670--- a/kernel/rcu/tree.h
92671+++ b/kernel/rcu/tree.h
92672@@ -87,11 +87,11 @@ struct rcu_dynticks {
92673 long long dynticks_nesting; /* Track irq/process nesting level. */
92674 /* Process level is worth LLONG_MAX/2. */
92675 int dynticks_nmi_nesting; /* Track NMI nesting level. */
92676- atomic_t dynticks; /* Even value for idle, else odd. */
92677+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
92678 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
92679 long long dynticks_idle_nesting;
92680 /* irq/process nesting level from idle. */
92681- atomic_t dynticks_idle; /* Even value for idle, else odd. */
92682+ atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
92683 /* "Idle" excludes userspace execution. */
92684 unsigned long dynticks_idle_jiffies;
92685 /* End of last non-NMI non-idle period. */
92686@@ -461,17 +461,17 @@ struct rcu_state {
92687 /* _rcu_barrier(). */
92688 /* End of fields guarded by barrier_mutex. */
92689
92690- atomic_long_t expedited_start; /* Starting ticket. */
92691- atomic_long_t expedited_done; /* Done ticket. */
92692- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
92693- atomic_long_t expedited_tryfail; /* # acquisition failures. */
92694- atomic_long_t expedited_workdone1; /* # done by others #1. */
92695- atomic_long_t expedited_workdone2; /* # done by others #2. */
92696- atomic_long_t expedited_normal; /* # fallbacks to normal. */
92697- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
92698- atomic_long_t expedited_done_tries; /* # tries to update _done. */
92699- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
92700- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
92701+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
92702+ atomic_long_t expedited_done; /* Done ticket. */
92703+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
92704+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
92705+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
92706+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
92707+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
92708+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
92709+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
92710+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
92711+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
92712
92713 unsigned long jiffies_force_qs; /* Time at which to invoke */
92714 /* force_quiescent_state(). */
92715diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
92716index a7997e2..9787c9e 100644
92717--- a/kernel/rcu/tree_plugin.h
92718+++ b/kernel/rcu/tree_plugin.h
92719@@ -735,7 +735,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
92720 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
92721 {
92722 return !rcu_preempted_readers_exp(rnp) &&
92723- ACCESS_ONCE(rnp->expmask) == 0;
92724+ ACCESS_ONCE_RW(rnp->expmask) == 0;
92725 }
92726
92727 /*
92728@@ -897,7 +897,7 @@ void synchronize_rcu_expedited(void)
92729
92730 /* Clean up and exit. */
92731 smp_mb(); /* ensure expedited GP seen before counter increment. */
92732- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
92733+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
92734 unlock_mb_ret:
92735 mutex_unlock(&sync_rcu_preempt_exp_mutex);
92736 mb_ret:
92737@@ -1452,7 +1452,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
92738 free_cpumask_var(cm);
92739 }
92740
92741-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
92742+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
92743 .store = &rcu_cpu_kthread_task,
92744 .thread_should_run = rcu_cpu_kthread_should_run,
92745 .thread_fn = rcu_cpu_kthread,
92746@@ -1932,7 +1932,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
92747 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
92748 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
92749 cpu, ticks_value, ticks_title,
92750- atomic_read(&rdtp->dynticks) & 0xfff,
92751+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
92752 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
92753 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
92754 fast_no_hz);
92755@@ -2076,7 +2076,7 @@ static void wake_nocb_leader(struct rcu_data *rdp, bool force)
92756 return;
92757 if (ACCESS_ONCE(rdp_leader->nocb_leader_sleep) || force) {
92758 /* Prior xchg orders against prior callback enqueue. */
92759- ACCESS_ONCE(rdp_leader->nocb_leader_sleep) = false;
92760+ ACCESS_ONCE_RW(rdp_leader->nocb_leader_sleep) = false;
92761 wake_up(&rdp_leader->nocb_wq);
92762 }
92763 }
92764@@ -2101,7 +2101,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
92765
92766 /* Enqueue the callback on the nocb list and update counts. */
92767 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
92768- ACCESS_ONCE(*old_rhpp) = rhp;
92769+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
92770 atomic_long_add(rhcount, &rdp->nocb_q_count);
92771 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
92772
92773@@ -2272,7 +2272,7 @@ wait_again:
92774 continue; /* No CBs here, try next follower. */
92775
92776 /* Move callbacks to wait-for-GP list, which is empty. */
92777- ACCESS_ONCE(rdp->nocb_head) = NULL;
92778+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
92779 rdp->nocb_gp_tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
92780 rdp->nocb_gp_count = atomic_long_xchg(&rdp->nocb_q_count, 0);
92781 rdp->nocb_gp_count_lazy =
92782@@ -2398,7 +2398,7 @@ static int rcu_nocb_kthread(void *arg)
92783 list = ACCESS_ONCE(rdp->nocb_follower_head);
92784 BUG_ON(!list);
92785 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, "WokeNonEmpty");
92786- ACCESS_ONCE(rdp->nocb_follower_head) = NULL;
92787+ ACCESS_ONCE_RW(rdp->nocb_follower_head) = NULL;
92788 tail = xchg(&rdp->nocb_follower_tail, &rdp->nocb_follower_head);
92789 c = atomic_long_xchg(&rdp->nocb_follower_count, 0);
92790 cl = atomic_long_xchg(&rdp->nocb_follower_count_lazy, 0);
92791@@ -2428,8 +2428,8 @@ static int rcu_nocb_kthread(void *arg)
92792 list = next;
92793 }
92794 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
92795- ACCESS_ONCE(rdp->nocb_p_count) -= c;
92796- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
92797+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
92798+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
92799 rdp->n_nocbs_invoked += c;
92800 }
92801 return 0;
92802@@ -2446,7 +2446,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
92803 {
92804 if (!rcu_nocb_need_deferred_wakeup(rdp))
92805 return;
92806- ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
92807+ ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
92808 wake_nocb_leader(rdp, false);
92809 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
92810 }
92811@@ -2510,7 +2510,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
92812 t = kthread_run(rcu_nocb_kthread, rdp,
92813 "rcuo%c/%d", rsp->abbr, cpu);
92814 BUG_ON(IS_ERR(t));
92815- ACCESS_ONCE(rdp->nocb_kthread) = t;
92816+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
92817 }
92818 }
92819
92820@@ -2641,11 +2641,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
92821
92822 /* Record start of fully idle period. */
92823 j = jiffies;
92824- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
92825+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
92826 smp_mb__before_atomic();
92827- atomic_inc(&rdtp->dynticks_idle);
92828+ atomic_inc_unchecked(&rdtp->dynticks_idle);
92829 smp_mb__after_atomic();
92830- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
92831+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
92832 }
92833
92834 /*
92835@@ -2710,9 +2710,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
92836
92837 /* Record end of idle period. */
92838 smp_mb__before_atomic();
92839- atomic_inc(&rdtp->dynticks_idle);
92840+ atomic_inc_unchecked(&rdtp->dynticks_idle);
92841 smp_mb__after_atomic();
92842- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
92843+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
92844
92845 /*
92846 * If we are the timekeeping CPU, we are permitted to be non-idle
92847@@ -2753,7 +2753,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
92848 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
92849
92850 /* Pick up current idle and NMI-nesting counter and check. */
92851- cur = atomic_read(&rdtp->dynticks_idle);
92852+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
92853 if (cur & 0x1) {
92854 *isidle = false; /* We are not idle! */
92855 return;
92856@@ -2802,7 +2802,7 @@ static void rcu_sysidle(unsigned long j)
92857 case RCU_SYSIDLE_NOT:
92858
92859 /* First time all are idle, so note a short idle period. */
92860- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92861+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92862 break;
92863
92864 case RCU_SYSIDLE_SHORT:
92865@@ -2840,7 +2840,7 @@ static void rcu_sysidle_cancel(void)
92866 {
92867 smp_mb();
92868 if (full_sysidle_state > RCU_SYSIDLE_SHORT)
92869- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
92870+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
92871 }
92872
92873 /*
92874@@ -2888,7 +2888,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
92875 smp_mb(); /* grace period precedes setting inuse. */
92876
92877 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
92878- ACCESS_ONCE(rshp->inuse) = 0;
92879+ ACCESS_ONCE_RW(rshp->inuse) = 0;
92880 }
92881
92882 /*
92883diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
92884index 5cdc62e..cc52e88 100644
92885--- a/kernel/rcu/tree_trace.c
92886+++ b/kernel/rcu/tree_trace.c
92887@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
92888 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
92889 rdp->passed_quiesce, rdp->qs_pending);
92890 seq_printf(m, " dt=%d/%llx/%d df=%lu",
92891- atomic_read(&rdp->dynticks->dynticks),
92892+ atomic_read_unchecked(&rdp->dynticks->dynticks),
92893 rdp->dynticks->dynticks_nesting,
92894 rdp->dynticks->dynticks_nmi_nesting,
92895 rdp->dynticks_fqs);
92896@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
92897 struct rcu_state *rsp = (struct rcu_state *)m->private;
92898
92899 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",
92900- atomic_long_read(&rsp->expedited_start),
92901+ atomic_long_read_unchecked(&rsp->expedited_start),
92902 atomic_long_read(&rsp->expedited_done),
92903- atomic_long_read(&rsp->expedited_wrap),
92904- atomic_long_read(&rsp->expedited_tryfail),
92905- atomic_long_read(&rsp->expedited_workdone1),
92906- atomic_long_read(&rsp->expedited_workdone2),
92907- atomic_long_read(&rsp->expedited_normal),
92908- atomic_long_read(&rsp->expedited_stoppedcpus),
92909- atomic_long_read(&rsp->expedited_done_tries),
92910- atomic_long_read(&rsp->expedited_done_lost),
92911- atomic_long_read(&rsp->expedited_done_exit));
92912+ atomic_long_read_unchecked(&rsp->expedited_wrap),
92913+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
92914+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
92915+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
92916+ atomic_long_read_unchecked(&rsp->expedited_normal),
92917+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
92918+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
92919+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
92920+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
92921 return 0;
92922 }
92923
92924diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
92925index 4056d79..c11741a 100644
92926--- a/kernel/rcu/update.c
92927+++ b/kernel/rcu/update.c
92928@@ -308,10 +308,10 @@ int rcu_jiffies_till_stall_check(void)
92929 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
92930 */
92931 if (till_stall_check < 3) {
92932- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
92933+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
92934 till_stall_check = 3;
92935 } else if (till_stall_check > 300) {
92936- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
92937+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
92938 till_stall_check = 300;
92939 }
92940 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
92941diff --git a/kernel/resource.c b/kernel/resource.c
92942index 60c5a38..ed77193 100644
92943--- a/kernel/resource.c
92944+++ b/kernel/resource.c
92945@@ -161,8 +161,18 @@ static const struct file_operations proc_iomem_operations = {
92946
92947 static int __init ioresources_init(void)
92948 {
92949+#ifdef CONFIG_GRKERNSEC_PROC_ADD
92950+#ifdef CONFIG_GRKERNSEC_PROC_USER
92951+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
92952+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
92953+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
92954+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
92955+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
92956+#endif
92957+#else
92958 proc_create("ioports", 0, NULL, &proc_ioports_operations);
92959 proc_create("iomem", 0, NULL, &proc_iomem_operations);
92960+#endif
92961 return 0;
92962 }
92963 __initcall(ioresources_init);
92964diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
92965index e73efba..c9bfbd4 100644
92966--- a/kernel/sched/auto_group.c
92967+++ b/kernel/sched/auto_group.c
92968@@ -11,7 +11,7 @@
92969
92970 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
92971 static struct autogroup autogroup_default;
92972-static atomic_t autogroup_seq_nr;
92973+static atomic_unchecked_t autogroup_seq_nr;
92974
92975 void __init autogroup_init(struct task_struct *init_task)
92976 {
92977@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
92978
92979 kref_init(&ag->kref);
92980 init_rwsem(&ag->lock);
92981- ag->id = atomic_inc_return(&autogroup_seq_nr);
92982+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
92983 ag->tg = tg;
92984 #ifdef CONFIG_RT_GROUP_SCHED
92985 /*
92986diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
92987index a63f4dc..349bbb0 100644
92988--- a/kernel/sched/completion.c
92989+++ b/kernel/sched/completion.c
92990@@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
92991 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92992 * or number of jiffies left till timeout) if completed.
92993 */
92994-long __sched
92995+long __sched __intentional_overflow(-1)
92996 wait_for_completion_interruptible_timeout(struct completion *x,
92997 unsigned long timeout)
92998 {
92999@@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
93000 *
93001 * Return: -ERESTARTSYS if interrupted, 0 if completed.
93002 */
93003-int __sched wait_for_completion_killable(struct completion *x)
93004+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
93005 {
93006 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
93007 if (t == -ERESTARTSYS)
93008@@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
93009 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
93010 * or number of jiffies left till timeout) if completed.
93011 */
93012-long __sched
93013+long __sched __intentional_overflow(-1)
93014 wait_for_completion_killable_timeout(struct completion *x,
93015 unsigned long timeout)
93016 {
93017diff --git a/kernel/sched/core.c b/kernel/sched/core.c
93018index 6d7cb91..420f2d2 100644
93019--- a/kernel/sched/core.c
93020+++ b/kernel/sched/core.c
93021@@ -1857,7 +1857,7 @@ void set_numabalancing_state(bool enabled)
93022 int sysctl_numa_balancing(struct ctl_table *table, int write,
93023 void __user *buffer, size_t *lenp, loff_t *ppos)
93024 {
93025- struct ctl_table t;
93026+ ctl_table_no_const t;
93027 int err;
93028 int state = numabalancing_enabled;
93029
93030@@ -2324,8 +2324,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
93031 next->active_mm = oldmm;
93032 atomic_inc(&oldmm->mm_count);
93033 enter_lazy_tlb(oldmm, next);
93034- } else
93035+ } else {
93036 switch_mm(oldmm, mm, next);
93037+ populate_stack();
93038+ }
93039
93040 if (!prev->mm) {
93041 prev->active_mm = NULL;
93042@@ -3107,6 +3109,8 @@ int can_nice(const struct task_struct *p, const int nice)
93043 /* convert nice value [19,-20] to rlimit style value [1,40] */
93044 int nice_rlim = nice_to_rlimit(nice);
93045
93046+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
93047+
93048 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
93049 capable(CAP_SYS_NICE));
93050 }
93051@@ -3133,7 +3137,8 @@ SYSCALL_DEFINE1(nice, int, increment)
93052 nice = task_nice(current) + increment;
93053
93054 nice = clamp_val(nice, MIN_NICE, MAX_NICE);
93055- if (increment < 0 && !can_nice(current, nice))
93056+ if (increment < 0 && (!can_nice(current, nice) ||
93057+ gr_handle_chroot_nice()))
93058 return -EPERM;
93059
93060 retval = security_task_setnice(current, nice);
93061@@ -3412,6 +3417,7 @@ recheck:
93062 if (policy != p->policy && !rlim_rtprio)
93063 return -EPERM;
93064
93065+ gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
93066 /* can't increase priority */
93067 if (attr->sched_priority > p->rt_priority &&
93068 attr->sched_priority > rlim_rtprio)
93069@@ -4802,6 +4808,7 @@ void idle_task_exit(void)
93070
93071 if (mm != &init_mm) {
93072 switch_mm(mm, &init_mm, current);
93073+ populate_stack();
93074 finish_arch_post_lock_switch();
93075 }
93076 mmdrop(mm);
93077@@ -4897,7 +4904,7 @@ static void migrate_tasks(unsigned int dead_cpu)
93078
93079 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
93080
93081-static struct ctl_table sd_ctl_dir[] = {
93082+static ctl_table_no_const sd_ctl_dir[] __read_only = {
93083 {
93084 .procname = "sched_domain",
93085 .mode = 0555,
93086@@ -4914,17 +4921,17 @@ static struct ctl_table sd_ctl_root[] = {
93087 {}
93088 };
93089
93090-static struct ctl_table *sd_alloc_ctl_entry(int n)
93091+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
93092 {
93093- struct ctl_table *entry =
93094+ ctl_table_no_const *entry =
93095 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
93096
93097 return entry;
93098 }
93099
93100-static void sd_free_ctl_entry(struct ctl_table **tablep)
93101+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
93102 {
93103- struct ctl_table *entry;
93104+ ctl_table_no_const *entry;
93105
93106 /*
93107 * In the intermediate directories, both the child directory and
93108@@ -4932,22 +4939,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
93109 * will always be set. In the lowest directory the names are
93110 * static strings and all have proc handlers.
93111 */
93112- for (entry = *tablep; entry->mode; entry++) {
93113- if (entry->child)
93114- sd_free_ctl_entry(&entry->child);
93115+ for (entry = tablep; entry->mode; entry++) {
93116+ if (entry->child) {
93117+ sd_free_ctl_entry(entry->child);
93118+ pax_open_kernel();
93119+ entry->child = NULL;
93120+ pax_close_kernel();
93121+ }
93122 if (entry->proc_handler == NULL)
93123 kfree(entry->procname);
93124 }
93125
93126- kfree(*tablep);
93127- *tablep = NULL;
93128+ kfree(tablep);
93129 }
93130
93131 static int min_load_idx = 0;
93132 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
93133
93134 static void
93135-set_table_entry(struct ctl_table *entry,
93136+set_table_entry(ctl_table_no_const *entry,
93137 const char *procname, void *data, int maxlen,
93138 umode_t mode, proc_handler *proc_handler,
93139 bool load_idx)
93140@@ -4967,7 +4977,7 @@ set_table_entry(struct ctl_table *entry,
93141 static struct ctl_table *
93142 sd_alloc_ctl_domain_table(struct sched_domain *sd)
93143 {
93144- struct ctl_table *table = sd_alloc_ctl_entry(14);
93145+ ctl_table_no_const *table = sd_alloc_ctl_entry(14);
93146
93147 if (table == NULL)
93148 return NULL;
93149@@ -5005,9 +5015,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
93150 return table;
93151 }
93152
93153-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
93154+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
93155 {
93156- struct ctl_table *entry, *table;
93157+ ctl_table_no_const *entry, *table;
93158 struct sched_domain *sd;
93159 int domain_num = 0, i;
93160 char buf[32];
93161@@ -5034,11 +5044,13 @@ static struct ctl_table_header *sd_sysctl_header;
93162 static void register_sched_domain_sysctl(void)
93163 {
93164 int i, cpu_num = num_possible_cpus();
93165- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
93166+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
93167 char buf[32];
93168
93169 WARN_ON(sd_ctl_dir[0].child);
93170+ pax_open_kernel();
93171 sd_ctl_dir[0].child = entry;
93172+ pax_close_kernel();
93173
93174 if (entry == NULL)
93175 return;
93176@@ -5061,8 +5073,12 @@ static void unregister_sched_domain_sysctl(void)
93177 if (sd_sysctl_header)
93178 unregister_sysctl_table(sd_sysctl_header);
93179 sd_sysctl_header = NULL;
93180- if (sd_ctl_dir[0].child)
93181- sd_free_ctl_entry(&sd_ctl_dir[0].child);
93182+ if (sd_ctl_dir[0].child) {
93183+ sd_free_ctl_entry(sd_ctl_dir[0].child);
93184+ pax_open_kernel();
93185+ sd_ctl_dir[0].child = NULL;
93186+ pax_close_kernel();
93187+ }
93188 }
93189 #else
93190 static void register_sched_domain_sysctl(void)
93191diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
93192index bfa3c86..e58767c 100644
93193--- a/kernel/sched/fair.c
93194+++ b/kernel/sched/fair.c
93195@@ -1873,7 +1873,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
93196
93197 static void reset_ptenuma_scan(struct task_struct *p)
93198 {
93199- ACCESS_ONCE(p->mm->numa_scan_seq)++;
93200+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
93201 p->mm->numa_scan_offset = 0;
93202 }
93203
93204@@ -7339,7 +7339,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
93205 * run_rebalance_domains is triggered when needed from the scheduler tick.
93206 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
93207 */
93208-static void run_rebalance_domains(struct softirq_action *h)
93209+static __latent_entropy void run_rebalance_domains(void)
93210 {
93211 struct rq *this_rq = this_rq();
93212 enum cpu_idle_type idle = this_rq->idle_balance ?
93213diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
93214index 579712f..a338a9d 100644
93215--- a/kernel/sched/sched.h
93216+++ b/kernel/sched/sched.h
93217@@ -1146,7 +1146,7 @@ struct sched_class {
93218 #ifdef CONFIG_FAIR_GROUP_SCHED
93219 void (*task_move_group) (struct task_struct *p, int on_rq);
93220 #endif
93221-};
93222+} __do_const;
93223
93224 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
93225 {
93226diff --git a/kernel/seccomp.c b/kernel/seccomp.c
93227index 44eb005..84922be 100644
93228--- a/kernel/seccomp.c
93229+++ b/kernel/seccomp.c
93230@@ -395,16 +395,15 @@ static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog)
93231 if (!filter)
93232 goto free_prog;
93233
93234- filter->prog = kzalloc(bpf_prog_size(new_len),
93235- GFP_KERNEL|__GFP_NOWARN);
93236+ filter->prog = bpf_prog_alloc(bpf_prog_size(new_len), __GFP_NOWARN);
93237 if (!filter->prog)
93238 goto free_filter;
93239
93240 ret = bpf_convert_filter(fp, fprog->len, filter->prog->insnsi, &new_len);
93241 if (ret)
93242 goto free_filter_prog;
93243- kfree(fp);
93244
93245+ kfree(fp);
93246 atomic_set(&filter->usage, 1);
93247 filter->prog->len = new_len;
93248
93249@@ -413,7 +412,7 @@ static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog)
93250 return filter;
93251
93252 free_filter_prog:
93253- kfree(filter->prog);
93254+ __bpf_prog_free(filter->prog);
93255 free_filter:
93256 kfree(filter);
93257 free_prog:
93258diff --git a/kernel/signal.c b/kernel/signal.c
93259index 8f0876f..1153a5a 100644
93260--- a/kernel/signal.c
93261+++ b/kernel/signal.c
93262@@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
93263
93264 int print_fatal_signals __read_mostly;
93265
93266-static void __user *sig_handler(struct task_struct *t, int sig)
93267+static __sighandler_t sig_handler(struct task_struct *t, int sig)
93268 {
93269 return t->sighand->action[sig - 1].sa.sa_handler;
93270 }
93271
93272-static int sig_handler_ignored(void __user *handler, int sig)
93273+static int sig_handler_ignored(__sighandler_t handler, int sig)
93274 {
93275 /* Is it explicitly or implicitly ignored? */
93276 return handler == SIG_IGN ||
93277@@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
93278
93279 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
93280 {
93281- void __user *handler;
93282+ __sighandler_t handler;
93283
93284 handler = sig_handler(t, sig);
93285
93286@@ -372,6 +372,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
93287 atomic_inc(&user->sigpending);
93288 rcu_read_unlock();
93289
93290+ if (!override_rlimit)
93291+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
93292+
93293 if (override_rlimit ||
93294 atomic_read(&user->sigpending) <=
93295 task_rlimit(t, RLIMIT_SIGPENDING)) {
93296@@ -499,7 +502,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
93297
93298 int unhandled_signal(struct task_struct *tsk, int sig)
93299 {
93300- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
93301+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
93302 if (is_global_init(tsk))
93303 return 1;
93304 if (handler != SIG_IGN && handler != SIG_DFL)
93305@@ -793,6 +796,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
93306 }
93307 }
93308
93309+ /* allow glibc communication via tgkill to other threads in our
93310+ thread group */
93311+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
93312+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
93313+ && gr_handle_signal(t, sig))
93314+ return -EPERM;
93315+
93316 return security_task_kill(t, info, sig, 0);
93317 }
93318
93319@@ -1176,7 +1186,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
93320 return send_signal(sig, info, p, 1);
93321 }
93322
93323-static int
93324+int
93325 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93326 {
93327 return send_signal(sig, info, t, 0);
93328@@ -1213,6 +1223,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93329 unsigned long int flags;
93330 int ret, blocked, ignored;
93331 struct k_sigaction *action;
93332+ int is_unhandled = 0;
93333
93334 spin_lock_irqsave(&t->sighand->siglock, flags);
93335 action = &t->sighand->action[sig-1];
93336@@ -1227,9 +1238,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93337 }
93338 if (action->sa.sa_handler == SIG_DFL)
93339 t->signal->flags &= ~SIGNAL_UNKILLABLE;
93340+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
93341+ is_unhandled = 1;
93342 ret = specific_send_sig_info(sig, info, t);
93343 spin_unlock_irqrestore(&t->sighand->siglock, flags);
93344
93345+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
93346+ normal operation */
93347+ if (is_unhandled) {
93348+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
93349+ gr_handle_crash(t, sig);
93350+ }
93351+
93352 return ret;
93353 }
93354
93355@@ -1300,8 +1320,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
93356 ret = check_kill_permission(sig, info, p);
93357 rcu_read_unlock();
93358
93359- if (!ret && sig)
93360+ if (!ret && sig) {
93361 ret = do_send_sig_info(sig, info, p, true);
93362+ if (!ret)
93363+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
93364+ }
93365
93366 return ret;
93367 }
93368@@ -2903,7 +2926,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
93369 int error = -ESRCH;
93370
93371 rcu_read_lock();
93372- p = find_task_by_vpid(pid);
93373+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
93374+ /* allow glibc communication via tgkill to other threads in our
93375+ thread group */
93376+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
93377+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
93378+ p = find_task_by_vpid_unrestricted(pid);
93379+ else
93380+#endif
93381+ p = find_task_by_vpid(pid);
93382 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
93383 error = check_kill_permission(sig, info, p);
93384 /*
93385@@ -3236,8 +3267,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
93386 }
93387 seg = get_fs();
93388 set_fs(KERNEL_DS);
93389- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
93390- (stack_t __force __user *) &uoss,
93391+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
93392+ (stack_t __force_user *) &uoss,
93393 compat_user_stack_pointer());
93394 set_fs(seg);
93395 if (ret >= 0 && uoss_ptr) {
93396diff --git a/kernel/smpboot.c b/kernel/smpboot.c
93397index eb89e18..a4e6792 100644
93398--- a/kernel/smpboot.c
93399+++ b/kernel/smpboot.c
93400@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
93401 }
93402 smpboot_unpark_thread(plug_thread, cpu);
93403 }
93404- list_add(&plug_thread->list, &hotplug_threads);
93405+ pax_list_add(&plug_thread->list, &hotplug_threads);
93406 out:
93407 mutex_unlock(&smpboot_threads_lock);
93408 return ret;
93409@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
93410 {
93411 get_online_cpus();
93412 mutex_lock(&smpboot_threads_lock);
93413- list_del(&plug_thread->list);
93414+ pax_list_del(&plug_thread->list);
93415 smpboot_destroy_threads(plug_thread);
93416 mutex_unlock(&smpboot_threads_lock);
93417 put_online_cpus();
93418diff --git a/kernel/softirq.c b/kernel/softirq.c
93419index 5918d22..e95d1926 100644
93420--- a/kernel/softirq.c
93421+++ b/kernel/softirq.c
93422@@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
93423 EXPORT_SYMBOL(irq_stat);
93424 #endif
93425
93426-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
93427+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
93428
93429 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
93430
93431@@ -266,7 +266,7 @@ restart:
93432 kstat_incr_softirqs_this_cpu(vec_nr);
93433
93434 trace_softirq_entry(vec_nr);
93435- h->action(h);
93436+ h->action();
93437 trace_softirq_exit(vec_nr);
93438 if (unlikely(prev_count != preempt_count())) {
93439 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
93440@@ -426,7 +426,7 @@ void __raise_softirq_irqoff(unsigned int nr)
93441 or_softirq_pending(1UL << nr);
93442 }
93443
93444-void open_softirq(int nr, void (*action)(struct softirq_action *))
93445+void __init open_softirq(int nr, void (*action)(void))
93446 {
93447 softirq_vec[nr].action = action;
93448 }
93449@@ -478,7 +478,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
93450 }
93451 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
93452
93453-static void tasklet_action(struct softirq_action *a)
93454+static void tasklet_action(void)
93455 {
93456 struct tasklet_struct *list;
93457
93458@@ -514,7 +514,7 @@ static void tasklet_action(struct softirq_action *a)
93459 }
93460 }
93461
93462-static void tasklet_hi_action(struct softirq_action *a)
93463+static __latent_entropy void tasklet_hi_action(void)
93464 {
93465 struct tasklet_struct *list;
93466
93467@@ -741,7 +741,7 @@ static struct notifier_block cpu_nfb = {
93468 .notifier_call = cpu_callback
93469 };
93470
93471-static struct smp_hotplug_thread softirq_threads = {
93472+static struct smp_hotplug_thread softirq_threads __read_only = {
93473 .store = &ksoftirqd,
93474 .thread_should_run = ksoftirqd_should_run,
93475 .thread_fn = run_ksoftirqd,
93476diff --git a/kernel/sys.c b/kernel/sys.c
93477index ce81291..df2ca85 100644
93478--- a/kernel/sys.c
93479+++ b/kernel/sys.c
93480@@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
93481 error = -EACCES;
93482 goto out;
93483 }
93484+
93485+ if (gr_handle_chroot_setpriority(p, niceval)) {
93486+ error = -EACCES;
93487+ goto out;
93488+ }
93489+
93490 no_nice = security_task_setnice(p, niceval);
93491 if (no_nice) {
93492 error = no_nice;
93493@@ -351,6 +357,20 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
93494 goto error;
93495 }
93496
93497+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
93498+ goto error;
93499+
93500+ if (!gid_eq(new->gid, old->gid)) {
93501+ /* make sure we generate a learn log for what will
93502+ end up being a role transition after a full-learning
93503+ policy is generated
93504+ CAP_SETGID is required to perform a transition
93505+ we may not log a CAP_SETGID check above, e.g.
93506+ in the case where new rgid = old egid
93507+ */
93508+ gr_learn_cap(current, new, CAP_SETGID);
93509+ }
93510+
93511 if (rgid != (gid_t) -1 ||
93512 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
93513 new->sgid = new->egid;
93514@@ -386,6 +406,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
93515 old = current_cred();
93516
93517 retval = -EPERM;
93518+
93519+ if (gr_check_group_change(kgid, kgid, kgid))
93520+ goto error;
93521+
93522 if (ns_capable(old->user_ns, CAP_SETGID))
93523 new->gid = new->egid = new->sgid = new->fsgid = kgid;
93524 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
93525@@ -403,7 +427,7 @@ error:
93526 /*
93527 * change the user struct in a credentials set to match the new UID
93528 */
93529-static int set_user(struct cred *new)
93530+int set_user(struct cred *new)
93531 {
93532 struct user_struct *new_user;
93533
93534@@ -483,7 +507,18 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
93535 goto error;
93536 }
93537
93538+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
93539+ goto error;
93540+
93541 if (!uid_eq(new->uid, old->uid)) {
93542+ /* make sure we generate a learn log for what will
93543+ end up being a role transition after a full-learning
93544+ policy is generated
93545+ CAP_SETUID is required to perform a transition
93546+ we may not log a CAP_SETUID check above, e.g.
93547+ in the case where new ruid = old euid
93548+ */
93549+ gr_learn_cap(current, new, CAP_SETUID);
93550 retval = set_user(new);
93551 if (retval < 0)
93552 goto error;
93553@@ -533,6 +568,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
93554 old = current_cred();
93555
93556 retval = -EPERM;
93557+
93558+ if (gr_check_crash_uid(kuid))
93559+ goto error;
93560+ if (gr_check_user_change(kuid, kuid, kuid))
93561+ goto error;
93562+
93563 if (ns_capable(old->user_ns, CAP_SETUID)) {
93564 new->suid = new->uid = kuid;
93565 if (!uid_eq(kuid, old->uid)) {
93566@@ -602,6 +643,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
93567 goto error;
93568 }
93569
93570+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
93571+ goto error;
93572+
93573 if (ruid != (uid_t) -1) {
93574 new->uid = kruid;
93575 if (!uid_eq(kruid, old->uid)) {
93576@@ -684,6 +728,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
93577 goto error;
93578 }
93579
93580+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
93581+ goto error;
93582+
93583 if (rgid != (gid_t) -1)
93584 new->gid = krgid;
93585 if (egid != (gid_t) -1)
93586@@ -745,12 +792,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
93587 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
93588 ns_capable(old->user_ns, CAP_SETUID)) {
93589 if (!uid_eq(kuid, old->fsuid)) {
93590+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
93591+ goto error;
93592+
93593 new->fsuid = kuid;
93594 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
93595 goto change_okay;
93596 }
93597 }
93598
93599+error:
93600 abort_creds(new);
93601 return old_fsuid;
93602
93603@@ -783,12 +834,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
93604 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
93605 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
93606 ns_capable(old->user_ns, CAP_SETGID)) {
93607+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
93608+ goto error;
93609+
93610 if (!gid_eq(kgid, old->fsgid)) {
93611 new->fsgid = kgid;
93612 goto change_okay;
93613 }
93614 }
93615
93616+error:
93617 abort_creds(new);
93618 return old_fsgid;
93619
93620@@ -1167,19 +1222,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
93621 return -EFAULT;
93622
93623 down_read(&uts_sem);
93624- error = __copy_to_user(&name->sysname, &utsname()->sysname,
93625+ error = __copy_to_user(name->sysname, &utsname()->sysname,
93626 __OLD_UTS_LEN);
93627 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
93628- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
93629+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
93630 __OLD_UTS_LEN);
93631 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
93632- error |= __copy_to_user(&name->release, &utsname()->release,
93633+ error |= __copy_to_user(name->release, &utsname()->release,
93634 __OLD_UTS_LEN);
93635 error |= __put_user(0, name->release + __OLD_UTS_LEN);
93636- error |= __copy_to_user(&name->version, &utsname()->version,
93637+ error |= __copy_to_user(name->version, &utsname()->version,
93638 __OLD_UTS_LEN);
93639 error |= __put_user(0, name->version + __OLD_UTS_LEN);
93640- error |= __copy_to_user(&name->machine, &utsname()->machine,
93641+ error |= __copy_to_user(name->machine, &utsname()->machine,
93642 __OLD_UTS_LEN);
93643 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
93644 up_read(&uts_sem);
93645@@ -1381,6 +1436,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
93646 */
93647 new_rlim->rlim_cur = 1;
93648 }
93649+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
93650+ is changed to a lower value. Since tasks can be created by the same
93651+ user in between this limit change and an execve by this task, force
93652+ a recheck only for this task by setting PF_NPROC_EXCEEDED
93653+ */
93654+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
93655+ tsk->flags |= PF_NPROC_EXCEEDED;
93656 }
93657 if (!retval) {
93658 if (old_rlim)
93659diff --git a/kernel/sysctl.c b/kernel/sysctl.c
93660index 75875a7..cd8e838 100644
93661--- a/kernel/sysctl.c
93662+++ b/kernel/sysctl.c
93663@@ -94,7 +94,6 @@
93664
93665
93666 #if defined(CONFIG_SYSCTL)
93667-
93668 /* External variables not in a header file. */
93669 extern int max_threads;
93670 extern int suid_dumpable;
93671@@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
93672
93673 /* Constants used for minimum and maximum */
93674 #ifdef CONFIG_LOCKUP_DETECTOR
93675-static int sixty = 60;
93676+static int sixty __read_only = 60;
93677 #endif
93678
93679-static int __maybe_unused neg_one = -1;
93680+static int __maybe_unused neg_one __read_only = -1;
93681
93682-static int zero;
93683-static int __maybe_unused one = 1;
93684-static int __maybe_unused two = 2;
93685-static int __maybe_unused four = 4;
93686-static unsigned long one_ul = 1;
93687-static int one_hundred = 100;
93688+static int zero __read_only = 0;
93689+static int __maybe_unused one __read_only = 1;
93690+static int __maybe_unused two __read_only = 2;
93691+static int __maybe_unused three __read_only = 3;
93692+static int __maybe_unused four __read_only = 4;
93693+static unsigned long one_ul __read_only = 1;
93694+static int one_hundred __read_only = 100;
93695 #ifdef CONFIG_PRINTK
93696-static int ten_thousand = 10000;
93697+static int ten_thousand __read_only = 10000;
93698 #endif
93699
93700 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
93701@@ -181,10 +181,8 @@ static int proc_taint(struct ctl_table *table, int write,
93702 void __user *buffer, size_t *lenp, loff_t *ppos);
93703 #endif
93704
93705-#ifdef CONFIG_PRINTK
93706 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93707 void __user *buffer, size_t *lenp, loff_t *ppos);
93708-#endif
93709
93710 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
93711 void __user *buffer, size_t *lenp, loff_t *ppos);
93712@@ -215,6 +213,8 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write,
93713
93714 #endif
93715
93716+extern struct ctl_table grsecurity_table[];
93717+
93718 static struct ctl_table kern_table[];
93719 static struct ctl_table vm_table[];
93720 static struct ctl_table fs_table[];
93721@@ -229,6 +229,20 @@ extern struct ctl_table epoll_table[];
93722 int sysctl_legacy_va_layout;
93723 #endif
93724
93725+#ifdef CONFIG_PAX_SOFTMODE
93726+static struct ctl_table pax_table[] = {
93727+ {
93728+ .procname = "softmode",
93729+ .data = &pax_softmode,
93730+ .maxlen = sizeof(unsigned int),
93731+ .mode = 0600,
93732+ .proc_handler = &proc_dointvec,
93733+ },
93734+
93735+ { }
93736+};
93737+#endif
93738+
93739 /* The default sysctl tables: */
93740
93741 static struct ctl_table sysctl_base_table[] = {
93742@@ -277,6 +291,22 @@ static int max_extfrag_threshold = 1000;
93743 #endif
93744
93745 static struct ctl_table kern_table[] = {
93746+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
93747+ {
93748+ .procname = "grsecurity",
93749+ .mode = 0500,
93750+ .child = grsecurity_table,
93751+ },
93752+#endif
93753+
93754+#ifdef CONFIG_PAX_SOFTMODE
93755+ {
93756+ .procname = "pax",
93757+ .mode = 0500,
93758+ .child = pax_table,
93759+ },
93760+#endif
93761+
93762 {
93763 .procname = "sched_child_runs_first",
93764 .data = &sysctl_sched_child_runs_first,
93765@@ -641,7 +671,7 @@ static struct ctl_table kern_table[] = {
93766 .data = &modprobe_path,
93767 .maxlen = KMOD_PATH_LEN,
93768 .mode = 0644,
93769- .proc_handler = proc_dostring,
93770+ .proc_handler = proc_dostring_modpriv,
93771 },
93772 {
93773 .procname = "modules_disabled",
93774@@ -808,16 +838,20 @@ static struct ctl_table kern_table[] = {
93775 .extra1 = &zero,
93776 .extra2 = &one,
93777 },
93778+#endif
93779 {
93780 .procname = "kptr_restrict",
93781 .data = &kptr_restrict,
93782 .maxlen = sizeof(int),
93783 .mode = 0644,
93784 .proc_handler = proc_dointvec_minmax_sysadmin,
93785+#ifdef CONFIG_GRKERNSEC_HIDESYM
93786+ .extra1 = &two,
93787+#else
93788 .extra1 = &zero,
93789+#endif
93790 .extra2 = &two,
93791 },
93792-#endif
93793 {
93794 .procname = "ngroups_max",
93795 .data = &ngroups_max,
93796@@ -1073,10 +1107,17 @@ static struct ctl_table kern_table[] = {
93797 */
93798 {
93799 .procname = "perf_event_paranoid",
93800- .data = &sysctl_perf_event_paranoid,
93801- .maxlen = sizeof(sysctl_perf_event_paranoid),
93802+ .data = &sysctl_perf_event_legitimately_concerned,
93803+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
93804 .mode = 0644,
93805- .proc_handler = proc_dointvec,
93806+ /* go ahead, be a hero */
93807+ .proc_handler = proc_dointvec_minmax_sysadmin,
93808+ .extra1 = &neg_one,
93809+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
93810+ .extra2 = &three,
93811+#else
93812+ .extra2 = &two,
93813+#endif
93814 },
93815 {
93816 .procname = "perf_event_mlock_kb",
93817@@ -1335,6 +1376,13 @@ static struct ctl_table vm_table[] = {
93818 .proc_handler = proc_dointvec_minmax,
93819 .extra1 = &zero,
93820 },
93821+ {
93822+ .procname = "heap_stack_gap",
93823+ .data = &sysctl_heap_stack_gap,
93824+ .maxlen = sizeof(sysctl_heap_stack_gap),
93825+ .mode = 0644,
93826+ .proc_handler = proc_doulongvec_minmax,
93827+ },
93828 #else
93829 {
93830 .procname = "nr_trim_pages",
93831@@ -1824,6 +1872,16 @@ int proc_dostring(struct ctl_table *table, int write,
93832 (char __user *)buffer, lenp, ppos);
93833 }
93834
93835+int proc_dostring_modpriv(struct ctl_table *table, int write,
93836+ void __user *buffer, size_t *lenp, loff_t *ppos)
93837+{
93838+ if (write && !capable(CAP_SYS_MODULE))
93839+ return -EPERM;
93840+
93841+ return _proc_do_string(table->data, table->maxlen, write,
93842+ buffer, lenp, ppos);
93843+}
93844+
93845 static size_t proc_skip_spaces(char **buf)
93846 {
93847 size_t ret;
93848@@ -1929,6 +1987,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
93849 len = strlen(tmp);
93850 if (len > *size)
93851 len = *size;
93852+ if (len > sizeof(tmp))
93853+ len = sizeof(tmp);
93854 if (copy_to_user(*buf, tmp, len))
93855 return -EFAULT;
93856 *size -= len;
93857@@ -2106,7 +2166,7 @@ int proc_dointvec(struct ctl_table *table, int write,
93858 static int proc_taint(struct ctl_table *table, int write,
93859 void __user *buffer, size_t *lenp, loff_t *ppos)
93860 {
93861- struct ctl_table t;
93862+ ctl_table_no_const t;
93863 unsigned long tmptaint = get_taint();
93864 int err;
93865
93866@@ -2134,7 +2194,6 @@ static int proc_taint(struct ctl_table *table, int write,
93867 return err;
93868 }
93869
93870-#ifdef CONFIG_PRINTK
93871 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93872 void __user *buffer, size_t *lenp, loff_t *ppos)
93873 {
93874@@ -2143,7 +2202,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93875
93876 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
93877 }
93878-#endif
93879
93880 struct do_proc_dointvec_minmax_conv_param {
93881 int *min;
93882@@ -2703,6 +2761,12 @@ int proc_dostring(struct ctl_table *table, int write,
93883 return -ENOSYS;
93884 }
93885
93886+int proc_dostring_modpriv(struct ctl_table *table, int write,
93887+ void __user *buffer, size_t *lenp, loff_t *ppos)
93888+{
93889+ return -ENOSYS;
93890+}
93891+
93892 int proc_dointvec(struct ctl_table *table, int write,
93893 void __user *buffer, size_t *lenp, loff_t *ppos)
93894 {
93895@@ -2759,5 +2823,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
93896 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
93897 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
93898 EXPORT_SYMBOL(proc_dostring);
93899+EXPORT_SYMBOL(proc_dostring_modpriv);
93900 EXPORT_SYMBOL(proc_doulongvec_minmax);
93901 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
93902diff --git a/kernel/taskstats.c b/kernel/taskstats.c
93903index 13d2f7c..c93d0b0 100644
93904--- a/kernel/taskstats.c
93905+++ b/kernel/taskstats.c
93906@@ -28,9 +28,12 @@
93907 #include <linux/fs.h>
93908 #include <linux/file.h>
93909 #include <linux/pid_namespace.h>
93910+#include <linux/grsecurity.h>
93911 #include <net/genetlink.h>
93912 #include <linux/atomic.h>
93913
93914+extern int gr_is_taskstats_denied(int pid);
93915+
93916 /*
93917 * Maximum length of a cpumask that can be specified in
93918 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
93919@@ -576,6 +579,9 @@ err:
93920
93921 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
93922 {
93923+ if (gr_is_taskstats_denied(current->pid))
93924+ return -EACCES;
93925+
93926 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
93927 return cmd_attr_register_cpumask(info);
93928 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
93929diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
93930index a7077d3..dd48a49 100644
93931--- a/kernel/time/alarmtimer.c
93932+++ b/kernel/time/alarmtimer.c
93933@@ -823,7 +823,7 @@ static int __init alarmtimer_init(void)
93934 struct platform_device *pdev;
93935 int error = 0;
93936 int i;
93937- struct k_clock alarm_clock = {
93938+ static struct k_clock alarm_clock = {
93939 .clock_getres = alarm_clock_getres,
93940 .clock_get = alarm_clock_get,
93941 .timer_create = alarm_timer_create,
93942diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
93943index 1c2fe7d..ce7483d 100644
93944--- a/kernel/time/hrtimer.c
93945+++ b/kernel/time/hrtimer.c
93946@@ -1399,7 +1399,7 @@ void hrtimer_peek_ahead_timers(void)
93947 local_irq_restore(flags);
93948 }
93949
93950-static void run_hrtimer_softirq(struct softirq_action *h)
93951+static __latent_entropy void run_hrtimer_softirq(void)
93952 {
93953 hrtimer_peek_ahead_timers();
93954 }
93955diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
93956index 3b89464..5e38379 100644
93957--- a/kernel/time/posix-cpu-timers.c
93958+++ b/kernel/time/posix-cpu-timers.c
93959@@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
93960
93961 static __init int init_posix_cpu_timers(void)
93962 {
93963- struct k_clock process = {
93964+ static struct k_clock process = {
93965 .clock_getres = process_cpu_clock_getres,
93966 .clock_get = process_cpu_clock_get,
93967 .timer_create = process_cpu_timer_create,
93968 .nsleep = process_cpu_nsleep,
93969 .nsleep_restart = process_cpu_nsleep_restart,
93970 };
93971- struct k_clock thread = {
93972+ static struct k_clock thread = {
93973 .clock_getres = thread_cpu_clock_getres,
93974 .clock_get = thread_cpu_clock_get,
93975 .timer_create = thread_cpu_timer_create,
93976diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
93977index 31ea01f..7fc61ef 100644
93978--- a/kernel/time/posix-timers.c
93979+++ b/kernel/time/posix-timers.c
93980@@ -43,6 +43,7 @@
93981 #include <linux/hash.h>
93982 #include <linux/posix-clock.h>
93983 #include <linux/posix-timers.h>
93984+#include <linux/grsecurity.h>
93985 #include <linux/syscalls.h>
93986 #include <linux/wait.h>
93987 #include <linux/workqueue.h>
93988@@ -124,7 +125,7 @@ static DEFINE_SPINLOCK(hash_lock);
93989 * which we beg off on and pass to do_sys_settimeofday().
93990 */
93991
93992-static struct k_clock posix_clocks[MAX_CLOCKS];
93993+static struct k_clock *posix_clocks[MAX_CLOCKS];
93994
93995 /*
93996 * These ones are defined below.
93997@@ -277,7 +278,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
93998 */
93999 static __init int init_posix_timers(void)
94000 {
94001- struct k_clock clock_realtime = {
94002+ static struct k_clock clock_realtime = {
94003 .clock_getres = hrtimer_get_res,
94004 .clock_get = posix_clock_realtime_get,
94005 .clock_set = posix_clock_realtime_set,
94006@@ -289,7 +290,7 @@ static __init int init_posix_timers(void)
94007 .timer_get = common_timer_get,
94008 .timer_del = common_timer_del,
94009 };
94010- struct k_clock clock_monotonic = {
94011+ static struct k_clock clock_monotonic = {
94012 .clock_getres = hrtimer_get_res,
94013 .clock_get = posix_ktime_get_ts,
94014 .nsleep = common_nsleep,
94015@@ -299,19 +300,19 @@ static __init int init_posix_timers(void)
94016 .timer_get = common_timer_get,
94017 .timer_del = common_timer_del,
94018 };
94019- struct k_clock clock_monotonic_raw = {
94020+ static struct k_clock clock_monotonic_raw = {
94021 .clock_getres = hrtimer_get_res,
94022 .clock_get = posix_get_monotonic_raw,
94023 };
94024- struct k_clock clock_realtime_coarse = {
94025+ static struct k_clock clock_realtime_coarse = {
94026 .clock_getres = posix_get_coarse_res,
94027 .clock_get = posix_get_realtime_coarse,
94028 };
94029- struct k_clock clock_monotonic_coarse = {
94030+ static struct k_clock clock_monotonic_coarse = {
94031 .clock_getres = posix_get_coarse_res,
94032 .clock_get = posix_get_monotonic_coarse,
94033 };
94034- struct k_clock clock_tai = {
94035+ static struct k_clock clock_tai = {
94036 .clock_getres = hrtimer_get_res,
94037 .clock_get = posix_get_tai,
94038 .nsleep = common_nsleep,
94039@@ -321,7 +322,7 @@ static __init int init_posix_timers(void)
94040 .timer_get = common_timer_get,
94041 .timer_del = common_timer_del,
94042 };
94043- struct k_clock clock_boottime = {
94044+ static struct k_clock clock_boottime = {
94045 .clock_getres = hrtimer_get_res,
94046 .clock_get = posix_get_boottime,
94047 .nsleep = common_nsleep,
94048@@ -533,7 +534,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
94049 return;
94050 }
94051
94052- posix_clocks[clock_id] = *new_clock;
94053+ posix_clocks[clock_id] = new_clock;
94054 }
94055 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
94056
94057@@ -579,9 +580,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
94058 return (id & CLOCKFD_MASK) == CLOCKFD ?
94059 &clock_posix_dynamic : &clock_posix_cpu;
94060
94061- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
94062+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
94063 return NULL;
94064- return &posix_clocks[id];
94065+ return posix_clocks[id];
94066 }
94067
94068 static int common_timer_create(struct k_itimer *new_timer)
94069@@ -599,7 +600,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
94070 struct k_clock *kc = clockid_to_kclock(which_clock);
94071 struct k_itimer *new_timer;
94072 int error, new_timer_id;
94073- sigevent_t event;
94074+ sigevent_t event = { };
94075 int it_id_set = IT_ID_NOT_SET;
94076
94077 if (!kc)
94078@@ -1014,6 +1015,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
94079 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
94080 return -EFAULT;
94081
94082+ /* only the CLOCK_REALTIME clock can be set, all other clocks
94083+ have their clock_set fptr set to a nosettime dummy function
94084+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
94085+ call common_clock_set, which calls do_sys_settimeofday, which
94086+ we hook
94087+ */
94088+
94089 return kc->clock_set(which_clock, &new_tp);
94090 }
94091
94092diff --git a/kernel/time/time.c b/kernel/time/time.c
94093index a9ae20f..d3fbde7 100644
94094--- a/kernel/time/time.c
94095+++ b/kernel/time/time.c
94096@@ -173,6 +173,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
94097 return error;
94098
94099 if (tz) {
94100+ /* we log in do_settimeofday called below, so don't log twice
94101+ */
94102+ if (!tv)
94103+ gr_log_timechange();
94104+
94105 sys_tz = *tz;
94106 update_vsyscall_tz();
94107 if (firsttime) {
94108diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
94109index ec1791f..6a086cd 100644
94110--- a/kernel/time/timekeeping.c
94111+++ b/kernel/time/timekeeping.c
94112@@ -15,6 +15,7 @@
94113 #include <linux/init.h>
94114 #include <linux/mm.h>
94115 #include <linux/sched.h>
94116+#include <linux/grsecurity.h>
94117 #include <linux/syscore_ops.h>
94118 #include <linux/clocksource.h>
94119 #include <linux/jiffies.h>
94120@@ -717,6 +718,8 @@ int do_settimeofday(const struct timespec *tv)
94121 if (!timespec_valid_strict(tv))
94122 return -EINVAL;
94123
94124+ gr_log_timechange();
94125+
94126 raw_spin_lock_irqsave(&timekeeper_lock, flags);
94127 write_seqcount_begin(&tk_core.seq);
94128
94129diff --git a/kernel/time/timer.c b/kernel/time/timer.c
94130index 9bbb834..3caa8ed 100644
94131--- a/kernel/time/timer.c
94132+++ b/kernel/time/timer.c
94133@@ -1394,7 +1394,7 @@ void update_process_times(int user_tick)
94134 /*
94135 * This function runs timers and the timer-tq in bottom half context.
94136 */
94137-static void run_timer_softirq(struct softirq_action *h)
94138+static __latent_entropy void run_timer_softirq(void)
94139 {
94140 struct tvec_base *base = __this_cpu_read(tvec_bases);
94141
94142@@ -1457,7 +1457,7 @@ static void process_timeout(unsigned long __data)
94143 *
94144 * In all cases the return value is guaranteed to be non-negative.
94145 */
94146-signed long __sched schedule_timeout(signed long timeout)
94147+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
94148 {
94149 struct timer_list timer;
94150 unsigned long expire;
94151diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
94152index 61ed862..3b52c65 100644
94153--- a/kernel/time/timer_list.c
94154+++ b/kernel/time/timer_list.c
94155@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
94156
94157 static void print_name_offset(struct seq_file *m, void *sym)
94158 {
94159+#ifdef CONFIG_GRKERNSEC_HIDESYM
94160+ SEQ_printf(m, "<%p>", NULL);
94161+#else
94162 char symname[KSYM_NAME_LEN];
94163
94164 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
94165 SEQ_printf(m, "<%pK>", sym);
94166 else
94167 SEQ_printf(m, "%s", symname);
94168+#endif
94169 }
94170
94171 static void
94172@@ -119,7 +123,11 @@ next_one:
94173 static void
94174 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
94175 {
94176+#ifdef CONFIG_GRKERNSEC_HIDESYM
94177+ SEQ_printf(m, " .base: %p\n", NULL);
94178+#else
94179 SEQ_printf(m, " .base: %pK\n", base);
94180+#endif
94181 SEQ_printf(m, " .index: %d\n",
94182 base->index);
94183 SEQ_printf(m, " .resolution: %Lu nsecs\n",
94184@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
94185 {
94186 struct proc_dir_entry *pe;
94187
94188+#ifdef CONFIG_GRKERNSEC_PROC_ADD
94189+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
94190+#else
94191 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
94192+#endif
94193 if (!pe)
94194 return -ENOMEM;
94195 return 0;
94196diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
94197index 1fb08f2..ca4bb1e 100644
94198--- a/kernel/time/timer_stats.c
94199+++ b/kernel/time/timer_stats.c
94200@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
94201 static unsigned long nr_entries;
94202 static struct entry entries[MAX_ENTRIES];
94203
94204-static atomic_t overflow_count;
94205+static atomic_unchecked_t overflow_count;
94206
94207 /*
94208 * The entries are in a hash-table, for fast lookup:
94209@@ -140,7 +140,7 @@ static void reset_entries(void)
94210 nr_entries = 0;
94211 memset(entries, 0, sizeof(entries));
94212 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
94213- atomic_set(&overflow_count, 0);
94214+ atomic_set_unchecked(&overflow_count, 0);
94215 }
94216
94217 static struct entry *alloc_entry(void)
94218@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
94219 if (likely(entry))
94220 entry->count++;
94221 else
94222- atomic_inc(&overflow_count);
94223+ atomic_inc_unchecked(&overflow_count);
94224
94225 out_unlock:
94226 raw_spin_unlock_irqrestore(lock, flags);
94227@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
94228
94229 static void print_name_offset(struct seq_file *m, unsigned long addr)
94230 {
94231+#ifdef CONFIG_GRKERNSEC_HIDESYM
94232+ seq_printf(m, "<%p>", NULL);
94233+#else
94234 char symname[KSYM_NAME_LEN];
94235
94236 if (lookup_symbol_name(addr, symname) < 0)
94237- seq_printf(m, "<%p>", (void *)addr);
94238+ seq_printf(m, "<%pK>", (void *)addr);
94239 else
94240 seq_printf(m, "%s", symname);
94241+#endif
94242 }
94243
94244 static int tstats_show(struct seq_file *m, void *v)
94245@@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
94246
94247 seq_puts(m, "Timer Stats Version: v0.3\n");
94248 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
94249- if (atomic_read(&overflow_count))
94250- seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
94251+ if (atomic_read_unchecked(&overflow_count))
94252+ seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
94253 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
94254
94255 for (i = 0; i < nr_entries; i++) {
94256@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
94257 {
94258 struct proc_dir_entry *pe;
94259
94260+#ifdef CONFIG_GRKERNSEC_PROC_ADD
94261+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
94262+#else
94263 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
94264+#endif
94265 if (!pe)
94266 return -ENOMEM;
94267 return 0;
94268diff --git a/kernel/torture.c b/kernel/torture.c
94269index d600af2..27a4e9d 100644
94270--- a/kernel/torture.c
94271+++ b/kernel/torture.c
94272@@ -484,7 +484,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
94273 mutex_lock(&fullstop_mutex);
94274 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
94275 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
94276- ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
94277+ ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
94278 } else {
94279 pr_warn("Concurrent rmmod and shutdown illegal!\n");
94280 }
94281@@ -551,14 +551,14 @@ static int torture_stutter(void *arg)
94282 if (!torture_must_stop()) {
94283 if (stutter > 1) {
94284 schedule_timeout_interruptible(stutter - 1);
94285- ACCESS_ONCE(stutter_pause_test) = 2;
94286+ ACCESS_ONCE_RW(stutter_pause_test) = 2;
94287 }
94288 schedule_timeout_interruptible(1);
94289- ACCESS_ONCE(stutter_pause_test) = 1;
94290+ ACCESS_ONCE_RW(stutter_pause_test) = 1;
94291 }
94292 if (!torture_must_stop())
94293 schedule_timeout_interruptible(stutter);
94294- ACCESS_ONCE(stutter_pause_test) = 0;
94295+ ACCESS_ONCE_RW(stutter_pause_test) = 0;
94296 torture_shutdown_absorb("torture_stutter");
94297 } while (!torture_must_stop());
94298 torture_kthread_stopping("torture_stutter");
94299@@ -645,7 +645,7 @@ bool torture_cleanup(void)
94300 schedule_timeout_uninterruptible(10);
94301 return true;
94302 }
94303- ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
94304+ ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
94305 mutex_unlock(&fullstop_mutex);
94306 torture_shutdown_cleanup();
94307 torture_shuffle_cleanup();
94308diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
94309index c1bd4ad..4b861dc 100644
94310--- a/kernel/trace/blktrace.c
94311+++ b/kernel/trace/blktrace.c
94312@@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
94313 struct blk_trace *bt = filp->private_data;
94314 char buf[16];
94315
94316- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
94317+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
94318
94319 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
94320 }
94321@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
94322 return 1;
94323
94324 bt = buf->chan->private_data;
94325- atomic_inc(&bt->dropped);
94326+ atomic_inc_unchecked(&bt->dropped);
94327 return 0;
94328 }
94329
94330@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
94331
94332 bt->dir = dir;
94333 bt->dev = dev;
94334- atomic_set(&bt->dropped, 0);
94335+ atomic_set_unchecked(&bt->dropped, 0);
94336 INIT_LIST_HEAD(&bt->running_list);
94337
94338 ret = -EIO;
94339diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
94340index 5916a8e..220c9c2 100644
94341--- a/kernel/trace/ftrace.c
94342+++ b/kernel/trace/ftrace.c
94343@@ -2128,12 +2128,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
94344 if (unlikely(ftrace_disabled))
94345 return 0;
94346
94347+ ret = ftrace_arch_code_modify_prepare();
94348+ FTRACE_WARN_ON(ret);
94349+ if (ret)
94350+ return 0;
94351+
94352 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
94353+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
94354 if (ret) {
94355 ftrace_bug(ret, ip);
94356- return 0;
94357 }
94358- return 1;
94359+ return ret ? 0 : 1;
94360 }
94361
94362 /*
94363@@ -4458,8 +4463,10 @@ static int ftrace_process_locs(struct module *mod,
94364 if (!count)
94365 return 0;
94366
94367+ pax_open_kernel();
94368 sort(start, count, sizeof(*start),
94369 ftrace_cmp_ips, ftrace_swap_ips);
94370+ pax_close_kernel();
94371
94372 start_pg = ftrace_allocate_pages(count);
94373 if (!start_pg)
94374@@ -5254,7 +5261,7 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list)
94375
94376 if (t->ret_stack == NULL) {
94377 atomic_set(&t->tracing_graph_pause, 0);
94378- atomic_set(&t->trace_overrun, 0);
94379+ atomic_set_unchecked(&t->trace_overrun, 0);
94380 t->curr_ret_stack = -1;
94381 /* Make sure the tasks see the -1 first: */
94382 smp_wmb();
94383@@ -5467,7 +5474,7 @@ static void
94384 graph_init_task(struct task_struct *t, struct ftrace_ret_stack *ret_stack)
94385 {
94386 atomic_set(&t->tracing_graph_pause, 0);
94387- atomic_set(&t->trace_overrun, 0);
94388+ atomic_set_unchecked(&t->trace_overrun, 0);
94389 t->ftrace_timestamp = 0;
94390 /* make curr_ret_stack visible before we add the ret_stack */
94391 smp_wmb();
94392diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
94393index a56e07c..d46f0ba 100644
94394--- a/kernel/trace/ring_buffer.c
94395+++ b/kernel/trace/ring_buffer.c
94396@@ -352,9 +352,9 @@ struct buffer_data_page {
94397 */
94398 struct buffer_page {
94399 struct list_head list; /* list of buffer pages */
94400- local_t write; /* index for next write */
94401+ local_unchecked_t write; /* index for next write */
94402 unsigned read; /* index for next read */
94403- local_t entries; /* entries on this page */
94404+ local_unchecked_t entries; /* entries on this page */
94405 unsigned long real_end; /* real end of data */
94406 struct buffer_data_page *page; /* Actual data page */
94407 };
94408@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
94409 unsigned long last_overrun;
94410 local_t entries_bytes;
94411 local_t entries;
94412- local_t overrun;
94413- local_t commit_overrun;
94414+ local_unchecked_t overrun;
94415+ local_unchecked_t commit_overrun;
94416 local_t dropped_events;
94417 local_t committing;
94418 local_t commits;
94419@@ -1032,8 +1032,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
94420 *
94421 * We add a counter to the write field to denote this.
94422 */
94423- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
94424- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
94425+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
94426+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
94427
94428 /*
94429 * Just make sure we have seen our old_write and synchronize
94430@@ -1061,8 +1061,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
94431 * cmpxchg to only update if an interrupt did not already
94432 * do it for us. If the cmpxchg fails, we don't care.
94433 */
94434- (void)local_cmpxchg(&next_page->write, old_write, val);
94435- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
94436+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
94437+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
94438
94439 /*
94440 * No need to worry about races with clearing out the commit.
94441@@ -1429,12 +1429,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
94442
94443 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
94444 {
94445- return local_read(&bpage->entries) & RB_WRITE_MASK;
94446+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
94447 }
94448
94449 static inline unsigned long rb_page_write(struct buffer_page *bpage)
94450 {
94451- return local_read(&bpage->write) & RB_WRITE_MASK;
94452+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
94453 }
94454
94455 static int
94456@@ -1529,7 +1529,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
94457 * bytes consumed in ring buffer from here.
94458 * Increment overrun to account for the lost events.
94459 */
94460- local_add(page_entries, &cpu_buffer->overrun);
94461+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
94462 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
94463 }
94464
94465@@ -2091,7 +2091,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
94466 * it is our responsibility to update
94467 * the counters.
94468 */
94469- local_add(entries, &cpu_buffer->overrun);
94470+ local_add_unchecked(entries, &cpu_buffer->overrun);
94471 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
94472
94473 /*
94474@@ -2241,7 +2241,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94475 if (tail == BUF_PAGE_SIZE)
94476 tail_page->real_end = 0;
94477
94478- local_sub(length, &tail_page->write);
94479+ local_sub_unchecked(length, &tail_page->write);
94480 return;
94481 }
94482
94483@@ -2276,7 +2276,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94484 rb_event_set_padding(event);
94485
94486 /* Set the write back to the previous setting */
94487- local_sub(length, &tail_page->write);
94488+ local_sub_unchecked(length, &tail_page->write);
94489 return;
94490 }
94491
94492@@ -2288,7 +2288,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94493
94494 /* Set write to end of buffer */
94495 length = (tail + length) - BUF_PAGE_SIZE;
94496- local_sub(length, &tail_page->write);
94497+ local_sub_unchecked(length, &tail_page->write);
94498 }
94499
94500 /*
94501@@ -2314,7 +2314,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
94502 * about it.
94503 */
94504 if (unlikely(next_page == commit_page)) {
94505- local_inc(&cpu_buffer->commit_overrun);
94506+ local_inc_unchecked(&cpu_buffer->commit_overrun);
94507 goto out_reset;
94508 }
94509
94510@@ -2370,7 +2370,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
94511 cpu_buffer->tail_page) &&
94512 (cpu_buffer->commit_page ==
94513 cpu_buffer->reader_page))) {
94514- local_inc(&cpu_buffer->commit_overrun);
94515+ local_inc_unchecked(&cpu_buffer->commit_overrun);
94516 goto out_reset;
94517 }
94518 }
94519@@ -2418,7 +2418,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
94520 length += RB_LEN_TIME_EXTEND;
94521
94522 tail_page = cpu_buffer->tail_page;
94523- write = local_add_return(length, &tail_page->write);
94524+ write = local_add_return_unchecked(length, &tail_page->write);
94525
94526 /* set write to only the index of the write */
94527 write &= RB_WRITE_MASK;
94528@@ -2442,7 +2442,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
94529 kmemcheck_annotate_bitfield(event, bitfield);
94530 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
94531
94532- local_inc(&tail_page->entries);
94533+ local_inc_unchecked(&tail_page->entries);
94534
94535 /*
94536 * If this is the first commit on the page, then update
94537@@ -2475,7 +2475,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
94538
94539 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
94540 unsigned long write_mask =
94541- local_read(&bpage->write) & ~RB_WRITE_MASK;
94542+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
94543 unsigned long event_length = rb_event_length(event);
94544 /*
94545 * This is on the tail page. It is possible that
94546@@ -2485,7 +2485,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
94547 */
94548 old_index += write_mask;
94549 new_index += write_mask;
94550- index = local_cmpxchg(&bpage->write, old_index, new_index);
94551+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
94552 if (index == old_index) {
94553 /* update counters */
94554 local_sub(event_length, &cpu_buffer->entries_bytes);
94555@@ -2877,7 +2877,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
94556
94557 /* Do the likely case first */
94558 if (likely(bpage->page == (void *)addr)) {
94559- local_dec(&bpage->entries);
94560+ local_dec_unchecked(&bpage->entries);
94561 return;
94562 }
94563
94564@@ -2889,7 +2889,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
94565 start = bpage;
94566 do {
94567 if (bpage->page == (void *)addr) {
94568- local_dec(&bpage->entries);
94569+ local_dec_unchecked(&bpage->entries);
94570 return;
94571 }
94572 rb_inc_page(cpu_buffer, &bpage);
94573@@ -3173,7 +3173,7 @@ static inline unsigned long
94574 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
94575 {
94576 return local_read(&cpu_buffer->entries) -
94577- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
94578+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
94579 }
94580
94581 /**
94582@@ -3262,7 +3262,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
94583 return 0;
94584
94585 cpu_buffer = buffer->buffers[cpu];
94586- ret = local_read(&cpu_buffer->overrun);
94587+ ret = local_read_unchecked(&cpu_buffer->overrun);
94588
94589 return ret;
94590 }
94591@@ -3285,7 +3285,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
94592 return 0;
94593
94594 cpu_buffer = buffer->buffers[cpu];
94595- ret = local_read(&cpu_buffer->commit_overrun);
94596+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
94597
94598 return ret;
94599 }
94600@@ -3370,7 +3370,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
94601 /* if you care about this being correct, lock the buffer */
94602 for_each_buffer_cpu(buffer, cpu) {
94603 cpu_buffer = buffer->buffers[cpu];
94604- overruns += local_read(&cpu_buffer->overrun);
94605+ overruns += local_read_unchecked(&cpu_buffer->overrun);
94606 }
94607
94608 return overruns;
94609@@ -3541,8 +3541,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
94610 /*
94611 * Reset the reader page to size zero.
94612 */
94613- local_set(&cpu_buffer->reader_page->write, 0);
94614- local_set(&cpu_buffer->reader_page->entries, 0);
94615+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94616+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94617 local_set(&cpu_buffer->reader_page->page->commit, 0);
94618 cpu_buffer->reader_page->real_end = 0;
94619
94620@@ -3576,7 +3576,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
94621 * want to compare with the last_overrun.
94622 */
94623 smp_mb();
94624- overwrite = local_read(&(cpu_buffer->overrun));
94625+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
94626
94627 /*
94628 * Here's the tricky part.
94629@@ -4148,8 +4148,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94630
94631 cpu_buffer->head_page
94632 = list_entry(cpu_buffer->pages, struct buffer_page, list);
94633- local_set(&cpu_buffer->head_page->write, 0);
94634- local_set(&cpu_buffer->head_page->entries, 0);
94635+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
94636+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
94637 local_set(&cpu_buffer->head_page->page->commit, 0);
94638
94639 cpu_buffer->head_page->read = 0;
94640@@ -4159,14 +4159,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94641
94642 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
94643 INIT_LIST_HEAD(&cpu_buffer->new_pages);
94644- local_set(&cpu_buffer->reader_page->write, 0);
94645- local_set(&cpu_buffer->reader_page->entries, 0);
94646+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94647+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94648 local_set(&cpu_buffer->reader_page->page->commit, 0);
94649 cpu_buffer->reader_page->read = 0;
94650
94651 local_set(&cpu_buffer->entries_bytes, 0);
94652- local_set(&cpu_buffer->overrun, 0);
94653- local_set(&cpu_buffer->commit_overrun, 0);
94654+ local_set_unchecked(&cpu_buffer->overrun, 0);
94655+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
94656 local_set(&cpu_buffer->dropped_events, 0);
94657 local_set(&cpu_buffer->entries, 0);
94658 local_set(&cpu_buffer->committing, 0);
94659@@ -4571,8 +4571,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
94660 rb_init_page(bpage);
94661 bpage = reader->page;
94662 reader->page = *data_page;
94663- local_set(&reader->write, 0);
94664- local_set(&reader->entries, 0);
94665+ local_set_unchecked(&reader->write, 0);
94666+ local_set_unchecked(&reader->entries, 0);
94667 reader->read = 0;
94668 *data_page = bpage;
94669
94670diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
94671index 1520933..c651ebc 100644
94672--- a/kernel/trace/trace.c
94673+++ b/kernel/trace/trace.c
94674@@ -3488,7 +3488,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
94675 return 0;
94676 }
94677
94678-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
94679+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
94680 {
94681 /* do nothing if flag is already set */
94682 if (!!(trace_flags & mask) == !!enabled)
94683diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
94684index 385391f..8d2250f 100644
94685--- a/kernel/trace/trace.h
94686+++ b/kernel/trace/trace.h
94687@@ -1280,7 +1280,7 @@ extern const char *__stop___tracepoint_str[];
94688 void trace_printk_init_buffers(void);
94689 void trace_printk_start_comm(void);
94690 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
94691-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
94692+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
94693
94694 /*
94695 * Normal trace_printk() and friends allocates special buffers
94696diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
94697index 57b67b1..66082a9 100644
94698--- a/kernel/trace/trace_clock.c
94699+++ b/kernel/trace/trace_clock.c
94700@@ -124,7 +124,7 @@ u64 notrace trace_clock_global(void)
94701 return now;
94702 }
94703
94704-static atomic64_t trace_counter;
94705+static atomic64_unchecked_t trace_counter;
94706
94707 /*
94708 * trace_clock_counter(): simply an atomic counter.
94709@@ -133,5 +133,5 @@ static atomic64_t trace_counter;
94710 */
94711 u64 notrace trace_clock_counter(void)
94712 {
94713- return atomic64_add_return(1, &trace_counter);
94714+ return atomic64_inc_return_unchecked(&trace_counter);
94715 }
94716diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
94717index ef06ce7..3ea161d 100644
94718--- a/kernel/trace/trace_events.c
94719+++ b/kernel/trace/trace_events.c
94720@@ -1720,7 +1720,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
94721 return 0;
94722 }
94723
94724-struct ftrace_module_file_ops;
94725 static void __add_event_to_tracers(struct ftrace_event_call *call);
94726
94727 /* Add an additional event_call dynamically */
94728diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
94729index f0a0c98..3692dc8 100644
94730--- a/kernel/trace/trace_functions_graph.c
94731+++ b/kernel/trace/trace_functions_graph.c
94732@@ -133,7 +133,7 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth,
94733
94734 /* The return trace stack is full */
94735 if (current->curr_ret_stack == FTRACE_RETFUNC_DEPTH - 1) {
94736- atomic_inc(&current->trace_overrun);
94737+ atomic_inc_unchecked(&current->trace_overrun);
94738 return -EBUSY;
94739 }
94740
94741@@ -230,7 +230,7 @@ ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret,
94742 *ret = current->ret_stack[index].ret;
94743 trace->func = current->ret_stack[index].func;
94744 trace->calltime = current->ret_stack[index].calltime;
94745- trace->overrun = atomic_read(&current->trace_overrun);
94746+ trace->overrun = atomic_read_unchecked(&current->trace_overrun);
94747 trace->depth = index;
94748 }
94749
94750diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
94751index 0abd9b8..6a663a2 100644
94752--- a/kernel/trace/trace_mmiotrace.c
94753+++ b/kernel/trace/trace_mmiotrace.c
94754@@ -24,7 +24,7 @@ struct header_iter {
94755 static struct trace_array *mmio_trace_array;
94756 static bool overrun_detected;
94757 static unsigned long prev_overruns;
94758-static atomic_t dropped_count;
94759+static atomic_unchecked_t dropped_count;
94760
94761 static void mmio_reset_data(struct trace_array *tr)
94762 {
94763@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
94764
94765 static unsigned long count_overruns(struct trace_iterator *iter)
94766 {
94767- unsigned long cnt = atomic_xchg(&dropped_count, 0);
94768+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
94769 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
94770
94771 if (over > prev_overruns)
94772@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
94773 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
94774 sizeof(*entry), 0, pc);
94775 if (!event) {
94776- atomic_inc(&dropped_count);
94777+ atomic_inc_unchecked(&dropped_count);
94778 return;
94779 }
94780 entry = ring_buffer_event_data(event);
94781@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
94782 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
94783 sizeof(*entry), 0, pc);
94784 if (!event) {
94785- atomic_inc(&dropped_count);
94786+ atomic_inc_unchecked(&dropped_count);
94787 return;
94788 }
94789 entry = ring_buffer_event_data(event);
94790diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
94791index c6977d5..d243785 100644
94792--- a/kernel/trace/trace_output.c
94793+++ b/kernel/trace/trace_output.c
94794@@ -712,14 +712,16 @@ int register_ftrace_event(struct trace_event *event)
94795 goto out;
94796 }
94797
94798+ pax_open_kernel();
94799 if (event->funcs->trace == NULL)
94800- event->funcs->trace = trace_nop_print;
94801+ *(void **)&event->funcs->trace = trace_nop_print;
94802 if (event->funcs->raw == NULL)
94803- event->funcs->raw = trace_nop_print;
94804+ *(void **)&event->funcs->raw = trace_nop_print;
94805 if (event->funcs->hex == NULL)
94806- event->funcs->hex = trace_nop_print;
94807+ *(void **)&event->funcs->hex = trace_nop_print;
94808 if (event->funcs->binary == NULL)
94809- event->funcs->binary = trace_nop_print;
94810+ *(void **)&event->funcs->binary = trace_nop_print;
94811+ pax_close_kernel();
94812
94813 key = event->type & (EVENT_HASHSIZE - 1);
94814
94815diff --git a/kernel/trace/trace_seq.c b/kernel/trace/trace_seq.c
94816index 1f24ed9..10407ec 100644
94817--- a/kernel/trace/trace_seq.c
94818+++ b/kernel/trace/trace_seq.c
94819@@ -367,7 +367,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
94820
94821 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
94822 if (!IS_ERR(p)) {
94823- p = mangle_path(s->buffer + s->len, p, "\n");
94824+ p = mangle_path(s->buffer + s->len, p, "\n\\");
94825 if (p) {
94826 s->len = p - s->buffer;
94827 return 1;
94828diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
94829index 8a4e5cb..64f270d 100644
94830--- a/kernel/trace/trace_stack.c
94831+++ b/kernel/trace/trace_stack.c
94832@@ -91,7 +91,7 @@ check_stack(unsigned long ip, unsigned long *stack)
94833 return;
94834
94835 /* we do not handle interrupt stacks yet */
94836- if (!object_is_on_stack(stack))
94837+ if (!object_starts_on_stack(stack))
94838 return;
94839
94840 local_irq_save(flags);
94841diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
94842index 7e3cd7a..5156a5fe 100644
94843--- a/kernel/trace/trace_syscalls.c
94844+++ b/kernel/trace/trace_syscalls.c
94845@@ -602,6 +602,8 @@ static int perf_sysenter_enable(struct ftrace_event_call *call)
94846 int num;
94847
94848 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94849+ if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94850+ return -EINVAL;
94851
94852 mutex_lock(&syscall_trace_lock);
94853 if (!sys_perf_refcount_enter)
94854@@ -622,6 +624,8 @@ static void perf_sysenter_disable(struct ftrace_event_call *call)
94855 int num;
94856
94857 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94858+ if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94859+ return;
94860
94861 mutex_lock(&syscall_trace_lock);
94862 sys_perf_refcount_enter--;
94863@@ -674,6 +678,8 @@ static int perf_sysexit_enable(struct ftrace_event_call *call)
94864 int num;
94865
94866 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94867+ if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94868+ return -EINVAL;
94869
94870 mutex_lock(&syscall_trace_lock);
94871 if (!sys_perf_refcount_exit)
94872@@ -694,6 +700,8 @@ static void perf_sysexit_disable(struct ftrace_event_call *call)
94873 int num;
94874
94875 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94876+ if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94877+ return;
94878
94879 mutex_lock(&syscall_trace_lock);
94880 sys_perf_refcount_exit--;
94881diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
94882index aa312b0..395f343 100644
94883--- a/kernel/user_namespace.c
94884+++ b/kernel/user_namespace.c
94885@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
94886 !kgid_has_mapping(parent_ns, group))
94887 return -EPERM;
94888
94889+#ifdef CONFIG_GRKERNSEC
94890+ /*
94891+ * This doesn't really inspire confidence:
94892+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
94893+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
94894+ * Increases kernel attack surface in areas developers
94895+ * previously cared little about ("low importance due
94896+ * to requiring "root" capability")
94897+ * To be removed when this code receives *proper* review
94898+ */
94899+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
94900+ !capable(CAP_SETGID))
94901+ return -EPERM;
94902+#endif
94903+
94904 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
94905 if (!ns)
94906 return -ENOMEM;
94907@@ -872,7 +887,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
94908 if (atomic_read(&current->mm->mm_users) > 1)
94909 return -EINVAL;
94910
94911- if (current->fs->users != 1)
94912+ if (atomic_read(&current->fs->users) != 1)
94913 return -EINVAL;
94914
94915 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
94916diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
94917index c8eac43..4b5f08f 100644
94918--- a/kernel/utsname_sysctl.c
94919+++ b/kernel/utsname_sysctl.c
94920@@ -47,7 +47,7 @@ static void put_uts(struct ctl_table *table, int write, void *which)
94921 static int proc_do_uts_string(struct ctl_table *table, int write,
94922 void __user *buffer, size_t *lenp, loff_t *ppos)
94923 {
94924- struct ctl_table uts_table;
94925+ ctl_table_no_const uts_table;
94926 int r;
94927 memcpy(&uts_table, table, sizeof(uts_table));
94928 uts_table.data = get_uts(table, write);
94929diff --git a/kernel/watchdog.c b/kernel/watchdog.c
94930index a8d6914..8fbdb13 100644
94931--- a/kernel/watchdog.c
94932+++ b/kernel/watchdog.c
94933@@ -521,7 +521,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
94934 static void watchdog_nmi_disable(unsigned int cpu) { return; }
94935 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
94936
94937-static struct smp_hotplug_thread watchdog_threads = {
94938+static struct smp_hotplug_thread watchdog_threads __read_only = {
94939 .store = &softlockup_watchdog,
94940 .thread_should_run = watchdog_should_run,
94941 .thread_fn = watchdog,
94942diff --git a/kernel/workqueue.c b/kernel/workqueue.c
94943index 5dbe22a..872413c 100644
94944--- a/kernel/workqueue.c
94945+++ b/kernel/workqueue.c
94946@@ -4507,7 +4507,7 @@ static void rebind_workers(struct worker_pool *pool)
94947 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
94948 worker_flags |= WORKER_REBOUND;
94949 worker_flags &= ~WORKER_UNBOUND;
94950- ACCESS_ONCE(worker->flags) = worker_flags;
94951+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
94952 }
94953
94954 spin_unlock_irq(&pool->lock);
94955diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
94956index a285900..5e3b26b 100644
94957--- a/lib/Kconfig.debug
94958+++ b/lib/Kconfig.debug
94959@@ -882,7 +882,7 @@ config DEBUG_MUTEXES
94960
94961 config DEBUG_WW_MUTEX_SLOWPATH
94962 bool "Wait/wound mutex debugging: Slowpath testing"
94963- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94964+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94965 select DEBUG_LOCK_ALLOC
94966 select DEBUG_SPINLOCK
94967 select DEBUG_MUTEXES
94968@@ -899,7 +899,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
94969
94970 config DEBUG_LOCK_ALLOC
94971 bool "Lock debugging: detect incorrect freeing of live locks"
94972- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94973+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94974 select DEBUG_SPINLOCK
94975 select DEBUG_MUTEXES
94976 select LOCKDEP
94977@@ -913,7 +913,7 @@ config DEBUG_LOCK_ALLOC
94978
94979 config PROVE_LOCKING
94980 bool "Lock debugging: prove locking correctness"
94981- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94982+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94983 select LOCKDEP
94984 select DEBUG_SPINLOCK
94985 select DEBUG_MUTEXES
94986@@ -964,7 +964,7 @@ config LOCKDEP
94987
94988 config LOCK_STAT
94989 bool "Lock usage statistics"
94990- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94991+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94992 select LOCKDEP
94993 select DEBUG_SPINLOCK
94994 select DEBUG_MUTEXES
94995@@ -1437,6 +1437,7 @@ config LATENCYTOP
94996 depends on DEBUG_KERNEL
94997 depends on STACKTRACE_SUPPORT
94998 depends on PROC_FS
94999+ depends on !GRKERNSEC_HIDESYM
95000 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
95001 select KALLSYMS
95002 select KALLSYMS_ALL
95003@@ -1453,7 +1454,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
95004 config DEBUG_STRICT_USER_COPY_CHECKS
95005 bool "Strict user copy size checks"
95006 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
95007- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
95008+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
95009 help
95010 Enabling this option turns a certain set of sanity checks for user
95011 copy operations into compile time failures.
95012@@ -1581,7 +1582,7 @@ endmenu # runtime tests
95013
95014 config PROVIDE_OHCI1394_DMA_INIT
95015 bool "Remote debugging over FireWire early on boot"
95016- depends on PCI && X86
95017+ depends on PCI && X86 && !GRKERNSEC
95018 help
95019 If you want to debug problems which hang or crash the kernel early
95020 on boot and the crashing machine has a FireWire port, you can use
95021diff --git a/lib/Makefile b/lib/Makefile
95022index d6b4bc4..a3724eb 100644
95023--- a/lib/Makefile
95024+++ b/lib/Makefile
95025@@ -55,7 +55,7 @@ obj-$(CONFIG_BTREE) += btree.o
95026 obj-$(CONFIG_INTERVAL_TREE) += interval_tree.o
95027 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
95028 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
95029-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
95030+obj-y += list_debug.o
95031 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
95032
95033 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
95034diff --git a/lib/average.c b/lib/average.c
95035index 114d1be..ab0350c 100644
95036--- a/lib/average.c
95037+++ b/lib/average.c
95038@@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
95039 {
95040 unsigned long internal = ACCESS_ONCE(avg->internal);
95041
95042- ACCESS_ONCE(avg->internal) = internal ?
95043+ ACCESS_ONCE_RW(avg->internal) = internal ?
95044 (((internal << avg->weight) - internal) +
95045 (val << avg->factor)) >> avg->weight :
95046 (val << avg->factor);
95047diff --git a/lib/bitmap.c b/lib/bitmap.c
95048index 33ce011..89e3d6f 100644
95049--- a/lib/bitmap.c
95050+++ b/lib/bitmap.c
95051@@ -433,7 +433,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
95052 {
95053 int c, old_c, totaldigits, ndigits, nchunks, nbits;
95054 u32 chunk;
95055- const char __user __force *ubuf = (const char __user __force *)buf;
95056+ const char __user *ubuf = (const char __force_user *)buf;
95057
95058 bitmap_zero(maskp, nmaskbits);
95059
95060@@ -518,7 +518,7 @@ int bitmap_parse_user(const char __user *ubuf,
95061 {
95062 if (!access_ok(VERIFY_READ, ubuf, ulen))
95063 return -EFAULT;
95064- return __bitmap_parse((const char __force *)ubuf,
95065+ return __bitmap_parse((const char __force_kernel *)ubuf,
95066 ulen, 1, maskp, nmaskbits);
95067
95068 }
95069@@ -609,7 +609,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
95070 {
95071 unsigned a, b;
95072 int c, old_c, totaldigits;
95073- const char __user __force *ubuf = (const char __user __force *)buf;
95074+ const char __user *ubuf = (const char __force_user *)buf;
95075 int exp_digit, in_range;
95076
95077 totaldigits = c = 0;
95078@@ -704,7 +704,7 @@ int bitmap_parselist_user(const char __user *ubuf,
95079 {
95080 if (!access_ok(VERIFY_READ, ubuf, ulen))
95081 return -EFAULT;
95082- return __bitmap_parselist((const char __force *)ubuf,
95083+ return __bitmap_parselist((const char __force_kernel *)ubuf,
95084 ulen, 1, maskp, nmaskbits);
95085 }
95086 EXPORT_SYMBOL(bitmap_parselist_user);
95087diff --git a/lib/bug.c b/lib/bug.c
95088index d1d7c78..b354235 100644
95089--- a/lib/bug.c
95090+++ b/lib/bug.c
95091@@ -137,6 +137,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
95092 return BUG_TRAP_TYPE_NONE;
95093
95094 bug = find_bug(bugaddr);
95095+ if (!bug)
95096+ return BUG_TRAP_TYPE_NONE;
95097
95098 file = NULL;
95099 line = 0;
95100diff --git a/lib/debugobjects.c b/lib/debugobjects.c
95101index 547f7f9..a6d4ba0 100644
95102--- a/lib/debugobjects.c
95103+++ b/lib/debugobjects.c
95104@@ -289,7 +289,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
95105 if (limit > 4)
95106 return;
95107
95108- is_on_stack = object_is_on_stack(addr);
95109+ is_on_stack = object_starts_on_stack(addr);
95110 if (is_on_stack == onstack)
95111 return;
95112
95113diff --git a/lib/div64.c b/lib/div64.c
95114index 4382ad7..08aa558 100644
95115--- a/lib/div64.c
95116+++ b/lib/div64.c
95117@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
95118 EXPORT_SYMBOL(__div64_32);
95119
95120 #ifndef div_s64_rem
95121-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
95122+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
95123 {
95124 u64 quotient;
95125
95126@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
95127 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
95128 */
95129 #ifndef div64_u64
95130-u64 div64_u64(u64 dividend, u64 divisor)
95131+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
95132 {
95133 u32 high = divisor >> 32;
95134 u64 quot;
95135diff --git a/lib/dma-debug.c b/lib/dma-debug.c
95136index 98f2d7e..899da5c 100644
95137--- a/lib/dma-debug.c
95138+++ b/lib/dma-debug.c
95139@@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
95140
95141 void dma_debug_add_bus(struct bus_type *bus)
95142 {
95143- struct notifier_block *nb;
95144+ notifier_block_no_const *nb;
95145
95146 if (global_disable)
95147 return;
95148@@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
95149
95150 static void check_for_stack(struct device *dev, void *addr)
95151 {
95152- if (object_is_on_stack(addr))
95153+ if (object_starts_on_stack(addr))
95154 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
95155 "stack [addr=%p]\n", addr);
95156 }
95157diff --git a/lib/hash.c b/lib/hash.c
95158index fea973f..386626f 100644
95159--- a/lib/hash.c
95160+++ b/lib/hash.c
95161@@ -14,7 +14,7 @@
95162 #include <linux/hash.h>
95163 #include <linux/cache.h>
95164
95165-static struct fast_hash_ops arch_hash_ops __read_mostly = {
95166+static struct fast_hash_ops arch_hash_ops __read_only = {
95167 .hash = jhash,
95168 .hash2 = jhash2,
95169 };
95170diff --git a/lib/inflate.c b/lib/inflate.c
95171index 013a761..c28f3fc 100644
95172--- a/lib/inflate.c
95173+++ b/lib/inflate.c
95174@@ -269,7 +269,7 @@ static void free(void *where)
95175 malloc_ptr = free_mem_ptr;
95176 }
95177 #else
95178-#define malloc(a) kmalloc(a, GFP_KERNEL)
95179+#define malloc(a) kmalloc((a), GFP_KERNEL)
95180 #define free(a) kfree(a)
95181 #endif
95182
95183diff --git a/lib/ioremap.c b/lib/ioremap.c
95184index 0c9216c..863bd89 100644
95185--- a/lib/ioremap.c
95186+++ b/lib/ioremap.c
95187@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
95188 unsigned long next;
95189
95190 phys_addr -= addr;
95191- pmd = pmd_alloc(&init_mm, pud, addr);
95192+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
95193 if (!pmd)
95194 return -ENOMEM;
95195 do {
95196@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
95197 unsigned long next;
95198
95199 phys_addr -= addr;
95200- pud = pud_alloc(&init_mm, pgd, addr);
95201+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
95202 if (!pud)
95203 return -ENOMEM;
95204 do {
95205diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
95206index bd2bea9..6b3c95e 100644
95207--- a/lib/is_single_threaded.c
95208+++ b/lib/is_single_threaded.c
95209@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
95210 struct task_struct *p, *t;
95211 bool ret;
95212
95213+ if (!mm)
95214+ return true;
95215+
95216 if (atomic_read(&task->signal->live) != 1)
95217 return false;
95218
95219diff --git a/lib/kobject.c b/lib/kobject.c
95220index 58751bb..93a1853 100644
95221--- a/lib/kobject.c
95222+++ b/lib/kobject.c
95223@@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
95224
95225
95226 static DEFINE_SPINLOCK(kobj_ns_type_lock);
95227-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
95228+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
95229
95230-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
95231+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
95232 {
95233 enum kobj_ns_type type = ops->type;
95234 int error;
95235diff --git a/lib/list_debug.c b/lib/list_debug.c
95236index c24c2f7..f0296f4 100644
95237--- a/lib/list_debug.c
95238+++ b/lib/list_debug.c
95239@@ -11,7 +11,9 @@
95240 #include <linux/bug.h>
95241 #include <linux/kernel.h>
95242 #include <linux/rculist.h>
95243+#include <linux/mm.h>
95244
95245+#ifdef CONFIG_DEBUG_LIST
95246 /*
95247 * Insert a new entry between two known consecutive entries.
95248 *
95249@@ -19,21 +21,40 @@
95250 * the prev/next entries already!
95251 */
95252
95253+static bool __list_add_debug(struct list_head *new,
95254+ struct list_head *prev,
95255+ struct list_head *next)
95256+{
95257+ if (unlikely(next->prev != prev)) {
95258+ printk(KERN_ERR "list_add corruption. next->prev should be "
95259+ "prev (%p), but was %p. (next=%p).\n",
95260+ prev, next->prev, next);
95261+ BUG();
95262+ return false;
95263+ }
95264+ if (unlikely(prev->next != next)) {
95265+ printk(KERN_ERR "list_add corruption. prev->next should be "
95266+ "next (%p), but was %p. (prev=%p).\n",
95267+ next, prev->next, prev);
95268+ BUG();
95269+ return false;
95270+ }
95271+ if (unlikely(new == prev || new == next)) {
95272+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
95273+ new, prev, next);
95274+ BUG();
95275+ return false;
95276+ }
95277+ return true;
95278+}
95279+
95280 void __list_add(struct list_head *new,
95281- struct list_head *prev,
95282- struct list_head *next)
95283+ struct list_head *prev,
95284+ struct list_head *next)
95285 {
95286- WARN(next->prev != prev,
95287- "list_add corruption. next->prev should be "
95288- "prev (%p), but was %p. (next=%p).\n",
95289- prev, next->prev, next);
95290- WARN(prev->next != next,
95291- "list_add corruption. prev->next should be "
95292- "next (%p), but was %p. (prev=%p).\n",
95293- next, prev->next, prev);
95294- WARN(new == prev || new == next,
95295- "list_add double add: new=%p, prev=%p, next=%p.\n",
95296- new, prev, next);
95297+ if (!__list_add_debug(new, prev, next))
95298+ return;
95299+
95300 next->prev = new;
95301 new->next = next;
95302 new->prev = prev;
95303@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
95304 }
95305 EXPORT_SYMBOL(__list_add);
95306
95307-void __list_del_entry(struct list_head *entry)
95308+static bool __list_del_entry_debug(struct list_head *entry)
95309 {
95310 struct list_head *prev, *next;
95311
95312 prev = entry->prev;
95313 next = entry->next;
95314
95315- if (WARN(next == LIST_POISON1,
95316- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
95317- entry, LIST_POISON1) ||
95318- WARN(prev == LIST_POISON2,
95319- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
95320- entry, LIST_POISON2) ||
95321- WARN(prev->next != entry,
95322- "list_del corruption. prev->next should be %p, "
95323- "but was %p\n", entry, prev->next) ||
95324- WARN(next->prev != entry,
95325- "list_del corruption. next->prev should be %p, "
95326- "but was %p\n", entry, next->prev))
95327+ if (unlikely(next == LIST_POISON1)) {
95328+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
95329+ entry, LIST_POISON1);
95330+ BUG();
95331+ return false;
95332+ }
95333+ if (unlikely(prev == LIST_POISON2)) {
95334+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
95335+ entry, LIST_POISON2);
95336+ BUG();
95337+ return false;
95338+ }
95339+ if (unlikely(entry->prev->next != entry)) {
95340+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
95341+ "but was %p\n", entry, prev->next);
95342+ BUG();
95343+ return false;
95344+ }
95345+ if (unlikely(entry->next->prev != entry)) {
95346+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
95347+ "but was %p\n", entry, next->prev);
95348+ BUG();
95349+ return false;
95350+ }
95351+ return true;
95352+}
95353+
95354+void __list_del_entry(struct list_head *entry)
95355+{
95356+ if (!__list_del_entry_debug(entry))
95357 return;
95358
95359- __list_del(prev, next);
95360+ __list_del(entry->prev, entry->next);
95361 }
95362 EXPORT_SYMBOL(__list_del_entry);
95363
95364@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
95365 void __list_add_rcu(struct list_head *new,
95366 struct list_head *prev, struct list_head *next)
95367 {
95368- WARN(next->prev != prev,
95369- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
95370- prev, next->prev, next);
95371- WARN(prev->next != next,
95372- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
95373- next, prev->next, prev);
95374+ if (!__list_add_debug(new, prev, next))
95375+ return;
95376+
95377 new->next = next;
95378 new->prev = prev;
95379 rcu_assign_pointer(list_next_rcu(prev), new);
95380 next->prev = new;
95381 }
95382 EXPORT_SYMBOL(__list_add_rcu);
95383+#endif
95384+
95385+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
95386+{
95387+#ifdef CONFIG_DEBUG_LIST
95388+ if (!__list_add_debug(new, prev, next))
95389+ return;
95390+#endif
95391+
95392+ pax_open_kernel();
95393+ next->prev = new;
95394+ new->next = next;
95395+ new->prev = prev;
95396+ prev->next = new;
95397+ pax_close_kernel();
95398+}
95399+EXPORT_SYMBOL(__pax_list_add);
95400+
95401+void pax_list_del(struct list_head *entry)
95402+{
95403+#ifdef CONFIG_DEBUG_LIST
95404+ if (!__list_del_entry_debug(entry))
95405+ return;
95406+#endif
95407+
95408+ pax_open_kernel();
95409+ __list_del(entry->prev, entry->next);
95410+ entry->next = LIST_POISON1;
95411+ entry->prev = LIST_POISON2;
95412+ pax_close_kernel();
95413+}
95414+EXPORT_SYMBOL(pax_list_del);
95415+
95416+void pax_list_del_init(struct list_head *entry)
95417+{
95418+ pax_open_kernel();
95419+ __list_del(entry->prev, entry->next);
95420+ INIT_LIST_HEAD(entry);
95421+ pax_close_kernel();
95422+}
95423+EXPORT_SYMBOL(pax_list_del_init);
95424+
95425+void __pax_list_add_rcu(struct list_head *new,
95426+ struct list_head *prev, struct list_head *next)
95427+{
95428+#ifdef CONFIG_DEBUG_LIST
95429+ if (!__list_add_debug(new, prev, next))
95430+ return;
95431+#endif
95432+
95433+ pax_open_kernel();
95434+ new->next = next;
95435+ new->prev = prev;
95436+ rcu_assign_pointer(list_next_rcu(prev), new);
95437+ next->prev = new;
95438+ pax_close_kernel();
95439+}
95440+EXPORT_SYMBOL(__pax_list_add_rcu);
95441+
95442+void pax_list_del_rcu(struct list_head *entry)
95443+{
95444+#ifdef CONFIG_DEBUG_LIST
95445+ if (!__list_del_entry_debug(entry))
95446+ return;
95447+#endif
95448+
95449+ pax_open_kernel();
95450+ __list_del(entry->prev, entry->next);
95451+ entry->next = LIST_POISON1;
95452+ entry->prev = LIST_POISON2;
95453+ pax_close_kernel();
95454+}
95455+EXPORT_SYMBOL(pax_list_del_rcu);
95456diff --git a/lib/lockref.c b/lib/lockref.c
95457index d2233de..fa1a2f6 100644
95458--- a/lib/lockref.c
95459+++ b/lib/lockref.c
95460@@ -48,13 +48,13 @@
95461 void lockref_get(struct lockref *lockref)
95462 {
95463 CMPXCHG_LOOP(
95464- new.count++;
95465+ __lockref_inc(&new);
95466 ,
95467 return;
95468 );
95469
95470 spin_lock(&lockref->lock);
95471- lockref->count++;
95472+ __lockref_inc(lockref);
95473 spin_unlock(&lockref->lock);
95474 }
95475 EXPORT_SYMBOL(lockref_get);
95476@@ -69,7 +69,7 @@ int lockref_get_not_zero(struct lockref *lockref)
95477 int retval;
95478
95479 CMPXCHG_LOOP(
95480- new.count++;
95481+ __lockref_inc(&new);
95482 if (!old.count)
95483 return 0;
95484 ,
95485@@ -79,7 +79,7 @@ int lockref_get_not_zero(struct lockref *lockref)
95486 spin_lock(&lockref->lock);
95487 retval = 0;
95488 if (lockref->count) {
95489- lockref->count++;
95490+ __lockref_inc(lockref);
95491 retval = 1;
95492 }
95493 spin_unlock(&lockref->lock);
95494@@ -96,7 +96,7 @@ EXPORT_SYMBOL(lockref_get_not_zero);
95495 int lockref_get_or_lock(struct lockref *lockref)
95496 {
95497 CMPXCHG_LOOP(
95498- new.count++;
95499+ __lockref_inc(&new);
95500 if (!old.count)
95501 break;
95502 ,
95503@@ -106,7 +106,7 @@ int lockref_get_or_lock(struct lockref *lockref)
95504 spin_lock(&lockref->lock);
95505 if (!lockref->count)
95506 return 0;
95507- lockref->count++;
95508+ __lockref_inc(lockref);
95509 spin_unlock(&lockref->lock);
95510 return 1;
95511 }
95512@@ -120,7 +120,7 @@ EXPORT_SYMBOL(lockref_get_or_lock);
95513 int lockref_put_or_lock(struct lockref *lockref)
95514 {
95515 CMPXCHG_LOOP(
95516- new.count--;
95517+ __lockref_dec(&new);
95518 if (old.count <= 1)
95519 break;
95520 ,
95521@@ -130,7 +130,7 @@ int lockref_put_or_lock(struct lockref *lockref)
95522 spin_lock(&lockref->lock);
95523 if (lockref->count <= 1)
95524 return 0;
95525- lockref->count--;
95526+ __lockref_dec(lockref);
95527 spin_unlock(&lockref->lock);
95528 return 1;
95529 }
95530@@ -157,7 +157,7 @@ int lockref_get_not_dead(struct lockref *lockref)
95531 int retval;
95532
95533 CMPXCHG_LOOP(
95534- new.count++;
95535+ __lockref_inc(&new);
95536 if ((int)old.count < 0)
95537 return 0;
95538 ,
95539@@ -167,7 +167,7 @@ int lockref_get_not_dead(struct lockref *lockref)
95540 spin_lock(&lockref->lock);
95541 retval = 0;
95542 if ((int) lockref->count >= 0) {
95543- lockref->count++;
95544+ __lockref_inc(lockref);
95545 retval = 1;
95546 }
95547 spin_unlock(&lockref->lock);
95548diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
95549index a89cf09..1a42c2d 100644
95550--- a/lib/percpu-refcount.c
95551+++ b/lib/percpu-refcount.c
95552@@ -29,7 +29,7 @@
95553 * can't hit 0 before we've added up all the percpu refs.
95554 */
95555
95556-#define PCPU_COUNT_BIAS (1U << 31)
95557+#define PCPU_COUNT_BIAS (1U << 30)
95558
95559 static unsigned __percpu *pcpu_count_ptr(struct percpu_ref *ref)
95560 {
95561diff --git a/lib/radix-tree.c b/lib/radix-tree.c
95562index 3291a8e..346a91e 100644
95563--- a/lib/radix-tree.c
95564+++ b/lib/radix-tree.c
95565@@ -67,7 +67,7 @@ struct radix_tree_preload {
95566 int nr;
95567 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
95568 };
95569-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
95570+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
95571
95572 static inline void *ptr_to_indirect(void *ptr)
95573 {
95574diff --git a/lib/random32.c b/lib/random32.c
95575index c9b6bf3..4752c6d4 100644
95576--- a/lib/random32.c
95577+++ b/lib/random32.c
95578@@ -46,7 +46,7 @@ static inline void prandom_state_selftest(void)
95579 }
95580 #endif
95581
95582-static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
95583+static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
95584
95585 /**
95586 * prandom_u32_state - seeded pseudo-random number generator.
95587diff --git a/lib/rbtree.c b/lib/rbtree.c
95588index c16c81a..4dcbda1 100644
95589--- a/lib/rbtree.c
95590+++ b/lib/rbtree.c
95591@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
95592 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
95593
95594 static const struct rb_augment_callbacks dummy_callbacks = {
95595- dummy_propagate, dummy_copy, dummy_rotate
95596+ .propagate = dummy_propagate,
95597+ .copy = dummy_copy,
95598+ .rotate = dummy_rotate
95599 };
95600
95601 void rb_insert_color(struct rb_node *node, struct rb_root *root)
95602diff --git a/lib/show_mem.c b/lib/show_mem.c
95603index 0922579..9d7adb9 100644
95604--- a/lib/show_mem.c
95605+++ b/lib/show_mem.c
95606@@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
95607 quicklist_total_size());
95608 #endif
95609 #ifdef CONFIG_MEMORY_FAILURE
95610- printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
95611+ printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
95612 #endif
95613 }
95614diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
95615index bb2b201..46abaf9 100644
95616--- a/lib/strncpy_from_user.c
95617+++ b/lib/strncpy_from_user.c
95618@@ -21,7 +21,7 @@
95619 */
95620 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
95621 {
95622- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95623+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95624 long res = 0;
95625
95626 /*
95627diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
95628index a28df52..3d55877 100644
95629--- a/lib/strnlen_user.c
95630+++ b/lib/strnlen_user.c
95631@@ -26,7 +26,7 @@
95632 */
95633 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
95634 {
95635- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95636+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95637 long align, res = 0;
95638 unsigned long c;
95639
95640diff --git a/lib/swiotlb.c b/lib/swiotlb.c
95641index 4abda07..b9d3765 100644
95642--- a/lib/swiotlb.c
95643+++ b/lib/swiotlb.c
95644@@ -682,7 +682,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
95645
95646 void
95647 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
95648- dma_addr_t dev_addr)
95649+ dma_addr_t dev_addr, struct dma_attrs *attrs)
95650 {
95651 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
95652
95653diff --git a/lib/test_bpf.c b/lib/test_bpf.c
95654index 89e0345..3347efe 100644
95655--- a/lib/test_bpf.c
95656+++ b/lib/test_bpf.c
95657@@ -1798,7 +1798,7 @@ static struct bpf_prog *generate_filter(int which, int *err)
95658 break;
95659
95660 case INTERNAL:
95661- fp = kzalloc(bpf_prog_size(flen), GFP_KERNEL);
95662+ fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
95663 if (fp == NULL) {
95664 pr_cont("UNEXPECTED_FAIL no memory left\n");
95665 *err = -ENOMEM;
95666diff --git a/lib/usercopy.c b/lib/usercopy.c
95667index 4f5b1dd..7cab418 100644
95668--- a/lib/usercopy.c
95669+++ b/lib/usercopy.c
95670@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
95671 WARN(1, "Buffer overflow detected!\n");
95672 }
95673 EXPORT_SYMBOL(copy_from_user_overflow);
95674+
95675+void copy_to_user_overflow(void)
95676+{
95677+ WARN(1, "Buffer overflow detected!\n");
95678+}
95679+EXPORT_SYMBOL(copy_to_user_overflow);
95680diff --git a/lib/vsprintf.c b/lib/vsprintf.c
95681index 6fe2c84..2fe5ec6 100644
95682--- a/lib/vsprintf.c
95683+++ b/lib/vsprintf.c
95684@@ -16,6 +16,9 @@
95685 * - scnprintf and vscnprintf
95686 */
95687
95688+#ifdef CONFIG_GRKERNSEC_HIDESYM
95689+#define __INCLUDED_BY_HIDESYM 1
95690+#endif
95691 #include <stdarg.h>
95692 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
95693 #include <linux/types.h>
95694@@ -624,7 +627,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
95695 #ifdef CONFIG_KALLSYMS
95696 if (*fmt == 'B')
95697 sprint_backtrace(sym, value);
95698- else if (*fmt != 'f' && *fmt != 's')
95699+ else if (*fmt != 'f' && *fmt != 's' && *fmt != 'X')
95700 sprint_symbol(sym, value);
95701 else
95702 sprint_symbol_no_offset(sym, value);
95703@@ -1183,7 +1186,11 @@ char *address_val(char *buf, char *end, const void *addr,
95704 return number(buf, end, num, spec);
95705 }
95706
95707+#ifdef CONFIG_GRKERNSEC_HIDESYM
95708+int kptr_restrict __read_mostly = 2;
95709+#else
95710 int kptr_restrict __read_mostly;
95711+#endif
95712
95713 /*
95714 * Show a '%p' thing. A kernel extension is that the '%p' is followed
95715@@ -1194,8 +1201,10 @@ int kptr_restrict __read_mostly;
95716 *
95717 * - 'F' For symbolic function descriptor pointers with offset
95718 * - 'f' For simple symbolic function names without offset
95719+ * - 'X' For simple symbolic function names without offset approved for use with GRKERNSEC_HIDESYM
95720 * - 'S' For symbolic direct pointers with offset
95721 * - 's' For symbolic direct pointers without offset
95722+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
95723 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
95724 * - 'B' For backtraced symbolic direct pointers with offset
95725 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
95726@@ -1263,12 +1272,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95727
95728 if (!ptr && *fmt != 'K') {
95729 /*
95730- * Print (null) with the same width as a pointer so it makes
95731+ * Print (nil) with the same width as a pointer so it makes
95732 * tabular output look nice.
95733 */
95734 if (spec.field_width == -1)
95735 spec.field_width = default_width;
95736- return string(buf, end, "(null)", spec);
95737+ return string(buf, end, "(nil)", spec);
95738 }
95739
95740 switch (*fmt) {
95741@@ -1278,6 +1287,14 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95742 /* Fallthrough */
95743 case 'S':
95744 case 's':
95745+#ifdef CONFIG_GRKERNSEC_HIDESYM
95746+ break;
95747+#else
95748+ return symbol_string(buf, end, ptr, spec, fmt);
95749+#endif
95750+ case 'X':
95751+ ptr = dereference_function_descriptor(ptr);
95752+ case 'A':
95753 case 'B':
95754 return symbol_string(buf, end, ptr, spec, fmt);
95755 case 'R':
95756@@ -1333,6 +1350,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95757 va_end(va);
95758 return buf;
95759 }
95760+ case 'P':
95761+ break;
95762 case 'K':
95763 /*
95764 * %pK cannot be used in IRQ context because its test
95765@@ -1390,6 +1409,22 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95766 ((const struct file *)ptr)->f_path.dentry,
95767 spec, fmt);
95768 }
95769+
95770+#ifdef CONFIG_GRKERNSEC_HIDESYM
95771+ /* 'P' = approved pointers to copy to userland,
95772+ as in the /proc/kallsyms case, as we make it display nothing
95773+ for non-root users, and the real contents for root users
95774+ 'X' = approved simple symbols
95775+ Also ignore 'K' pointers, since we force their NULLing for non-root users
95776+ above
95777+ */
95778+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'X' && *fmt != 'K' && is_usercopy_object(buf)) {
95779+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
95780+ dump_stack();
95781+ ptr = NULL;
95782+ }
95783+#endif
95784+
95785 spec.flags |= SMALL;
95786 if (spec.field_width == -1) {
95787 spec.field_width = default_width;
95788@@ -2089,11 +2124,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95789 typeof(type) value; \
95790 if (sizeof(type) == 8) { \
95791 args = PTR_ALIGN(args, sizeof(u32)); \
95792- *(u32 *)&value = *(u32 *)args; \
95793- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
95794+ *(u32 *)&value = *(const u32 *)args; \
95795+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
95796 } else { \
95797 args = PTR_ALIGN(args, sizeof(type)); \
95798- value = *(typeof(type) *)args; \
95799+ value = *(const typeof(type) *)args; \
95800 } \
95801 args += sizeof(type); \
95802 value; \
95803@@ -2156,7 +2191,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95804 case FORMAT_TYPE_STR: {
95805 const char *str_arg = args;
95806 args += strlen(str_arg) + 1;
95807- str = string(str, end, (char *)str_arg, spec);
95808+ str = string(str, end, str_arg, spec);
95809 break;
95810 }
95811
95812diff --git a/localversion-grsec b/localversion-grsec
95813new file mode 100644
95814index 0000000..7cd6065
95815--- /dev/null
95816+++ b/localversion-grsec
95817@@ -0,0 +1 @@
95818+-grsec
95819diff --git a/mm/Kconfig b/mm/Kconfig
95820index 886db21..f514de2 100644
95821--- a/mm/Kconfig
95822+++ b/mm/Kconfig
95823@@ -333,10 +333,11 @@ config KSM
95824 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
95825
95826 config DEFAULT_MMAP_MIN_ADDR
95827- int "Low address space to protect from user allocation"
95828+ int "Low address space to protect from user allocation"
95829 depends on MMU
95830- default 4096
95831- help
95832+ default 32768 if ALPHA || ARM || PARISC || SPARC32
95833+ default 65536
95834+ help
95835 This is the portion of low virtual memory which should be protected
95836 from userspace allocation. Keeping a user from writing to low pages
95837 can help reduce the impact of kernel NULL pointer bugs.
95838@@ -367,7 +368,7 @@ config MEMORY_FAILURE
95839
95840 config HWPOISON_INJECT
95841 tristate "HWPoison pages injector"
95842- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
95843+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
95844 select PROC_PAGE_MONITOR
95845
95846 config NOMMU_INITIAL_TRIM_EXCESS
95847diff --git a/mm/backing-dev.c b/mm/backing-dev.c
95848index 1706cbb..f89dbca 100644
95849--- a/mm/backing-dev.c
95850+++ b/mm/backing-dev.c
95851@@ -12,7 +12,7 @@
95852 #include <linux/device.h>
95853 #include <trace/events/writeback.h>
95854
95855-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
95856+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
95857
95858 struct backing_dev_info default_backing_dev_info = {
95859 .name = "default",
95860@@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
95861 return err;
95862
95863 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
95864- atomic_long_inc_return(&bdi_seq));
95865+ atomic_long_inc_return_unchecked(&bdi_seq));
95866 if (err) {
95867 bdi_destroy(bdi);
95868 return err;
95869diff --git a/mm/filemap.c b/mm/filemap.c
95870index 90effcd..539aa64 100644
95871--- a/mm/filemap.c
95872+++ b/mm/filemap.c
95873@@ -2092,7 +2092,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
95874 struct address_space *mapping = file->f_mapping;
95875
95876 if (!mapping->a_ops->readpage)
95877- return -ENOEXEC;
95878+ return -ENODEV;
95879 file_accessed(file);
95880 vma->vm_ops = &generic_file_vm_ops;
95881 return 0;
95882@@ -2270,6 +2270,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
95883 *pos = i_size_read(inode);
95884
95885 if (limit != RLIM_INFINITY) {
95886+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
95887 if (*pos >= limit) {
95888 send_sig(SIGXFSZ, current, 0);
95889 return -EFBIG;
95890diff --git a/mm/fremap.c b/mm/fremap.c
95891index 72b8fa3..c5b39f1 100644
95892--- a/mm/fremap.c
95893+++ b/mm/fremap.c
95894@@ -180,6 +180,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
95895 retry:
95896 vma = find_vma(mm, start);
95897
95898+#ifdef CONFIG_PAX_SEGMEXEC
95899+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
95900+ goto out;
95901+#endif
95902+
95903 /*
95904 * Make sure the vma is shared, that it supports prefaulting,
95905 * and that the remapped range is valid and fully within
95906diff --git a/mm/gup.c b/mm/gup.c
95907index 91d044b..a58ecf6 100644
95908--- a/mm/gup.c
95909+++ b/mm/gup.c
95910@@ -270,11 +270,6 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
95911 unsigned int fault_flags = 0;
95912 int ret;
95913
95914- /* For mlock, just skip the stack guard page. */
95915- if ((*flags & FOLL_MLOCK) &&
95916- (stack_guard_page_start(vma, address) ||
95917- stack_guard_page_end(vma, address + PAGE_SIZE)))
95918- return -ENOENT;
95919 if (*flags & FOLL_WRITE)
95920 fault_flags |= FAULT_FLAG_WRITE;
95921 if (nonblocking)
95922@@ -436,14 +431,14 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95923 if (!(gup_flags & FOLL_FORCE))
95924 gup_flags |= FOLL_NUMA;
95925
95926- do {
95927+ while (nr_pages) {
95928 struct page *page;
95929 unsigned int foll_flags = gup_flags;
95930 unsigned int page_increm;
95931
95932 /* first iteration or cross vma bound */
95933 if (!vma || start >= vma->vm_end) {
95934- vma = find_extend_vma(mm, start);
95935+ vma = find_vma(mm, start);
95936 if (!vma && in_gate_area(mm, start)) {
95937 int ret;
95938 ret = get_gate_page(mm, start & PAGE_MASK,
95939@@ -455,7 +450,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95940 goto next_page;
95941 }
95942
95943- if (!vma || check_vma_flags(vma, gup_flags))
95944+ if (!vma || start < vma->vm_start || check_vma_flags(vma, gup_flags))
95945 return i ? : -EFAULT;
95946 if (is_vm_hugetlb_page(vma)) {
95947 i = follow_hugetlb_page(mm, vma, pages, vmas,
95948@@ -510,7 +505,7 @@ next_page:
95949 i += page_increm;
95950 start += page_increm * PAGE_SIZE;
95951 nr_pages -= page_increm;
95952- } while (nr_pages);
95953+ }
95954 return i;
95955 }
95956 EXPORT_SYMBOL(__get_user_pages);
95957diff --git a/mm/highmem.c b/mm/highmem.c
95958index 123bcd3..0de52ba 100644
95959--- a/mm/highmem.c
95960+++ b/mm/highmem.c
95961@@ -195,8 +195,9 @@ static void flush_all_zero_pkmaps(void)
95962 * So no dangers, even with speculative execution.
95963 */
95964 page = pte_page(pkmap_page_table[i]);
95965+ pax_open_kernel();
95966 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
95967-
95968+ pax_close_kernel();
95969 set_page_address(page, NULL);
95970 need_flush = 1;
95971 }
95972@@ -259,9 +260,11 @@ start:
95973 }
95974 }
95975 vaddr = PKMAP_ADDR(last_pkmap_nr);
95976+
95977+ pax_open_kernel();
95978 set_pte_at(&init_mm, vaddr,
95979 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
95980-
95981+ pax_close_kernel();
95982 pkmap_count[last_pkmap_nr] = 1;
95983 set_page_address(page, (void *)vaddr);
95984
95985diff --git a/mm/hugetlb.c b/mm/hugetlb.c
95986index eeceeeb..a209d58 100644
95987--- a/mm/hugetlb.c
95988+++ b/mm/hugetlb.c
95989@@ -2258,6 +2258,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95990 struct ctl_table *table, int write,
95991 void __user *buffer, size_t *length, loff_t *ppos)
95992 {
95993+ ctl_table_no_const t;
95994 struct hstate *h = &default_hstate;
95995 unsigned long tmp = h->max_huge_pages;
95996 int ret;
95997@@ -2265,9 +2266,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95998 if (!hugepages_supported())
95999 return -ENOTSUPP;
96000
96001- table->data = &tmp;
96002- table->maxlen = sizeof(unsigned long);
96003- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
96004+ t = *table;
96005+ t.data = &tmp;
96006+ t.maxlen = sizeof(unsigned long);
96007+ ret = proc_doulongvec_minmax(&t, write, buffer, length, ppos);
96008 if (ret)
96009 goto out;
96010
96011@@ -2302,6 +2304,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
96012 struct hstate *h = &default_hstate;
96013 unsigned long tmp;
96014 int ret;
96015+ ctl_table_no_const hugetlb_table;
96016
96017 if (!hugepages_supported())
96018 return -ENOTSUPP;
96019@@ -2311,9 +2314,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
96020 if (write && hstate_is_gigantic(h))
96021 return -EINVAL;
96022
96023- table->data = &tmp;
96024- table->maxlen = sizeof(unsigned long);
96025- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
96026+ hugetlb_table = *table;
96027+ hugetlb_table.data = &tmp;
96028+ hugetlb_table.maxlen = sizeof(unsigned long);
96029+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
96030 if (ret)
96031 goto out;
96032
96033@@ -2792,6 +2796,27 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
96034 mutex_unlock(&mapping->i_mmap_mutex);
96035 }
96036
96037+#ifdef CONFIG_PAX_SEGMEXEC
96038+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
96039+{
96040+ struct mm_struct *mm = vma->vm_mm;
96041+ struct vm_area_struct *vma_m;
96042+ unsigned long address_m;
96043+ pte_t *ptep_m;
96044+
96045+ vma_m = pax_find_mirror_vma(vma);
96046+ if (!vma_m)
96047+ return;
96048+
96049+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96050+ address_m = address + SEGMEXEC_TASK_SIZE;
96051+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
96052+ get_page(page_m);
96053+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
96054+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
96055+}
96056+#endif
96057+
96058 /*
96059 * Hugetlb_cow() should be called with page lock of the original hugepage held.
96060 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
96061@@ -2903,6 +2928,11 @@ retry_avoidcopy:
96062 make_huge_pte(vma, new_page, 1));
96063 page_remove_rmap(old_page);
96064 hugepage_add_new_anon_rmap(new_page, vma, address);
96065+
96066+#ifdef CONFIG_PAX_SEGMEXEC
96067+ pax_mirror_huge_pte(vma, address, new_page);
96068+#endif
96069+
96070 /* Make the old page be freed below */
96071 new_page = old_page;
96072 }
96073@@ -3063,6 +3093,10 @@ retry:
96074 && (vma->vm_flags & VM_SHARED)));
96075 set_huge_pte_at(mm, address, ptep, new_pte);
96076
96077+#ifdef CONFIG_PAX_SEGMEXEC
96078+ pax_mirror_huge_pte(vma, address, page);
96079+#endif
96080+
96081 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
96082 /* Optimization, do the COW without a second fault */
96083 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
96084@@ -3129,6 +3163,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96085 struct hstate *h = hstate_vma(vma);
96086 struct address_space *mapping;
96087
96088+#ifdef CONFIG_PAX_SEGMEXEC
96089+ struct vm_area_struct *vma_m;
96090+#endif
96091+
96092 address &= huge_page_mask(h);
96093
96094 ptep = huge_pte_offset(mm, address);
96095@@ -3142,6 +3180,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96096 VM_FAULT_SET_HINDEX(hstate_index(h));
96097 }
96098
96099+#ifdef CONFIG_PAX_SEGMEXEC
96100+ vma_m = pax_find_mirror_vma(vma);
96101+ if (vma_m) {
96102+ unsigned long address_m;
96103+
96104+ if (vma->vm_start > vma_m->vm_start) {
96105+ address_m = address;
96106+ address -= SEGMEXEC_TASK_SIZE;
96107+ vma = vma_m;
96108+ h = hstate_vma(vma);
96109+ } else
96110+ address_m = address + SEGMEXEC_TASK_SIZE;
96111+
96112+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
96113+ return VM_FAULT_OOM;
96114+ address_m &= HPAGE_MASK;
96115+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
96116+ }
96117+#endif
96118+
96119 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
96120 if (!ptep)
96121 return VM_FAULT_OOM;
96122diff --git a/mm/internal.h b/mm/internal.h
96123index 5f2772f..4c3882c 100644
96124--- a/mm/internal.h
96125+++ b/mm/internal.h
96126@@ -134,6 +134,7 @@ __find_buddy_index(unsigned long page_idx, unsigned int order)
96127
96128 extern int __isolate_free_page(struct page *page, unsigned int order);
96129 extern void __free_pages_bootmem(struct page *page, unsigned int order);
96130+extern void free_compound_page(struct page *page);
96131 extern void prep_compound_page(struct page *page, unsigned long order);
96132 #ifdef CONFIG_MEMORY_FAILURE
96133 extern bool is_free_buddy_page(struct page *page);
96134@@ -376,7 +377,7 @@ extern u32 hwpoison_filter_enable;
96135
96136 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
96137 unsigned long, unsigned long,
96138- unsigned long, unsigned long);
96139+ unsigned long, unsigned long) __intentional_overflow(-1);
96140
96141 extern void set_pageblock_order(void);
96142 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
96143diff --git a/mm/iov_iter.c b/mm/iov_iter.c
96144index 141dcf7..7327fd3 100644
96145--- a/mm/iov_iter.c
96146+++ b/mm/iov_iter.c
96147@@ -173,7 +173,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
96148
96149 while (bytes) {
96150 char __user *buf = iov->iov_base + base;
96151- int copy = min(bytes, iov->iov_len - base);
96152+ size_t copy = min(bytes, iov->iov_len - base);
96153
96154 base = 0;
96155 left = __copy_from_user_inatomic(vaddr, buf, copy);
96156@@ -201,7 +201,7 @@ static size_t copy_from_user_atomic_iovec(struct page *page,
96157
96158 kaddr = kmap_atomic(page);
96159 if (likely(i->nr_segs == 1)) {
96160- int left;
96161+ size_t left;
96162 char __user *buf = i->iov->iov_base + i->iov_offset;
96163 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
96164 copied = bytes - left;
96165@@ -231,7 +231,7 @@ static void advance_iovec(struct iov_iter *i, size_t bytes)
96166 * zero-length segments (without overruning the iovec).
96167 */
96168 while (bytes || unlikely(i->count && !iov->iov_len)) {
96169- int copy;
96170+ size_t copy;
96171
96172 copy = min(bytes, iov->iov_len - base);
96173 BUG_ON(!i->count || i->count < copy);
96174diff --git a/mm/kmemleak.c b/mm/kmemleak.c
96175index 3cda50c..032ba634 100644
96176--- a/mm/kmemleak.c
96177+++ b/mm/kmemleak.c
96178@@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
96179
96180 for (i = 0; i < object->trace_len; i++) {
96181 void *ptr = (void *)object->trace[i];
96182- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
96183+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
96184 }
96185 }
96186
96187@@ -1905,7 +1905,7 @@ static int __init kmemleak_late_init(void)
96188 return -ENOMEM;
96189 }
96190
96191- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
96192+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
96193 &kmemleak_fops);
96194 if (!dentry)
96195 pr_warning("Failed to create the debugfs kmemleak file\n");
96196diff --git a/mm/maccess.c b/mm/maccess.c
96197index d53adf9..03a24bf 100644
96198--- a/mm/maccess.c
96199+++ b/mm/maccess.c
96200@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
96201 set_fs(KERNEL_DS);
96202 pagefault_disable();
96203 ret = __copy_from_user_inatomic(dst,
96204- (__force const void __user *)src, size);
96205+ (const void __force_user *)src, size);
96206 pagefault_enable();
96207 set_fs(old_fs);
96208
96209@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
96210
96211 set_fs(KERNEL_DS);
96212 pagefault_disable();
96213- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
96214+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
96215 pagefault_enable();
96216 set_fs(old_fs);
96217
96218diff --git a/mm/madvise.c b/mm/madvise.c
96219index 0938b30..199abe8 100644
96220--- a/mm/madvise.c
96221+++ b/mm/madvise.c
96222@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
96223 pgoff_t pgoff;
96224 unsigned long new_flags = vma->vm_flags;
96225
96226+#ifdef CONFIG_PAX_SEGMEXEC
96227+ struct vm_area_struct *vma_m;
96228+#endif
96229+
96230 switch (behavior) {
96231 case MADV_NORMAL:
96232 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
96233@@ -126,6 +130,13 @@ success:
96234 /*
96235 * vm_flags is protected by the mmap_sem held in write mode.
96236 */
96237+
96238+#ifdef CONFIG_PAX_SEGMEXEC
96239+ vma_m = pax_find_mirror_vma(vma);
96240+ if (vma_m)
96241+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
96242+#endif
96243+
96244 vma->vm_flags = new_flags;
96245
96246 out:
96247@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
96248 struct vm_area_struct **prev,
96249 unsigned long start, unsigned long end)
96250 {
96251+
96252+#ifdef CONFIG_PAX_SEGMEXEC
96253+ struct vm_area_struct *vma_m;
96254+#endif
96255+
96256 *prev = vma;
96257 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
96258 return -EINVAL;
96259@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
96260 zap_page_range(vma, start, end - start, &details);
96261 } else
96262 zap_page_range(vma, start, end - start, NULL);
96263+
96264+#ifdef CONFIG_PAX_SEGMEXEC
96265+ vma_m = pax_find_mirror_vma(vma);
96266+ if (vma_m) {
96267+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
96268+ struct zap_details details = {
96269+ .nonlinear_vma = vma_m,
96270+ .last_index = ULONG_MAX,
96271+ };
96272+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
96273+ } else
96274+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
96275+ }
96276+#endif
96277+
96278 return 0;
96279 }
96280
96281@@ -488,6 +519,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
96282 if (end < start)
96283 return error;
96284
96285+#ifdef CONFIG_PAX_SEGMEXEC
96286+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
96287+ if (end > SEGMEXEC_TASK_SIZE)
96288+ return error;
96289+ } else
96290+#endif
96291+
96292+ if (end > TASK_SIZE)
96293+ return error;
96294+
96295 error = 0;
96296 if (end == start)
96297 return error;
96298diff --git a/mm/memory-failure.c b/mm/memory-failure.c
96299index 44c6bd2..60369dc3 100644
96300--- a/mm/memory-failure.c
96301+++ b/mm/memory-failure.c
96302@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
96303
96304 int sysctl_memory_failure_recovery __read_mostly = 1;
96305
96306-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
96307+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
96308
96309 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
96310
96311@@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
96312 pfn, t->comm, t->pid);
96313 si.si_signo = SIGBUS;
96314 si.si_errno = 0;
96315- si.si_addr = (void *)addr;
96316+ si.si_addr = (void __user *)addr;
96317 #ifdef __ARCH_SI_TRAPNO
96318 si.si_trapno = trapno;
96319 #endif
96320@@ -791,7 +791,7 @@ static struct page_state {
96321 unsigned long res;
96322 char *msg;
96323 int (*action)(struct page *p, unsigned long pfn);
96324-} error_states[] = {
96325+} __do_const error_states[] = {
96326 { reserved, reserved, "reserved kernel", me_kernel },
96327 /*
96328 * free pages are specially detected outside this table:
96329@@ -1099,7 +1099,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
96330 nr_pages = 1 << compound_order(hpage);
96331 else /* normal page or thp */
96332 nr_pages = 1;
96333- atomic_long_add(nr_pages, &num_poisoned_pages);
96334+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
96335
96336 /*
96337 * We need/can do nothing about count=0 pages.
96338@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
96339 if (PageHWPoison(hpage)) {
96340 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
96341 || (p != hpage && TestSetPageHWPoison(hpage))) {
96342- atomic_long_sub(nr_pages, &num_poisoned_pages);
96343+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96344 unlock_page(hpage);
96345 return 0;
96346 }
96347@@ -1196,14 +1196,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
96348 */
96349 if (!PageHWPoison(p)) {
96350 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
96351- atomic_long_sub(nr_pages, &num_poisoned_pages);
96352+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96353 put_page(hpage);
96354 res = 0;
96355 goto out;
96356 }
96357 if (hwpoison_filter(p)) {
96358 if (TestClearPageHWPoison(p))
96359- atomic_long_sub(nr_pages, &num_poisoned_pages);
96360+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96361 unlock_page(hpage);
96362 put_page(hpage);
96363 return 0;
96364@@ -1433,7 +1433,7 @@ int unpoison_memory(unsigned long pfn)
96365 return 0;
96366 }
96367 if (TestClearPageHWPoison(p))
96368- atomic_long_dec(&num_poisoned_pages);
96369+ atomic_long_dec_unchecked(&num_poisoned_pages);
96370 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
96371 return 0;
96372 }
96373@@ -1447,7 +1447,7 @@ int unpoison_memory(unsigned long pfn)
96374 */
96375 if (TestClearPageHWPoison(page)) {
96376 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
96377- atomic_long_sub(nr_pages, &num_poisoned_pages);
96378+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96379 freeit = 1;
96380 if (PageHuge(page))
96381 clear_page_hwpoison_huge_page(page);
96382@@ -1572,11 +1572,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
96383 if (PageHuge(page)) {
96384 set_page_hwpoison_huge_page(hpage);
96385 dequeue_hwpoisoned_huge_page(hpage);
96386- atomic_long_add(1 << compound_order(hpage),
96387+ atomic_long_add_unchecked(1 << compound_order(hpage),
96388 &num_poisoned_pages);
96389 } else {
96390 SetPageHWPoison(page);
96391- atomic_long_inc(&num_poisoned_pages);
96392+ atomic_long_inc_unchecked(&num_poisoned_pages);
96393 }
96394 }
96395 return ret;
96396@@ -1615,7 +1615,7 @@ static int __soft_offline_page(struct page *page, int flags)
96397 put_page(page);
96398 pr_info("soft_offline: %#lx: invalidated\n", pfn);
96399 SetPageHWPoison(page);
96400- atomic_long_inc(&num_poisoned_pages);
96401+ atomic_long_inc_unchecked(&num_poisoned_pages);
96402 return 0;
96403 }
96404
96405@@ -1666,7 +1666,7 @@ static int __soft_offline_page(struct page *page, int flags)
96406 if (!is_free_buddy_page(page))
96407 pr_info("soft offline: %#lx: page leaked\n",
96408 pfn);
96409- atomic_long_inc(&num_poisoned_pages);
96410+ atomic_long_inc_unchecked(&num_poisoned_pages);
96411 }
96412 } else {
96413 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
96414@@ -1736,11 +1736,11 @@ int soft_offline_page(struct page *page, int flags)
96415 if (PageHuge(page)) {
96416 set_page_hwpoison_huge_page(hpage);
96417 dequeue_hwpoisoned_huge_page(hpage);
96418- atomic_long_add(1 << compound_order(hpage),
96419+ atomic_long_add_unchecked(1 << compound_order(hpage),
96420 &num_poisoned_pages);
96421 } else {
96422 SetPageHWPoison(page);
96423- atomic_long_inc(&num_poisoned_pages);
96424+ atomic_long_inc_unchecked(&num_poisoned_pages);
96425 }
96426 }
96427 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
96428diff --git a/mm/memory.c b/mm/memory.c
96429index 37b80fc..9cdef79 100644
96430--- a/mm/memory.c
96431+++ b/mm/memory.c
96432@@ -415,6 +415,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
96433 free_pte_range(tlb, pmd, addr);
96434 } while (pmd++, addr = next, addr != end);
96435
96436+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
96437 start &= PUD_MASK;
96438 if (start < floor)
96439 return;
96440@@ -429,6 +430,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
96441 pmd = pmd_offset(pud, start);
96442 pud_clear(pud);
96443 pmd_free_tlb(tlb, pmd, start);
96444+#endif
96445+
96446 }
96447
96448 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96449@@ -448,6 +451,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96450 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
96451 } while (pud++, addr = next, addr != end);
96452
96453+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
96454 start &= PGDIR_MASK;
96455 if (start < floor)
96456 return;
96457@@ -462,6 +466,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96458 pud = pud_offset(pgd, start);
96459 pgd_clear(pgd);
96460 pud_free_tlb(tlb, pud, start);
96461+#endif
96462+
96463 }
96464
96465 /*
96466@@ -691,10 +697,10 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr,
96467 * Choose text because data symbols depend on CONFIG_KALLSYMS_ALL=y
96468 */
96469 if (vma->vm_ops)
96470- printk(KERN_ALERT "vma->vm_ops->fault: %pSR\n",
96471+ printk(KERN_ALERT "vma->vm_ops->fault: %pAR\n",
96472 vma->vm_ops->fault);
96473 if (vma->vm_file)
96474- printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pSR\n",
96475+ printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pAR\n",
96476 vma->vm_file->f_op->mmap);
96477 dump_stack();
96478 add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
96479@@ -815,20 +821,20 @@ copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
96480 if (!pte_file(pte)) {
96481 swp_entry_t entry = pte_to_swp_entry(pte);
96482
96483- if (swap_duplicate(entry) < 0)
96484- return entry.val;
96485+ if (likely(!non_swap_entry(entry))) {
96486+ if (swap_duplicate(entry) < 0)
96487+ return entry.val;
96488
96489- /* make sure dst_mm is on swapoff's mmlist. */
96490- if (unlikely(list_empty(&dst_mm->mmlist))) {
96491- spin_lock(&mmlist_lock);
96492- if (list_empty(&dst_mm->mmlist))
96493- list_add(&dst_mm->mmlist,
96494- &src_mm->mmlist);
96495- spin_unlock(&mmlist_lock);
96496- }
96497- if (likely(!non_swap_entry(entry)))
96498+ /* make sure dst_mm is on swapoff's mmlist. */
96499+ if (unlikely(list_empty(&dst_mm->mmlist))) {
96500+ spin_lock(&mmlist_lock);
96501+ if (list_empty(&dst_mm->mmlist))
96502+ list_add(&dst_mm->mmlist,
96503+ &src_mm->mmlist);
96504+ spin_unlock(&mmlist_lock);
96505+ }
96506 rss[MM_SWAPENTS]++;
96507- else if (is_migration_entry(entry)) {
96508+ } else if (is_migration_entry(entry)) {
96509 page = migration_entry_to_page(entry);
96510
96511 if (PageAnon(page))
96512@@ -1501,6 +1507,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
96513 page_add_file_rmap(page);
96514 set_pte_at(mm, addr, pte, mk_pte(page, prot));
96515
96516+#ifdef CONFIG_PAX_SEGMEXEC
96517+ pax_mirror_file_pte(vma, addr, page, ptl);
96518+#endif
96519+
96520 retval = 0;
96521 pte_unmap_unlock(pte, ptl);
96522 return retval;
96523@@ -1545,9 +1555,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
96524 if (!page_count(page))
96525 return -EINVAL;
96526 if (!(vma->vm_flags & VM_MIXEDMAP)) {
96527+
96528+#ifdef CONFIG_PAX_SEGMEXEC
96529+ struct vm_area_struct *vma_m;
96530+#endif
96531+
96532 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
96533 BUG_ON(vma->vm_flags & VM_PFNMAP);
96534 vma->vm_flags |= VM_MIXEDMAP;
96535+
96536+#ifdef CONFIG_PAX_SEGMEXEC
96537+ vma_m = pax_find_mirror_vma(vma);
96538+ if (vma_m)
96539+ vma_m->vm_flags |= VM_MIXEDMAP;
96540+#endif
96541+
96542 }
96543 return insert_page(vma, addr, page, vma->vm_page_prot);
96544 }
96545@@ -1630,6 +1652,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
96546 unsigned long pfn)
96547 {
96548 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
96549+ BUG_ON(vma->vm_mirror);
96550
96551 if (addr < vma->vm_start || addr >= vma->vm_end)
96552 return -EFAULT;
96553@@ -1877,7 +1900,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
96554
96555 BUG_ON(pud_huge(*pud));
96556
96557- pmd = pmd_alloc(mm, pud, addr);
96558+ pmd = (mm == &init_mm) ?
96559+ pmd_alloc_kernel(mm, pud, addr) :
96560+ pmd_alloc(mm, pud, addr);
96561 if (!pmd)
96562 return -ENOMEM;
96563 do {
96564@@ -1897,7 +1922,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
96565 unsigned long next;
96566 int err;
96567
96568- pud = pud_alloc(mm, pgd, addr);
96569+ pud = (mm == &init_mm) ?
96570+ pud_alloc_kernel(mm, pgd, addr) :
96571+ pud_alloc(mm, pgd, addr);
96572 if (!pud)
96573 return -ENOMEM;
96574 do {
96575@@ -2019,6 +2046,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
96576 return ret;
96577 }
96578
96579+#ifdef CONFIG_PAX_SEGMEXEC
96580+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
96581+{
96582+ struct mm_struct *mm = vma->vm_mm;
96583+ spinlock_t *ptl;
96584+ pte_t *pte, entry;
96585+
96586+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
96587+ entry = *pte;
96588+ if (!pte_present(entry)) {
96589+ if (!pte_none(entry)) {
96590+ BUG_ON(pte_file(entry));
96591+ free_swap_and_cache(pte_to_swp_entry(entry));
96592+ pte_clear_not_present_full(mm, address, pte, 0);
96593+ }
96594+ } else {
96595+ struct page *page;
96596+
96597+ flush_cache_page(vma, address, pte_pfn(entry));
96598+ entry = ptep_clear_flush(vma, address, pte);
96599+ BUG_ON(pte_dirty(entry));
96600+ page = vm_normal_page(vma, address, entry);
96601+ if (page) {
96602+ update_hiwater_rss(mm);
96603+ if (PageAnon(page))
96604+ dec_mm_counter_fast(mm, MM_ANONPAGES);
96605+ else
96606+ dec_mm_counter_fast(mm, MM_FILEPAGES);
96607+ page_remove_rmap(page);
96608+ page_cache_release(page);
96609+ }
96610+ }
96611+ pte_unmap_unlock(pte, ptl);
96612+}
96613+
96614+/* PaX: if vma is mirrored, synchronize the mirror's PTE
96615+ *
96616+ * the ptl of the lower mapped page is held on entry and is not released on exit
96617+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
96618+ */
96619+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
96620+{
96621+ struct mm_struct *mm = vma->vm_mm;
96622+ unsigned long address_m;
96623+ spinlock_t *ptl_m;
96624+ struct vm_area_struct *vma_m;
96625+ pmd_t *pmd_m;
96626+ pte_t *pte_m, entry_m;
96627+
96628+ BUG_ON(!page_m || !PageAnon(page_m));
96629+
96630+ vma_m = pax_find_mirror_vma(vma);
96631+ if (!vma_m)
96632+ return;
96633+
96634+ BUG_ON(!PageLocked(page_m));
96635+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96636+ address_m = address + SEGMEXEC_TASK_SIZE;
96637+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96638+ pte_m = pte_offset_map(pmd_m, address_m);
96639+ ptl_m = pte_lockptr(mm, pmd_m);
96640+ if (ptl != ptl_m) {
96641+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96642+ if (!pte_none(*pte_m))
96643+ goto out;
96644+ }
96645+
96646+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96647+ page_cache_get(page_m);
96648+ page_add_anon_rmap(page_m, vma_m, address_m);
96649+ inc_mm_counter_fast(mm, MM_ANONPAGES);
96650+ set_pte_at(mm, address_m, pte_m, entry_m);
96651+ update_mmu_cache(vma_m, address_m, pte_m);
96652+out:
96653+ if (ptl != ptl_m)
96654+ spin_unlock(ptl_m);
96655+ pte_unmap(pte_m);
96656+ unlock_page(page_m);
96657+}
96658+
96659+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
96660+{
96661+ struct mm_struct *mm = vma->vm_mm;
96662+ unsigned long address_m;
96663+ spinlock_t *ptl_m;
96664+ struct vm_area_struct *vma_m;
96665+ pmd_t *pmd_m;
96666+ pte_t *pte_m, entry_m;
96667+
96668+ BUG_ON(!page_m || PageAnon(page_m));
96669+
96670+ vma_m = pax_find_mirror_vma(vma);
96671+ if (!vma_m)
96672+ return;
96673+
96674+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96675+ address_m = address + SEGMEXEC_TASK_SIZE;
96676+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96677+ pte_m = pte_offset_map(pmd_m, address_m);
96678+ ptl_m = pte_lockptr(mm, pmd_m);
96679+ if (ptl != ptl_m) {
96680+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96681+ if (!pte_none(*pte_m))
96682+ goto out;
96683+ }
96684+
96685+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96686+ page_cache_get(page_m);
96687+ page_add_file_rmap(page_m);
96688+ inc_mm_counter_fast(mm, MM_FILEPAGES);
96689+ set_pte_at(mm, address_m, pte_m, entry_m);
96690+ update_mmu_cache(vma_m, address_m, pte_m);
96691+out:
96692+ if (ptl != ptl_m)
96693+ spin_unlock(ptl_m);
96694+ pte_unmap(pte_m);
96695+}
96696+
96697+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
96698+{
96699+ struct mm_struct *mm = vma->vm_mm;
96700+ unsigned long address_m;
96701+ spinlock_t *ptl_m;
96702+ struct vm_area_struct *vma_m;
96703+ pmd_t *pmd_m;
96704+ pte_t *pte_m, entry_m;
96705+
96706+ vma_m = pax_find_mirror_vma(vma);
96707+ if (!vma_m)
96708+ return;
96709+
96710+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96711+ address_m = address + SEGMEXEC_TASK_SIZE;
96712+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96713+ pte_m = pte_offset_map(pmd_m, address_m);
96714+ ptl_m = pte_lockptr(mm, pmd_m);
96715+ if (ptl != ptl_m) {
96716+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96717+ if (!pte_none(*pte_m))
96718+ goto out;
96719+ }
96720+
96721+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
96722+ set_pte_at(mm, address_m, pte_m, entry_m);
96723+out:
96724+ if (ptl != ptl_m)
96725+ spin_unlock(ptl_m);
96726+ pte_unmap(pte_m);
96727+}
96728+
96729+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
96730+{
96731+ struct page *page_m;
96732+ pte_t entry;
96733+
96734+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
96735+ goto out;
96736+
96737+ entry = *pte;
96738+ page_m = vm_normal_page(vma, address, entry);
96739+ if (!page_m)
96740+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
96741+ else if (PageAnon(page_m)) {
96742+ if (pax_find_mirror_vma(vma)) {
96743+ pte_unmap_unlock(pte, ptl);
96744+ lock_page(page_m);
96745+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
96746+ if (pte_same(entry, *pte))
96747+ pax_mirror_anon_pte(vma, address, page_m, ptl);
96748+ else
96749+ unlock_page(page_m);
96750+ }
96751+ } else
96752+ pax_mirror_file_pte(vma, address, page_m, ptl);
96753+
96754+out:
96755+ pte_unmap_unlock(pte, ptl);
96756+}
96757+#endif
96758+
96759 /*
96760 * This routine handles present pages, when users try to write
96761 * to a shared page. It is done by copying the page to a new address
96762@@ -2217,6 +2424,12 @@ gotten:
96763 */
96764 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96765 if (likely(pte_same(*page_table, orig_pte))) {
96766+
96767+#ifdef CONFIG_PAX_SEGMEXEC
96768+ if (pax_find_mirror_vma(vma))
96769+ BUG_ON(!trylock_page(new_page));
96770+#endif
96771+
96772 if (old_page) {
96773 if (!PageAnon(old_page)) {
96774 dec_mm_counter_fast(mm, MM_FILEPAGES);
96775@@ -2270,6 +2483,10 @@ gotten:
96776 page_remove_rmap(old_page);
96777 }
96778
96779+#ifdef CONFIG_PAX_SEGMEXEC
96780+ pax_mirror_anon_pte(vma, address, new_page, ptl);
96781+#endif
96782+
96783 /* Free the old page.. */
96784 new_page = old_page;
96785 ret |= VM_FAULT_WRITE;
96786@@ -2544,6 +2761,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96787 swap_free(entry);
96788 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
96789 try_to_free_swap(page);
96790+
96791+#ifdef CONFIG_PAX_SEGMEXEC
96792+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
96793+#endif
96794+
96795 unlock_page(page);
96796 if (page != swapcache) {
96797 /*
96798@@ -2567,6 +2789,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96799
96800 /* No need to invalidate - it was non-present before */
96801 update_mmu_cache(vma, address, page_table);
96802+
96803+#ifdef CONFIG_PAX_SEGMEXEC
96804+ pax_mirror_anon_pte(vma, address, page, ptl);
96805+#endif
96806+
96807 unlock:
96808 pte_unmap_unlock(page_table, ptl);
96809 out:
96810@@ -2586,40 +2813,6 @@ out_release:
96811 }
96812
96813 /*
96814- * This is like a special single-page "expand_{down|up}wards()",
96815- * except we must first make sure that 'address{-|+}PAGE_SIZE'
96816- * doesn't hit another vma.
96817- */
96818-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
96819-{
96820- address &= PAGE_MASK;
96821- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
96822- struct vm_area_struct *prev = vma->vm_prev;
96823-
96824- /*
96825- * Is there a mapping abutting this one below?
96826- *
96827- * That's only ok if it's the same stack mapping
96828- * that has gotten split..
96829- */
96830- if (prev && prev->vm_end == address)
96831- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
96832-
96833- expand_downwards(vma, address - PAGE_SIZE);
96834- }
96835- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
96836- struct vm_area_struct *next = vma->vm_next;
96837-
96838- /* As VM_GROWSDOWN but s/below/above/ */
96839- if (next && next->vm_start == address + PAGE_SIZE)
96840- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
96841-
96842- expand_upwards(vma, address + PAGE_SIZE);
96843- }
96844- return 0;
96845-}
96846-
96847-/*
96848 * We enter with non-exclusive mmap_sem (to exclude vma changes,
96849 * but allow concurrent faults), and pte mapped but not yet locked.
96850 * We return with mmap_sem still held, but pte unmapped and unlocked.
96851@@ -2629,27 +2822,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96852 unsigned int flags)
96853 {
96854 struct mem_cgroup *memcg;
96855- struct page *page;
96856+ struct page *page = NULL;
96857 spinlock_t *ptl;
96858 pte_t entry;
96859
96860- pte_unmap(page_table);
96861-
96862- /* Check if we need to add a guard page to the stack */
96863- if (check_stack_guard_page(vma, address) < 0)
96864- return VM_FAULT_SIGBUS;
96865-
96866- /* Use the zero-page for reads */
96867 if (!(flags & FAULT_FLAG_WRITE)) {
96868 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
96869 vma->vm_page_prot));
96870- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96871+ ptl = pte_lockptr(mm, pmd);
96872+ spin_lock(ptl);
96873 if (!pte_none(*page_table))
96874 goto unlock;
96875 goto setpte;
96876 }
96877
96878 /* Allocate our own private page. */
96879+ pte_unmap(page_table);
96880+
96881 if (unlikely(anon_vma_prepare(vma)))
96882 goto oom;
96883 page = alloc_zeroed_user_highpage_movable(vma, address);
96884@@ -2673,6 +2862,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96885 if (!pte_none(*page_table))
96886 goto release;
96887
96888+#ifdef CONFIG_PAX_SEGMEXEC
96889+ if (pax_find_mirror_vma(vma))
96890+ BUG_ON(!trylock_page(page));
96891+#endif
96892+
96893 inc_mm_counter_fast(mm, MM_ANONPAGES);
96894 page_add_new_anon_rmap(page, vma, address);
96895 mem_cgroup_commit_charge(page, memcg, false);
96896@@ -2682,6 +2876,12 @@ setpte:
96897
96898 /* No need to invalidate - it was non-present before */
96899 update_mmu_cache(vma, address, page_table);
96900+
96901+#ifdef CONFIG_PAX_SEGMEXEC
96902+ if (page)
96903+ pax_mirror_anon_pte(vma, address, page, ptl);
96904+#endif
96905+
96906 unlock:
96907 pte_unmap_unlock(page_table, ptl);
96908 return 0;
96909@@ -2912,6 +3112,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96910 return ret;
96911 }
96912 do_set_pte(vma, address, fault_page, pte, false, false);
96913+
96914+#ifdef CONFIG_PAX_SEGMEXEC
96915+ pax_mirror_file_pte(vma, address, fault_page, ptl);
96916+#endif
96917+
96918 unlock_page(fault_page);
96919 unlock_out:
96920 pte_unmap_unlock(pte, ptl);
96921@@ -2954,7 +3159,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96922 page_cache_release(fault_page);
96923 goto uncharge_out;
96924 }
96925+
96926+#ifdef CONFIG_PAX_SEGMEXEC
96927+ if (pax_find_mirror_vma(vma))
96928+ BUG_ON(!trylock_page(new_page));
96929+#endif
96930+
96931 do_set_pte(vma, address, new_page, pte, true, true);
96932+
96933+#ifdef CONFIG_PAX_SEGMEXEC
96934+ pax_mirror_anon_pte(vma, address, new_page, ptl);
96935+#endif
96936+
96937 mem_cgroup_commit_charge(new_page, memcg, false);
96938 lru_cache_add_active_or_unevictable(new_page, vma);
96939 pte_unmap_unlock(pte, ptl);
96940@@ -3004,6 +3220,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96941 return ret;
96942 }
96943 do_set_pte(vma, address, fault_page, pte, true, false);
96944+
96945+#ifdef CONFIG_PAX_SEGMEXEC
96946+ pax_mirror_file_pte(vma, address, fault_page, ptl);
96947+#endif
96948+
96949 pte_unmap_unlock(pte, ptl);
96950
96951 if (set_page_dirty(fault_page))
96952@@ -3245,6 +3466,12 @@ static int handle_pte_fault(struct mm_struct *mm,
96953 if (flags & FAULT_FLAG_WRITE)
96954 flush_tlb_fix_spurious_fault(vma, address);
96955 }
96956+
96957+#ifdef CONFIG_PAX_SEGMEXEC
96958+ pax_mirror_pte(vma, address, pte, pmd, ptl);
96959+ return 0;
96960+#endif
96961+
96962 unlock:
96963 pte_unmap_unlock(pte, ptl);
96964 return 0;
96965@@ -3264,9 +3491,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96966 pmd_t *pmd;
96967 pte_t *pte;
96968
96969+#ifdef CONFIG_PAX_SEGMEXEC
96970+ struct vm_area_struct *vma_m;
96971+#endif
96972+
96973 if (unlikely(is_vm_hugetlb_page(vma)))
96974 return hugetlb_fault(mm, vma, address, flags);
96975
96976+#ifdef CONFIG_PAX_SEGMEXEC
96977+ vma_m = pax_find_mirror_vma(vma);
96978+ if (vma_m) {
96979+ unsigned long address_m;
96980+ pgd_t *pgd_m;
96981+ pud_t *pud_m;
96982+ pmd_t *pmd_m;
96983+
96984+ if (vma->vm_start > vma_m->vm_start) {
96985+ address_m = address;
96986+ address -= SEGMEXEC_TASK_SIZE;
96987+ vma = vma_m;
96988+ } else
96989+ address_m = address + SEGMEXEC_TASK_SIZE;
96990+
96991+ pgd_m = pgd_offset(mm, address_m);
96992+ pud_m = pud_alloc(mm, pgd_m, address_m);
96993+ if (!pud_m)
96994+ return VM_FAULT_OOM;
96995+ pmd_m = pmd_alloc(mm, pud_m, address_m);
96996+ if (!pmd_m)
96997+ return VM_FAULT_OOM;
96998+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
96999+ return VM_FAULT_OOM;
97000+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
97001+ }
97002+#endif
97003+
97004 pgd = pgd_offset(mm, address);
97005 pud = pud_alloc(mm, pgd, address);
97006 if (!pud)
97007@@ -3400,6 +3659,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
97008 spin_unlock(&mm->page_table_lock);
97009 return 0;
97010 }
97011+
97012+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
97013+{
97014+ pud_t *new = pud_alloc_one(mm, address);
97015+ if (!new)
97016+ return -ENOMEM;
97017+
97018+ smp_wmb(); /* See comment in __pte_alloc */
97019+
97020+ spin_lock(&mm->page_table_lock);
97021+ if (pgd_present(*pgd)) /* Another has populated it */
97022+ pud_free(mm, new);
97023+ else
97024+ pgd_populate_kernel(mm, pgd, new);
97025+ spin_unlock(&mm->page_table_lock);
97026+ return 0;
97027+}
97028 #endif /* __PAGETABLE_PUD_FOLDED */
97029
97030 #ifndef __PAGETABLE_PMD_FOLDED
97031@@ -3430,6 +3706,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
97032 spin_unlock(&mm->page_table_lock);
97033 return 0;
97034 }
97035+
97036+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
97037+{
97038+ pmd_t *new = pmd_alloc_one(mm, address);
97039+ if (!new)
97040+ return -ENOMEM;
97041+
97042+ smp_wmb(); /* See comment in __pte_alloc */
97043+
97044+ spin_lock(&mm->page_table_lock);
97045+#ifndef __ARCH_HAS_4LEVEL_HACK
97046+ if (pud_present(*pud)) /* Another has populated it */
97047+ pmd_free(mm, new);
97048+ else
97049+ pud_populate_kernel(mm, pud, new);
97050+#else
97051+ if (pgd_present(*pud)) /* Another has populated it */
97052+ pmd_free(mm, new);
97053+ else
97054+ pgd_populate_kernel(mm, pud, new);
97055+#endif /* __ARCH_HAS_4LEVEL_HACK */
97056+ spin_unlock(&mm->page_table_lock);
97057+ return 0;
97058+}
97059 #endif /* __PAGETABLE_PMD_FOLDED */
97060
97061 static int __follow_pte(struct mm_struct *mm, unsigned long address,
97062@@ -3539,8 +3839,8 @@ out:
97063 return ret;
97064 }
97065
97066-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
97067- void *buf, int len, int write)
97068+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
97069+ void *buf, size_t len, int write)
97070 {
97071 resource_size_t phys_addr;
97072 unsigned long prot = 0;
97073@@ -3566,8 +3866,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
97074 * Access another process' address space as given in mm. If non-NULL, use the
97075 * given task for page fault accounting.
97076 */
97077-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
97078- unsigned long addr, void *buf, int len, int write)
97079+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
97080+ unsigned long addr, void *buf, size_t len, int write)
97081 {
97082 struct vm_area_struct *vma;
97083 void *old_buf = buf;
97084@@ -3575,7 +3875,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
97085 down_read(&mm->mmap_sem);
97086 /* ignore errors, just check how much was successfully transferred */
97087 while (len) {
97088- int bytes, ret, offset;
97089+ ssize_t bytes, ret, offset;
97090 void *maddr;
97091 struct page *page = NULL;
97092
97093@@ -3636,8 +3936,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
97094 *
97095 * The caller must hold a reference on @mm.
97096 */
97097-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
97098- void *buf, int len, int write)
97099+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
97100+ void *buf, size_t len, int write)
97101 {
97102 return __access_remote_vm(NULL, mm, addr, buf, len, write);
97103 }
97104@@ -3647,11 +3947,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
97105 * Source/target buffer must be kernel space,
97106 * Do not walk the page table directly, use get_user_pages
97107 */
97108-int access_process_vm(struct task_struct *tsk, unsigned long addr,
97109- void *buf, int len, int write)
97110+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
97111+ void *buf, size_t len, int write)
97112 {
97113 struct mm_struct *mm;
97114- int ret;
97115+ ssize_t ret;
97116
97117 mm = get_task_mm(tsk);
97118 if (!mm)
97119diff --git a/mm/mempolicy.c b/mm/mempolicy.c
97120index 8f5330d..b41914b 100644
97121--- a/mm/mempolicy.c
97122+++ b/mm/mempolicy.c
97123@@ -750,6 +750,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
97124 unsigned long vmstart;
97125 unsigned long vmend;
97126
97127+#ifdef CONFIG_PAX_SEGMEXEC
97128+ struct vm_area_struct *vma_m;
97129+#endif
97130+
97131 vma = find_vma(mm, start);
97132 if (!vma || vma->vm_start > start)
97133 return -EFAULT;
97134@@ -793,6 +797,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
97135 err = vma_replace_policy(vma, new_pol);
97136 if (err)
97137 goto out;
97138+
97139+#ifdef CONFIG_PAX_SEGMEXEC
97140+ vma_m = pax_find_mirror_vma(vma);
97141+ if (vma_m) {
97142+ err = vma_replace_policy(vma_m, new_pol);
97143+ if (err)
97144+ goto out;
97145+ }
97146+#endif
97147+
97148 }
97149
97150 out:
97151@@ -1225,6 +1239,17 @@ static long do_mbind(unsigned long start, unsigned long len,
97152
97153 if (end < start)
97154 return -EINVAL;
97155+
97156+#ifdef CONFIG_PAX_SEGMEXEC
97157+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
97158+ if (end > SEGMEXEC_TASK_SIZE)
97159+ return -EINVAL;
97160+ } else
97161+#endif
97162+
97163+ if (end > TASK_SIZE)
97164+ return -EINVAL;
97165+
97166 if (end == start)
97167 return 0;
97168
97169@@ -1450,8 +1475,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
97170 */
97171 tcred = __task_cred(task);
97172 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
97173- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
97174- !capable(CAP_SYS_NICE)) {
97175+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
97176 rcu_read_unlock();
97177 err = -EPERM;
97178 goto out_put;
97179@@ -1482,6 +1506,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
97180 goto out;
97181 }
97182
97183+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
97184+ if (mm != current->mm &&
97185+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
97186+ mmput(mm);
97187+ err = -EPERM;
97188+ goto out;
97189+ }
97190+#endif
97191+
97192 err = do_migrate_pages(mm, old, new,
97193 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
97194
97195diff --git a/mm/migrate.c b/mm/migrate.c
97196index 0143995..b294728 100644
97197--- a/mm/migrate.c
97198+++ b/mm/migrate.c
97199@@ -1495,8 +1495,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
97200 */
97201 tcred = __task_cred(task);
97202 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
97203- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
97204- !capable(CAP_SYS_NICE)) {
97205+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
97206 rcu_read_unlock();
97207 err = -EPERM;
97208 goto out;
97209diff --git a/mm/mlock.c b/mm/mlock.c
97210index ce84cb0..6d5a9aa 100644
97211--- a/mm/mlock.c
97212+++ b/mm/mlock.c
97213@@ -14,6 +14,7 @@
97214 #include <linux/pagevec.h>
97215 #include <linux/mempolicy.h>
97216 #include <linux/syscalls.h>
97217+#include <linux/security.h>
97218 #include <linux/sched.h>
97219 #include <linux/export.h>
97220 #include <linux/rmap.h>
97221@@ -613,7 +614,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
97222 {
97223 unsigned long nstart, end, tmp;
97224 struct vm_area_struct * vma, * prev;
97225- int error;
97226+ int error = 0;
97227
97228 VM_BUG_ON(start & ~PAGE_MASK);
97229 VM_BUG_ON(len != PAGE_ALIGN(len));
97230@@ -622,6 +623,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
97231 return -EINVAL;
97232 if (end == start)
97233 return 0;
97234+ if (end > TASK_SIZE)
97235+ return -EINVAL;
97236+
97237 vma = find_vma(current->mm, start);
97238 if (!vma || vma->vm_start > start)
97239 return -ENOMEM;
97240@@ -633,6 +637,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
97241 for (nstart = start ; ; ) {
97242 vm_flags_t newflags;
97243
97244+#ifdef CONFIG_PAX_SEGMEXEC
97245+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
97246+ break;
97247+#endif
97248+
97249 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
97250
97251 newflags = vma->vm_flags & ~VM_LOCKED;
97252@@ -746,6 +755,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
97253 locked += current->mm->locked_vm;
97254
97255 /* check against resource limits */
97256+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
97257 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
97258 error = do_mlock(start, len, 1);
97259
97260@@ -783,6 +793,11 @@ static int do_mlockall(int flags)
97261 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
97262 vm_flags_t newflags;
97263
97264+#ifdef CONFIG_PAX_SEGMEXEC
97265+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
97266+ break;
97267+#endif
97268+
97269 newflags = vma->vm_flags & ~VM_LOCKED;
97270 if (flags & MCL_CURRENT)
97271 newflags |= VM_LOCKED;
97272@@ -814,8 +829,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
97273 lock_limit >>= PAGE_SHIFT;
97274
97275 ret = -ENOMEM;
97276+
97277+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
97278+
97279 down_write(&current->mm->mmap_sem);
97280-
97281 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
97282 capable(CAP_IPC_LOCK))
97283 ret = do_mlockall(flags);
97284diff --git a/mm/mmap.c b/mm/mmap.c
97285index ebc25fa..9135e65 100644
97286--- a/mm/mmap.c
97287+++ b/mm/mmap.c
97288@@ -41,6 +41,7 @@
97289 #include <linux/notifier.h>
97290 #include <linux/memory.h>
97291 #include <linux/printk.h>
97292+#include <linux/random.h>
97293
97294 #include <asm/uaccess.h>
97295 #include <asm/cacheflush.h>
97296@@ -57,6 +58,16 @@
97297 #define arch_rebalance_pgtables(addr, len) (addr)
97298 #endif
97299
97300+static inline void verify_mm_writelocked(struct mm_struct *mm)
97301+{
97302+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
97303+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
97304+ up_read(&mm->mmap_sem);
97305+ BUG();
97306+ }
97307+#endif
97308+}
97309+
97310 static void unmap_region(struct mm_struct *mm,
97311 struct vm_area_struct *vma, struct vm_area_struct *prev,
97312 unsigned long start, unsigned long end);
97313@@ -76,16 +87,25 @@ static void unmap_region(struct mm_struct *mm,
97314 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
97315 *
97316 */
97317-pgprot_t protection_map[16] = {
97318+pgprot_t protection_map[16] __read_only = {
97319 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
97320 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
97321 };
97322
97323-pgprot_t vm_get_page_prot(unsigned long vm_flags)
97324+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
97325 {
97326- return __pgprot(pgprot_val(protection_map[vm_flags &
97327+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
97328 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
97329 pgprot_val(arch_vm_get_page_prot(vm_flags)));
97330+
97331+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97332+ if (!(__supported_pte_mask & _PAGE_NX) &&
97333+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
97334+ (vm_flags & (VM_READ | VM_WRITE)))
97335+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
97336+#endif
97337+
97338+ return prot;
97339 }
97340 EXPORT_SYMBOL(vm_get_page_prot);
97341
97342@@ -95,6 +115,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
97343 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
97344 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
97345 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
97346+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
97347 /*
97348 * Make sure vm_committed_as in one cacheline and not cacheline shared with
97349 * other variables. It can be updated by several CPUs frequently.
97350@@ -255,6 +276,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
97351 struct vm_area_struct *next = vma->vm_next;
97352
97353 might_sleep();
97354+ BUG_ON(vma->vm_mirror);
97355 if (vma->vm_ops && vma->vm_ops->close)
97356 vma->vm_ops->close(vma);
97357 if (vma->vm_file)
97358@@ -299,6 +321,12 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
97359 * not page aligned -Ram Gupta
97360 */
97361 rlim = rlimit(RLIMIT_DATA);
97362+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
97363+ /* force a minimum 16MB brk heap on setuid/setgid binaries */
97364+ if (rlim < PAGE_SIZE && (get_dumpable(mm) != SUID_DUMP_USER) && gr_is_global_nonroot(current_uid()))
97365+ rlim = 4096 * PAGE_SIZE;
97366+#endif
97367+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
97368 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
97369 (mm->end_data - mm->start_data) > rlim)
97370 goto out;
97371@@ -752,8 +780,11 @@ again: remove_next = 1 + (end > next->vm_end);
97372 * shrinking vma had, to cover any anon pages imported.
97373 */
97374 if (exporter && exporter->anon_vma && !importer->anon_vma) {
97375- if (anon_vma_clone(importer, exporter))
97376- return -ENOMEM;
97377+ int error;
97378+
97379+ error = anon_vma_clone(importer, exporter);
97380+ if (error)
97381+ return error;
97382 importer->anon_vma = exporter->anon_vma;
97383 }
97384 }
97385@@ -949,6 +980,12 @@ static int
97386 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
97387 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
97388 {
97389+
97390+#ifdef CONFIG_PAX_SEGMEXEC
97391+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
97392+ return 0;
97393+#endif
97394+
97395 if (is_mergeable_vma(vma, file, vm_flags) &&
97396 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
97397 if (vma->vm_pgoff == vm_pgoff)
97398@@ -968,6 +1005,12 @@ static int
97399 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
97400 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
97401 {
97402+
97403+#ifdef CONFIG_PAX_SEGMEXEC
97404+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
97405+ return 0;
97406+#endif
97407+
97408 if (is_mergeable_vma(vma, file, vm_flags) &&
97409 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
97410 pgoff_t vm_pglen;
97411@@ -1010,13 +1053,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
97412 struct vm_area_struct *vma_merge(struct mm_struct *mm,
97413 struct vm_area_struct *prev, unsigned long addr,
97414 unsigned long end, unsigned long vm_flags,
97415- struct anon_vma *anon_vma, struct file *file,
97416+ struct anon_vma *anon_vma, struct file *file,
97417 pgoff_t pgoff, struct mempolicy *policy)
97418 {
97419 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
97420 struct vm_area_struct *area, *next;
97421 int err;
97422
97423+#ifdef CONFIG_PAX_SEGMEXEC
97424+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
97425+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
97426+
97427+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
97428+#endif
97429+
97430 /*
97431 * We later require that vma->vm_flags == vm_flags,
97432 * so this tests vma->vm_flags & VM_SPECIAL, too.
97433@@ -1032,6 +1082,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97434 if (next && next->vm_end == end) /* cases 6, 7, 8 */
97435 next = next->vm_next;
97436
97437+#ifdef CONFIG_PAX_SEGMEXEC
97438+ if (prev)
97439+ prev_m = pax_find_mirror_vma(prev);
97440+ if (area)
97441+ area_m = pax_find_mirror_vma(area);
97442+ if (next)
97443+ next_m = pax_find_mirror_vma(next);
97444+#endif
97445+
97446 /*
97447 * Can it merge with the predecessor?
97448 */
97449@@ -1051,9 +1110,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97450 /* cases 1, 6 */
97451 err = vma_adjust(prev, prev->vm_start,
97452 next->vm_end, prev->vm_pgoff, NULL);
97453- } else /* cases 2, 5, 7 */
97454+
97455+#ifdef CONFIG_PAX_SEGMEXEC
97456+ if (!err && prev_m)
97457+ err = vma_adjust(prev_m, prev_m->vm_start,
97458+ next_m->vm_end, prev_m->vm_pgoff, NULL);
97459+#endif
97460+
97461+ } else { /* cases 2, 5, 7 */
97462 err = vma_adjust(prev, prev->vm_start,
97463 end, prev->vm_pgoff, NULL);
97464+
97465+#ifdef CONFIG_PAX_SEGMEXEC
97466+ if (!err && prev_m)
97467+ err = vma_adjust(prev_m, prev_m->vm_start,
97468+ end_m, prev_m->vm_pgoff, NULL);
97469+#endif
97470+
97471+ }
97472 if (err)
97473 return NULL;
97474 khugepaged_enter_vma_merge(prev, vm_flags);
97475@@ -1067,12 +1141,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97476 mpol_equal(policy, vma_policy(next)) &&
97477 can_vma_merge_before(next, vm_flags,
97478 anon_vma, file, pgoff+pglen)) {
97479- if (prev && addr < prev->vm_end) /* case 4 */
97480+ if (prev && addr < prev->vm_end) { /* case 4 */
97481 err = vma_adjust(prev, prev->vm_start,
97482 addr, prev->vm_pgoff, NULL);
97483- else /* cases 3, 8 */
97484+
97485+#ifdef CONFIG_PAX_SEGMEXEC
97486+ if (!err && prev_m)
97487+ err = vma_adjust(prev_m, prev_m->vm_start,
97488+ addr_m, prev_m->vm_pgoff, NULL);
97489+#endif
97490+
97491+ } else { /* cases 3, 8 */
97492 err = vma_adjust(area, addr, next->vm_end,
97493 next->vm_pgoff - pglen, NULL);
97494+
97495+#ifdef CONFIG_PAX_SEGMEXEC
97496+ if (!err && area_m)
97497+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
97498+ next_m->vm_pgoff - pglen, NULL);
97499+#endif
97500+
97501+ }
97502 if (err)
97503 return NULL;
97504 khugepaged_enter_vma_merge(area, vm_flags);
97505@@ -1181,8 +1270,10 @@ none:
97506 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
97507 struct file *file, long pages)
97508 {
97509- const unsigned long stack_flags
97510- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
97511+
97512+#ifdef CONFIG_PAX_RANDMMAP
97513+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
97514+#endif
97515
97516 mm->total_vm += pages;
97517
97518@@ -1190,7 +1281,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
97519 mm->shared_vm += pages;
97520 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
97521 mm->exec_vm += pages;
97522- } else if (flags & stack_flags)
97523+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
97524 mm->stack_vm += pages;
97525 }
97526 #endif /* CONFIG_PROC_FS */
97527@@ -1220,6 +1311,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
97528 locked += mm->locked_vm;
97529 lock_limit = rlimit(RLIMIT_MEMLOCK);
97530 lock_limit >>= PAGE_SHIFT;
97531+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
97532 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
97533 return -EAGAIN;
97534 }
97535@@ -1246,7 +1338,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97536 * (the exception is when the underlying filesystem is noexec
97537 * mounted, in which case we dont add PROT_EXEC.)
97538 */
97539- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
97540+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
97541 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
97542 prot |= PROT_EXEC;
97543
97544@@ -1272,7 +1364,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97545 /* Obtain the address to map to. we verify (or select) it and ensure
97546 * that it represents a valid section of the address space.
97547 */
97548- addr = get_unmapped_area(file, addr, len, pgoff, flags);
97549+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
97550 if (addr & ~PAGE_MASK)
97551 return addr;
97552
97553@@ -1283,6 +1375,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97554 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
97555 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
97556
97557+#ifdef CONFIG_PAX_MPROTECT
97558+ if (mm->pax_flags & MF_PAX_MPROTECT) {
97559+
97560+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
97561+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
97562+ mm->binfmt->handle_mmap)
97563+ mm->binfmt->handle_mmap(file);
97564+#endif
97565+
97566+#ifndef CONFIG_PAX_MPROTECT_COMPAT
97567+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
97568+ gr_log_rwxmmap(file);
97569+
97570+#ifdef CONFIG_PAX_EMUPLT
97571+ vm_flags &= ~VM_EXEC;
97572+#else
97573+ return -EPERM;
97574+#endif
97575+
97576+ }
97577+
97578+ if (!(vm_flags & VM_EXEC))
97579+ vm_flags &= ~VM_MAYEXEC;
97580+#else
97581+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
97582+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
97583+#endif
97584+ else
97585+ vm_flags &= ~VM_MAYWRITE;
97586+ }
97587+#endif
97588+
97589+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97590+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
97591+ vm_flags &= ~VM_PAGEEXEC;
97592+#endif
97593+
97594 if (flags & MAP_LOCKED)
97595 if (!can_do_mlock())
97596 return -EPERM;
97597@@ -1370,6 +1499,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97598 vm_flags |= VM_NORESERVE;
97599 }
97600
97601+ if (!gr_acl_handle_mmap(file, prot))
97602+ return -EACCES;
97603+
97604 addr = mmap_region(file, addr, len, vm_flags, pgoff);
97605 if (!IS_ERR_VALUE(addr) &&
97606 ((vm_flags & VM_LOCKED) ||
97607@@ -1463,7 +1595,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
97608 vm_flags_t vm_flags = vma->vm_flags;
97609
97610 /* If it was private or non-writable, the write bit is already clear */
97611- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
97612+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
97613 return 0;
97614
97615 /* The backer wishes to know when pages are first written to? */
97616@@ -1509,7 +1641,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
97617 struct rb_node **rb_link, *rb_parent;
97618 unsigned long charged = 0;
97619
97620+#ifdef CONFIG_PAX_SEGMEXEC
97621+ struct vm_area_struct *vma_m = NULL;
97622+#endif
97623+
97624+ /*
97625+ * mm->mmap_sem is required to protect against another thread
97626+ * changing the mappings in case we sleep.
97627+ */
97628+ verify_mm_writelocked(mm);
97629+
97630 /* Check against address space limit. */
97631+
97632+#ifdef CONFIG_PAX_RANDMMAP
97633+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
97634+#endif
97635+
97636 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
97637 unsigned long nr_pages;
97638
97639@@ -1528,11 +1675,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
97640
97641 /* Clear old maps */
97642 error = -ENOMEM;
97643-munmap_back:
97644 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
97645 if (do_munmap(mm, addr, len))
97646 return -ENOMEM;
97647- goto munmap_back;
97648+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
97649 }
97650
97651 /*
97652@@ -1563,6 +1709,16 @@ munmap_back:
97653 goto unacct_error;
97654 }
97655
97656+#ifdef CONFIG_PAX_SEGMEXEC
97657+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
97658+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97659+ if (!vma_m) {
97660+ error = -ENOMEM;
97661+ goto free_vma;
97662+ }
97663+ }
97664+#endif
97665+
97666 vma->vm_mm = mm;
97667 vma->vm_start = addr;
97668 vma->vm_end = addr + len;
97669@@ -1593,6 +1749,13 @@ munmap_back:
97670 if (error)
97671 goto unmap_and_free_vma;
97672
97673+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97674+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
97675+ vma->vm_flags |= VM_PAGEEXEC;
97676+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
97677+ }
97678+#endif
97679+
97680 /* Can addr have changed??
97681 *
97682 * Answer: Yes, several device drivers can do it in their
97683@@ -1626,6 +1789,12 @@ munmap_back:
97684 }
97685
97686 vma_link(mm, vma, prev, rb_link, rb_parent);
97687+
97688+#ifdef CONFIG_PAX_SEGMEXEC
97689+ if (vma_m)
97690+ BUG_ON(pax_mirror_vma(vma_m, vma));
97691+#endif
97692+
97693 /* Once vma denies write, undo our temporary denial count */
97694 if (file) {
97695 if (vm_flags & VM_SHARED)
97696@@ -1638,6 +1807,7 @@ out:
97697 perf_event_mmap(vma);
97698
97699 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
97700+ track_exec_limit(mm, addr, addr + len, vm_flags);
97701 if (vm_flags & VM_LOCKED) {
97702 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
97703 vma == get_gate_vma(current->mm)))
97704@@ -1673,6 +1843,12 @@ allow_write_and_free_vma:
97705 if (vm_flags & VM_DENYWRITE)
97706 allow_write_access(file);
97707 free_vma:
97708+
97709+#ifdef CONFIG_PAX_SEGMEXEC
97710+ if (vma_m)
97711+ kmem_cache_free(vm_area_cachep, vma_m);
97712+#endif
97713+
97714 kmem_cache_free(vm_area_cachep, vma);
97715 unacct_error:
97716 if (charged)
97717@@ -1680,7 +1856,63 @@ unacct_error:
97718 return error;
97719 }
97720
97721-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97722+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
97723+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
97724+{
97725+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
97726+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
97727+
97728+ return 0;
97729+}
97730+#endif
97731+
97732+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
97733+{
97734+ if (!vma) {
97735+#ifdef CONFIG_STACK_GROWSUP
97736+ if (addr > sysctl_heap_stack_gap)
97737+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
97738+ else
97739+ vma = find_vma(current->mm, 0);
97740+ if (vma && (vma->vm_flags & VM_GROWSUP))
97741+ return false;
97742+#endif
97743+ return true;
97744+ }
97745+
97746+ if (addr + len > vma->vm_start)
97747+ return false;
97748+
97749+ if (vma->vm_flags & VM_GROWSDOWN)
97750+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
97751+#ifdef CONFIG_STACK_GROWSUP
97752+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
97753+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
97754+#endif
97755+ else if (offset)
97756+ return offset <= vma->vm_start - addr - len;
97757+
97758+ return true;
97759+}
97760+
97761+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
97762+{
97763+ if (vma->vm_start < len)
97764+ return -ENOMEM;
97765+
97766+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
97767+ if (offset <= vma->vm_start - len)
97768+ return vma->vm_start - len - offset;
97769+ else
97770+ return -ENOMEM;
97771+ }
97772+
97773+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
97774+ return vma->vm_start - len - sysctl_heap_stack_gap;
97775+ return -ENOMEM;
97776+}
97777+
97778+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
97779 {
97780 /*
97781 * We implement the search by looking for an rbtree node that
97782@@ -1728,11 +1960,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97783 }
97784 }
97785
97786- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
97787+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
97788 check_current:
97789 /* Check if current node has a suitable gap */
97790 if (gap_start > high_limit)
97791 return -ENOMEM;
97792+
97793+ if (gap_end - gap_start > info->threadstack_offset)
97794+ gap_start += info->threadstack_offset;
97795+ else
97796+ gap_start = gap_end;
97797+
97798+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97799+ if (gap_end - gap_start > sysctl_heap_stack_gap)
97800+ gap_start += sysctl_heap_stack_gap;
97801+ else
97802+ gap_start = gap_end;
97803+ }
97804+ if (vma->vm_flags & VM_GROWSDOWN) {
97805+ if (gap_end - gap_start > sysctl_heap_stack_gap)
97806+ gap_end -= sysctl_heap_stack_gap;
97807+ else
97808+ gap_end = gap_start;
97809+ }
97810 if (gap_end >= low_limit && gap_end - gap_start >= length)
97811 goto found;
97812
97813@@ -1782,7 +2032,7 @@ found:
97814 return gap_start;
97815 }
97816
97817-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
97818+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
97819 {
97820 struct mm_struct *mm = current->mm;
97821 struct vm_area_struct *vma;
97822@@ -1836,6 +2086,24 @@ check_current:
97823 gap_end = vma->vm_start;
97824 if (gap_end < low_limit)
97825 return -ENOMEM;
97826+
97827+ if (gap_end - gap_start > info->threadstack_offset)
97828+ gap_end -= info->threadstack_offset;
97829+ else
97830+ gap_end = gap_start;
97831+
97832+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97833+ if (gap_end - gap_start > sysctl_heap_stack_gap)
97834+ gap_start += sysctl_heap_stack_gap;
97835+ else
97836+ gap_start = gap_end;
97837+ }
97838+ if (vma->vm_flags & VM_GROWSDOWN) {
97839+ if (gap_end - gap_start > sysctl_heap_stack_gap)
97840+ gap_end -= sysctl_heap_stack_gap;
97841+ else
97842+ gap_end = gap_start;
97843+ }
97844 if (gap_start <= high_limit && gap_end - gap_start >= length)
97845 goto found;
97846
97847@@ -1899,6 +2167,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97848 struct mm_struct *mm = current->mm;
97849 struct vm_area_struct *vma;
97850 struct vm_unmapped_area_info info;
97851+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97852
97853 if (len > TASK_SIZE - mmap_min_addr)
97854 return -ENOMEM;
97855@@ -1906,11 +2175,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97856 if (flags & MAP_FIXED)
97857 return addr;
97858
97859+#ifdef CONFIG_PAX_RANDMMAP
97860+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97861+#endif
97862+
97863 if (addr) {
97864 addr = PAGE_ALIGN(addr);
97865 vma = find_vma(mm, addr);
97866 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97867- (!vma || addr + len <= vma->vm_start))
97868+ check_heap_stack_gap(vma, addr, len, offset))
97869 return addr;
97870 }
97871
97872@@ -1919,6 +2192,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97873 info.low_limit = mm->mmap_base;
97874 info.high_limit = TASK_SIZE;
97875 info.align_mask = 0;
97876+ info.threadstack_offset = offset;
97877 return vm_unmapped_area(&info);
97878 }
97879 #endif
97880@@ -1937,6 +2211,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97881 struct mm_struct *mm = current->mm;
97882 unsigned long addr = addr0;
97883 struct vm_unmapped_area_info info;
97884+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97885
97886 /* requested length too big for entire address space */
97887 if (len > TASK_SIZE - mmap_min_addr)
97888@@ -1945,12 +2220,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97889 if (flags & MAP_FIXED)
97890 return addr;
97891
97892+#ifdef CONFIG_PAX_RANDMMAP
97893+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97894+#endif
97895+
97896 /* requesting a specific address */
97897 if (addr) {
97898 addr = PAGE_ALIGN(addr);
97899 vma = find_vma(mm, addr);
97900 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97901- (!vma || addr + len <= vma->vm_start))
97902+ check_heap_stack_gap(vma, addr, len, offset))
97903 return addr;
97904 }
97905
97906@@ -1959,6 +2238,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97907 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
97908 info.high_limit = mm->mmap_base;
97909 info.align_mask = 0;
97910+ info.threadstack_offset = offset;
97911 addr = vm_unmapped_area(&info);
97912
97913 /*
97914@@ -1971,6 +2251,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97915 VM_BUG_ON(addr != -ENOMEM);
97916 info.flags = 0;
97917 info.low_limit = TASK_UNMAPPED_BASE;
97918+
97919+#ifdef CONFIG_PAX_RANDMMAP
97920+ if (mm->pax_flags & MF_PAX_RANDMMAP)
97921+ info.low_limit += mm->delta_mmap;
97922+#endif
97923+
97924 info.high_limit = TASK_SIZE;
97925 addr = vm_unmapped_area(&info);
97926 }
97927@@ -2071,6 +2357,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
97928 return vma;
97929 }
97930
97931+#ifdef CONFIG_PAX_SEGMEXEC
97932+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
97933+{
97934+ struct vm_area_struct *vma_m;
97935+
97936+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
97937+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
97938+ BUG_ON(vma->vm_mirror);
97939+ return NULL;
97940+ }
97941+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
97942+ vma_m = vma->vm_mirror;
97943+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
97944+ BUG_ON(vma->vm_file != vma_m->vm_file);
97945+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
97946+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
97947+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
97948+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
97949+ return vma_m;
97950+}
97951+#endif
97952+
97953 /*
97954 * Verify that the stack growth is acceptable and
97955 * update accounting. This is shared with both the
97956@@ -2087,6 +2395,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97957 return -ENOMEM;
97958
97959 /* Stack limit test */
97960+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
97961 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
97962 return -ENOMEM;
97963
97964@@ -2097,6 +2406,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97965 locked = mm->locked_vm + grow;
97966 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
97967 limit >>= PAGE_SHIFT;
97968+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
97969 if (locked > limit && !capable(CAP_IPC_LOCK))
97970 return -ENOMEM;
97971 }
97972@@ -2126,37 +2436,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97973 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
97974 * vma is the last one with address > vma->vm_end. Have to extend vma.
97975 */
97976+#ifndef CONFIG_IA64
97977+static
97978+#endif
97979 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97980 {
97981 int error;
97982+ bool locknext;
97983
97984 if (!(vma->vm_flags & VM_GROWSUP))
97985 return -EFAULT;
97986
97987+ /* Also guard against wrapping around to address 0. */
97988+ if (address < PAGE_ALIGN(address+1))
97989+ address = PAGE_ALIGN(address+1);
97990+ else
97991+ return -ENOMEM;
97992+
97993 /*
97994 * We must make sure the anon_vma is allocated
97995 * so that the anon_vma locking is not a noop.
97996 */
97997 if (unlikely(anon_vma_prepare(vma)))
97998 return -ENOMEM;
97999+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
98000+ if (locknext && anon_vma_prepare(vma->vm_next))
98001+ return -ENOMEM;
98002 vma_lock_anon_vma(vma);
98003+ if (locknext)
98004+ vma_lock_anon_vma(vma->vm_next);
98005
98006 /*
98007 * vma->vm_start/vm_end cannot change under us because the caller
98008 * is required to hold the mmap_sem in read mode. We need the
98009- * anon_vma lock to serialize against concurrent expand_stacks.
98010- * Also guard against wrapping around to address 0.
98011+ * anon_vma locks to serialize against concurrent expand_stacks
98012+ * and expand_upwards.
98013 */
98014- if (address < PAGE_ALIGN(address+4))
98015- address = PAGE_ALIGN(address+4);
98016- else {
98017- vma_unlock_anon_vma(vma);
98018- return -ENOMEM;
98019- }
98020 error = 0;
98021
98022 /* Somebody else might have raced and expanded it already */
98023- if (address > vma->vm_end) {
98024+ 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)
98025+ error = -ENOMEM;
98026+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
98027 unsigned long size, grow;
98028
98029 size = address - vma->vm_start;
98030@@ -2191,6 +2512,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
98031 }
98032 }
98033 }
98034+ if (locknext)
98035+ vma_unlock_anon_vma(vma->vm_next);
98036 vma_unlock_anon_vma(vma);
98037 khugepaged_enter_vma_merge(vma, vma->vm_flags);
98038 validate_mm(vma->vm_mm);
98039@@ -2205,6 +2528,8 @@ int expand_downwards(struct vm_area_struct *vma,
98040 unsigned long address)
98041 {
98042 int error;
98043+ bool lockprev = false;
98044+ struct vm_area_struct *prev;
98045
98046 /*
98047 * We must make sure the anon_vma is allocated
98048@@ -2218,6 +2543,15 @@ int expand_downwards(struct vm_area_struct *vma,
98049 if (error)
98050 return error;
98051
98052+ prev = vma->vm_prev;
98053+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
98054+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
98055+#endif
98056+ if (lockprev && anon_vma_prepare(prev))
98057+ return -ENOMEM;
98058+ if (lockprev)
98059+ vma_lock_anon_vma(prev);
98060+
98061 vma_lock_anon_vma(vma);
98062
98063 /*
98064@@ -2227,9 +2561,17 @@ int expand_downwards(struct vm_area_struct *vma,
98065 */
98066
98067 /* Somebody else might have raced and expanded it already */
98068- if (address < vma->vm_start) {
98069+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
98070+ error = -ENOMEM;
98071+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
98072 unsigned long size, grow;
98073
98074+#ifdef CONFIG_PAX_SEGMEXEC
98075+ struct vm_area_struct *vma_m;
98076+
98077+ vma_m = pax_find_mirror_vma(vma);
98078+#endif
98079+
98080 size = vma->vm_end - address;
98081 grow = (vma->vm_start - address) >> PAGE_SHIFT;
98082
98083@@ -2254,13 +2596,27 @@ int expand_downwards(struct vm_area_struct *vma,
98084 vma->vm_pgoff -= grow;
98085 anon_vma_interval_tree_post_update_vma(vma);
98086 vma_gap_update(vma);
98087+
98088+#ifdef CONFIG_PAX_SEGMEXEC
98089+ if (vma_m) {
98090+ anon_vma_interval_tree_pre_update_vma(vma_m);
98091+ vma_m->vm_start -= grow << PAGE_SHIFT;
98092+ vma_m->vm_pgoff -= grow;
98093+ anon_vma_interval_tree_post_update_vma(vma_m);
98094+ vma_gap_update(vma_m);
98095+ }
98096+#endif
98097+
98098 spin_unlock(&vma->vm_mm->page_table_lock);
98099
98100+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
98101 perf_event_mmap(vma);
98102 }
98103 }
98104 }
98105 vma_unlock_anon_vma(vma);
98106+ if (lockprev)
98107+ vma_unlock_anon_vma(prev);
98108 khugepaged_enter_vma_merge(vma, vma->vm_flags);
98109 validate_mm(vma->vm_mm);
98110 return error;
98111@@ -2358,6 +2714,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
98112 do {
98113 long nrpages = vma_pages(vma);
98114
98115+#ifdef CONFIG_PAX_SEGMEXEC
98116+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
98117+ vma = remove_vma(vma);
98118+ continue;
98119+ }
98120+#endif
98121+
98122 if (vma->vm_flags & VM_ACCOUNT)
98123 nr_accounted += nrpages;
98124 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
98125@@ -2402,6 +2765,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
98126 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
98127 vma->vm_prev = NULL;
98128 do {
98129+
98130+#ifdef CONFIG_PAX_SEGMEXEC
98131+ if (vma->vm_mirror) {
98132+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
98133+ vma->vm_mirror->vm_mirror = NULL;
98134+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
98135+ vma->vm_mirror = NULL;
98136+ }
98137+#endif
98138+
98139 vma_rb_erase(vma, &mm->mm_rb);
98140 mm->map_count--;
98141 tail_vma = vma;
98142@@ -2429,14 +2802,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
98143 struct vm_area_struct *new;
98144 int err = -ENOMEM;
98145
98146+#ifdef CONFIG_PAX_SEGMEXEC
98147+ struct vm_area_struct *vma_m, *new_m = NULL;
98148+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
98149+#endif
98150+
98151 if (is_vm_hugetlb_page(vma) && (addr &
98152 ~(huge_page_mask(hstate_vma(vma)))))
98153 return -EINVAL;
98154
98155+#ifdef CONFIG_PAX_SEGMEXEC
98156+ vma_m = pax_find_mirror_vma(vma);
98157+#endif
98158+
98159 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
98160 if (!new)
98161 goto out_err;
98162
98163+#ifdef CONFIG_PAX_SEGMEXEC
98164+ if (vma_m) {
98165+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
98166+ if (!new_m) {
98167+ kmem_cache_free(vm_area_cachep, new);
98168+ goto out_err;
98169+ }
98170+ }
98171+#endif
98172+
98173 /* most fields are the same, copy all, and then fixup */
98174 *new = *vma;
98175
98176@@ -2449,11 +2841,28 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
98177 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
98178 }
98179
98180+#ifdef CONFIG_PAX_SEGMEXEC
98181+ if (vma_m) {
98182+ *new_m = *vma_m;
98183+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
98184+ new_m->vm_mirror = new;
98185+ new->vm_mirror = new_m;
98186+
98187+ if (new_below)
98188+ new_m->vm_end = addr_m;
98189+ else {
98190+ new_m->vm_start = addr_m;
98191+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
98192+ }
98193+ }
98194+#endif
98195+
98196 err = vma_dup_policy(vma, new);
98197 if (err)
98198 goto out_free_vma;
98199
98200- if (anon_vma_clone(new, vma))
98201+ err = anon_vma_clone(new, vma);
98202+ if (err)
98203 goto out_free_mpol;
98204
98205 if (new->vm_file)
98206@@ -2468,6 +2877,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
98207 else
98208 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
98209
98210+#ifdef CONFIG_PAX_SEGMEXEC
98211+ if (!err && vma_m) {
98212+ struct mempolicy *pol = vma_policy(new);
98213+
98214+ if (anon_vma_clone(new_m, vma_m))
98215+ goto out_free_mpol;
98216+
98217+ mpol_get(pol);
98218+ set_vma_policy(new_m, pol);
98219+
98220+ if (new_m->vm_file)
98221+ get_file(new_m->vm_file);
98222+
98223+ if (new_m->vm_ops && new_m->vm_ops->open)
98224+ new_m->vm_ops->open(new_m);
98225+
98226+ if (new_below)
98227+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
98228+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
98229+ else
98230+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
98231+
98232+ if (err) {
98233+ if (new_m->vm_ops && new_m->vm_ops->close)
98234+ new_m->vm_ops->close(new_m);
98235+ if (new_m->vm_file)
98236+ fput(new_m->vm_file);
98237+ mpol_put(pol);
98238+ }
98239+ }
98240+#endif
98241+
98242 /* Success. */
98243 if (!err)
98244 return 0;
98245@@ -2477,10 +2918,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
98246 new->vm_ops->close(new);
98247 if (new->vm_file)
98248 fput(new->vm_file);
98249- unlink_anon_vmas(new);
98250 out_free_mpol:
98251 mpol_put(vma_policy(new));
98252 out_free_vma:
98253+
98254+#ifdef CONFIG_PAX_SEGMEXEC
98255+ if (new_m) {
98256+ unlink_anon_vmas(new_m);
98257+ kmem_cache_free(vm_area_cachep, new_m);
98258+ }
98259+#endif
98260+
98261+ unlink_anon_vmas(new);
98262 kmem_cache_free(vm_area_cachep, new);
98263 out_err:
98264 return err;
98265@@ -2493,6 +2942,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
98266 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98267 unsigned long addr, int new_below)
98268 {
98269+
98270+#ifdef CONFIG_PAX_SEGMEXEC
98271+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
98272+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
98273+ if (mm->map_count >= sysctl_max_map_count-1)
98274+ return -ENOMEM;
98275+ } else
98276+#endif
98277+
98278 if (mm->map_count >= sysctl_max_map_count)
98279 return -ENOMEM;
98280
98281@@ -2504,11 +2962,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98282 * work. This now handles partial unmappings.
98283 * Jeremy Fitzhardinge <jeremy@goop.org>
98284 */
98285+#ifdef CONFIG_PAX_SEGMEXEC
98286 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
98287 {
98288+ int ret = __do_munmap(mm, start, len);
98289+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
98290+ return ret;
98291+
98292+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
98293+}
98294+
98295+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
98296+#else
98297+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
98298+#endif
98299+{
98300 unsigned long end;
98301 struct vm_area_struct *vma, *prev, *last;
98302
98303+ /*
98304+ * mm->mmap_sem is required to protect against another thread
98305+ * changing the mappings in case we sleep.
98306+ */
98307+ verify_mm_writelocked(mm);
98308+
98309 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
98310 return -EINVAL;
98311
98312@@ -2583,6 +3060,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
98313 /* Fix up all other VM information */
98314 remove_vma_list(mm, vma);
98315
98316+ track_exec_limit(mm, start, end, 0UL);
98317+
98318 return 0;
98319 }
98320
98321@@ -2591,6 +3070,13 @@ int vm_munmap(unsigned long start, size_t len)
98322 int ret;
98323 struct mm_struct *mm = current->mm;
98324
98325+
98326+#ifdef CONFIG_PAX_SEGMEXEC
98327+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
98328+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
98329+ return -EINVAL;
98330+#endif
98331+
98332 down_write(&mm->mmap_sem);
98333 ret = do_munmap(mm, start, len);
98334 up_write(&mm->mmap_sem);
98335@@ -2604,16 +3090,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
98336 return vm_munmap(addr, len);
98337 }
98338
98339-static inline void verify_mm_writelocked(struct mm_struct *mm)
98340-{
98341-#ifdef CONFIG_DEBUG_VM
98342- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
98343- WARN_ON(1);
98344- up_read(&mm->mmap_sem);
98345- }
98346-#endif
98347-}
98348-
98349 /*
98350 * this is really a simplified "do_mmap". it only handles
98351 * anonymous maps. eventually we may be able to do some
98352@@ -2627,6 +3103,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98353 struct rb_node ** rb_link, * rb_parent;
98354 pgoff_t pgoff = addr >> PAGE_SHIFT;
98355 int error;
98356+ unsigned long charged;
98357
98358 len = PAGE_ALIGN(len);
98359 if (!len)
98360@@ -2634,10 +3111,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98361
98362 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
98363
98364+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
98365+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
98366+ flags &= ~VM_EXEC;
98367+
98368+#ifdef CONFIG_PAX_MPROTECT
98369+ if (mm->pax_flags & MF_PAX_MPROTECT)
98370+ flags &= ~VM_MAYEXEC;
98371+#endif
98372+
98373+ }
98374+#endif
98375+
98376 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
98377 if (error & ~PAGE_MASK)
98378 return error;
98379
98380+ charged = len >> PAGE_SHIFT;
98381+
98382 error = mlock_future_check(mm, mm->def_flags, len);
98383 if (error)
98384 return error;
98385@@ -2651,21 +3142,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98386 /*
98387 * Clear old maps. this also does some error checking for us
98388 */
98389- munmap_back:
98390 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
98391 if (do_munmap(mm, addr, len))
98392 return -ENOMEM;
98393- goto munmap_back;
98394+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
98395 }
98396
98397 /* Check against address space limits *after* clearing old maps... */
98398- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
98399+ if (!may_expand_vm(mm, charged))
98400 return -ENOMEM;
98401
98402 if (mm->map_count > sysctl_max_map_count)
98403 return -ENOMEM;
98404
98405- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
98406+ if (security_vm_enough_memory_mm(mm, charged))
98407 return -ENOMEM;
98408
98409 /* Can we just expand an old private anonymous mapping? */
98410@@ -2679,7 +3169,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98411 */
98412 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98413 if (!vma) {
98414- vm_unacct_memory(len >> PAGE_SHIFT);
98415+ vm_unacct_memory(charged);
98416 return -ENOMEM;
98417 }
98418
98419@@ -2693,10 +3183,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98420 vma_link(mm, vma, prev, rb_link, rb_parent);
98421 out:
98422 perf_event_mmap(vma);
98423- mm->total_vm += len >> PAGE_SHIFT;
98424+ mm->total_vm += charged;
98425 if (flags & VM_LOCKED)
98426- mm->locked_vm += (len >> PAGE_SHIFT);
98427+ mm->locked_vm += charged;
98428 vma->vm_flags |= VM_SOFTDIRTY;
98429+ track_exec_limit(mm, addr, addr + len, flags);
98430 return addr;
98431 }
98432
98433@@ -2758,6 +3249,7 @@ void exit_mmap(struct mm_struct *mm)
98434 while (vma) {
98435 if (vma->vm_flags & VM_ACCOUNT)
98436 nr_accounted += vma_pages(vma);
98437+ vma->vm_mirror = NULL;
98438 vma = remove_vma(vma);
98439 }
98440 vm_unacct_memory(nr_accounted);
98441@@ -2775,6 +3267,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
98442 struct vm_area_struct *prev;
98443 struct rb_node **rb_link, *rb_parent;
98444
98445+#ifdef CONFIG_PAX_SEGMEXEC
98446+ struct vm_area_struct *vma_m = NULL;
98447+#endif
98448+
98449+ if (security_mmap_addr(vma->vm_start))
98450+ return -EPERM;
98451+
98452 /*
98453 * The vm_pgoff of a purely anonymous vma should be irrelevant
98454 * until its first write fault, when page's anon_vma and index
98455@@ -2798,7 +3297,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
98456 security_vm_enough_memory_mm(mm, vma_pages(vma)))
98457 return -ENOMEM;
98458
98459+#ifdef CONFIG_PAX_SEGMEXEC
98460+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
98461+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98462+ if (!vma_m)
98463+ return -ENOMEM;
98464+ }
98465+#endif
98466+
98467 vma_link(mm, vma, prev, rb_link, rb_parent);
98468+
98469+#ifdef CONFIG_PAX_SEGMEXEC
98470+ if (vma_m)
98471+ BUG_ON(pax_mirror_vma(vma_m, vma));
98472+#endif
98473+
98474 return 0;
98475 }
98476
98477@@ -2817,6 +3330,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
98478 struct rb_node **rb_link, *rb_parent;
98479 bool faulted_in_anon_vma = true;
98480
98481+ BUG_ON(vma->vm_mirror);
98482+
98483 /*
98484 * If anonymous vma has not yet been faulted, update new pgoff
98485 * to match new location, to increase its chance of merging.
98486@@ -2881,6 +3396,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
98487 return NULL;
98488 }
98489
98490+#ifdef CONFIG_PAX_SEGMEXEC
98491+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
98492+{
98493+ struct vm_area_struct *prev_m;
98494+ struct rb_node **rb_link_m, *rb_parent_m;
98495+ struct mempolicy *pol_m;
98496+
98497+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
98498+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
98499+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
98500+ *vma_m = *vma;
98501+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
98502+ if (anon_vma_clone(vma_m, vma))
98503+ return -ENOMEM;
98504+ pol_m = vma_policy(vma_m);
98505+ mpol_get(pol_m);
98506+ set_vma_policy(vma_m, pol_m);
98507+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
98508+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
98509+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
98510+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
98511+ if (vma_m->vm_file)
98512+ get_file(vma_m->vm_file);
98513+ if (vma_m->vm_ops && vma_m->vm_ops->open)
98514+ vma_m->vm_ops->open(vma_m);
98515+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
98516+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
98517+ vma_m->vm_mirror = vma;
98518+ vma->vm_mirror = vma_m;
98519+ return 0;
98520+}
98521+#endif
98522+
98523 /*
98524 * Return true if the calling process may expand its vm space by the passed
98525 * number of pages
98526@@ -2892,6 +3440,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
98527
98528 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
98529
98530+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
98531 if (cur + npages > lim)
98532 return 0;
98533 return 1;
98534@@ -2974,6 +3523,22 @@ static struct vm_area_struct *__install_special_mapping(
98535 vma->vm_start = addr;
98536 vma->vm_end = addr + len;
98537
98538+#ifdef CONFIG_PAX_MPROTECT
98539+ if (mm->pax_flags & MF_PAX_MPROTECT) {
98540+#ifndef CONFIG_PAX_MPROTECT_COMPAT
98541+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
98542+ return ERR_PTR(-EPERM);
98543+ if (!(vm_flags & VM_EXEC))
98544+ vm_flags &= ~VM_MAYEXEC;
98545+#else
98546+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
98547+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
98548+#endif
98549+ else
98550+ vm_flags &= ~VM_MAYWRITE;
98551+ }
98552+#endif
98553+
98554 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
98555 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
98556
98557diff --git a/mm/mprotect.c b/mm/mprotect.c
98558index c43d557..0b7ccd2 100644
98559--- a/mm/mprotect.c
98560+++ b/mm/mprotect.c
98561@@ -24,10 +24,18 @@
98562 #include <linux/migrate.h>
98563 #include <linux/perf_event.h>
98564 #include <linux/ksm.h>
98565+#include <linux/sched/sysctl.h>
98566+
98567+#ifdef CONFIG_PAX_MPROTECT
98568+#include <linux/elf.h>
98569+#include <linux/binfmts.h>
98570+#endif
98571+
98572 #include <asm/uaccess.h>
98573 #include <asm/pgtable.h>
98574 #include <asm/cacheflush.h>
98575 #include <asm/tlbflush.h>
98576+#include <asm/mmu_context.h>
98577
98578 #ifndef pgprot_modify
98579 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
98580@@ -256,6 +264,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
98581 return pages;
98582 }
98583
98584+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
98585+/* called while holding the mmap semaphor for writing except stack expansion */
98586+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
98587+{
98588+ unsigned long oldlimit, newlimit = 0UL;
98589+
98590+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
98591+ return;
98592+
98593+ spin_lock(&mm->page_table_lock);
98594+ oldlimit = mm->context.user_cs_limit;
98595+ if ((prot & VM_EXEC) && oldlimit < end)
98596+ /* USER_CS limit moved up */
98597+ newlimit = end;
98598+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
98599+ /* USER_CS limit moved down */
98600+ newlimit = start;
98601+
98602+ if (newlimit) {
98603+ mm->context.user_cs_limit = newlimit;
98604+
98605+#ifdef CONFIG_SMP
98606+ wmb();
98607+ cpus_clear(mm->context.cpu_user_cs_mask);
98608+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
98609+#endif
98610+
98611+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
98612+ }
98613+ spin_unlock(&mm->page_table_lock);
98614+ if (newlimit == end) {
98615+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
98616+
98617+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
98618+ if (is_vm_hugetlb_page(vma))
98619+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
98620+ else
98621+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
98622+ }
98623+}
98624+#endif
98625+
98626 int
98627 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98628 unsigned long start, unsigned long end, unsigned long newflags)
98629@@ -268,11 +318,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98630 int error;
98631 int dirty_accountable = 0;
98632
98633+#ifdef CONFIG_PAX_SEGMEXEC
98634+ struct vm_area_struct *vma_m = NULL;
98635+ unsigned long start_m, end_m;
98636+
98637+ start_m = start + SEGMEXEC_TASK_SIZE;
98638+ end_m = end + SEGMEXEC_TASK_SIZE;
98639+#endif
98640+
98641 if (newflags == oldflags) {
98642 *pprev = vma;
98643 return 0;
98644 }
98645
98646+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
98647+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
98648+
98649+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
98650+ return -ENOMEM;
98651+
98652+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
98653+ return -ENOMEM;
98654+ }
98655+
98656 /*
98657 * If we make a private mapping writable we increase our commit;
98658 * but (without finer accounting) cannot reduce our commit if we
98659@@ -289,6 +357,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98660 }
98661 }
98662
98663+#ifdef CONFIG_PAX_SEGMEXEC
98664+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
98665+ if (start != vma->vm_start) {
98666+ error = split_vma(mm, vma, start, 1);
98667+ if (error)
98668+ goto fail;
98669+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
98670+ *pprev = (*pprev)->vm_next;
98671+ }
98672+
98673+ if (end != vma->vm_end) {
98674+ error = split_vma(mm, vma, end, 0);
98675+ if (error)
98676+ goto fail;
98677+ }
98678+
98679+ if (pax_find_mirror_vma(vma)) {
98680+ error = __do_munmap(mm, start_m, end_m - start_m);
98681+ if (error)
98682+ goto fail;
98683+ } else {
98684+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98685+ if (!vma_m) {
98686+ error = -ENOMEM;
98687+ goto fail;
98688+ }
98689+ vma->vm_flags = newflags;
98690+ error = pax_mirror_vma(vma_m, vma);
98691+ if (error) {
98692+ vma->vm_flags = oldflags;
98693+ goto fail;
98694+ }
98695+ }
98696+ }
98697+#endif
98698+
98699 /*
98700 * First try to merge with previous and/or next vma.
98701 */
98702@@ -319,9 +423,21 @@ success:
98703 * vm_flags and vm_page_prot are protected by the mmap_sem
98704 * held in write mode.
98705 */
98706+
98707+#ifdef CONFIG_PAX_SEGMEXEC
98708+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
98709+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
98710+#endif
98711+
98712 vma->vm_flags = newflags;
98713+
98714+#ifdef CONFIG_PAX_MPROTECT
98715+ if (mm->binfmt && mm->binfmt->handle_mprotect)
98716+ mm->binfmt->handle_mprotect(vma, newflags);
98717+#endif
98718+
98719 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
98720- vm_get_page_prot(newflags));
98721+ vm_get_page_prot(vma->vm_flags));
98722
98723 if (vma_wants_writenotify(vma)) {
98724 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
98725@@ -360,6 +476,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98726 end = start + len;
98727 if (end <= start)
98728 return -ENOMEM;
98729+
98730+#ifdef CONFIG_PAX_SEGMEXEC
98731+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
98732+ if (end > SEGMEXEC_TASK_SIZE)
98733+ return -EINVAL;
98734+ } else
98735+#endif
98736+
98737+ if (end > TASK_SIZE)
98738+ return -EINVAL;
98739+
98740 if (!arch_validate_prot(prot))
98741 return -EINVAL;
98742
98743@@ -367,7 +494,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98744 /*
98745 * Does the application expect PROT_READ to imply PROT_EXEC:
98746 */
98747- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
98748+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
98749 prot |= PROT_EXEC;
98750
98751 vm_flags = calc_vm_prot_bits(prot);
98752@@ -399,6 +526,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98753 if (start > vma->vm_start)
98754 prev = vma;
98755
98756+#ifdef CONFIG_PAX_MPROTECT
98757+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
98758+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
98759+#endif
98760+
98761 for (nstart = start ; ; ) {
98762 unsigned long newflags;
98763
98764@@ -409,6 +541,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98765
98766 /* newflags >> 4 shift VM_MAY% in place of VM_% */
98767 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
98768+ if (prot & (PROT_WRITE | PROT_EXEC))
98769+ gr_log_rwxmprotect(vma);
98770+
98771+ error = -EACCES;
98772+ goto out;
98773+ }
98774+
98775+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
98776 error = -EACCES;
98777 goto out;
98778 }
98779@@ -423,6 +563,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98780 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
98781 if (error)
98782 goto out;
98783+
98784+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
98785+
98786 nstart = tmp;
98787
98788 if (nstart < prev->vm_end)
98789diff --git a/mm/mremap.c b/mm/mremap.c
98790index 05f1180..c3cde48 100644
98791--- a/mm/mremap.c
98792+++ b/mm/mremap.c
98793@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
98794 continue;
98795 pte = ptep_get_and_clear(mm, old_addr, old_pte);
98796 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
98797+
98798+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
98799+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
98800+ pte = pte_exprotect(pte);
98801+#endif
98802+
98803 pte = move_soft_dirty_pte(pte);
98804 set_pte_at(mm, new_addr, new_pte, pte);
98805 }
98806@@ -344,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
98807 if (is_vm_hugetlb_page(vma))
98808 goto Einval;
98809
98810+#ifdef CONFIG_PAX_SEGMEXEC
98811+ if (pax_find_mirror_vma(vma))
98812+ goto Einval;
98813+#endif
98814+
98815 /* We can't remap across vm area boundaries */
98816 if (old_len > vma->vm_end - addr)
98817 goto Efault;
98818@@ -399,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
98819 unsigned long ret = -EINVAL;
98820 unsigned long charged = 0;
98821 unsigned long map_flags;
98822+ unsigned long pax_task_size = TASK_SIZE;
98823
98824 if (new_addr & ~PAGE_MASK)
98825 goto out;
98826
98827- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
98828+#ifdef CONFIG_PAX_SEGMEXEC
98829+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
98830+ pax_task_size = SEGMEXEC_TASK_SIZE;
98831+#endif
98832+
98833+ pax_task_size -= PAGE_SIZE;
98834+
98835+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
98836 goto out;
98837
98838 /* Check if the location we're moving into overlaps the
98839 * old location at all, and fail if it does.
98840 */
98841- if ((new_addr <= addr) && (new_addr+new_len) > addr)
98842- goto out;
98843-
98844- if ((addr <= new_addr) && (addr+old_len) > new_addr)
98845+ if (addr + old_len > new_addr && new_addr + new_len > addr)
98846 goto out;
98847
98848 ret = do_munmap(mm, new_addr, new_len);
98849@@ -481,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98850 unsigned long ret = -EINVAL;
98851 unsigned long charged = 0;
98852 bool locked = false;
98853+ unsigned long pax_task_size = TASK_SIZE;
98854
98855 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
98856 return ret;
98857@@ -502,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98858 if (!new_len)
98859 return ret;
98860
98861+#ifdef CONFIG_PAX_SEGMEXEC
98862+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
98863+ pax_task_size = SEGMEXEC_TASK_SIZE;
98864+#endif
98865+
98866+ pax_task_size -= PAGE_SIZE;
98867+
98868+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
98869+ old_len > pax_task_size || addr > pax_task_size-old_len)
98870+ return ret;
98871+
98872 down_write(&current->mm->mmap_sem);
98873
98874 if (flags & MREMAP_FIXED) {
98875@@ -552,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98876 new_addr = addr;
98877 }
98878 ret = addr;
98879+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
98880 goto out;
98881 }
98882 }
98883@@ -575,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98884 goto out;
98885 }
98886
98887+ map_flags = vma->vm_flags;
98888 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
98889+ if (!(ret & ~PAGE_MASK)) {
98890+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
98891+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
98892+ }
98893 }
98894 out:
98895 if (ret & ~PAGE_MASK)
98896diff --git a/mm/nommu.c b/mm/nommu.c
98897index a881d96..e5932cd 100644
98898--- a/mm/nommu.c
98899+++ b/mm/nommu.c
98900@@ -70,7 +70,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
98901 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
98902 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
98903 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
98904-int heap_stack_gap = 0;
98905
98906 atomic_long_t mmap_pages_allocated;
98907
98908@@ -857,15 +856,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
98909 EXPORT_SYMBOL(find_vma);
98910
98911 /*
98912- * find a VMA
98913- * - we don't extend stack VMAs under NOMMU conditions
98914- */
98915-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
98916-{
98917- return find_vma(mm, addr);
98918-}
98919-
98920-/*
98921 * expand a stack to a given address
98922 * - not supported under NOMMU conditions
98923 */
98924@@ -1572,6 +1562,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98925
98926 /* most fields are the same, copy all, and then fixup */
98927 *new = *vma;
98928+ INIT_LIST_HEAD(&new->anon_vma_chain);
98929 *region = *vma->vm_region;
98930 new->vm_region = region;
98931
98932@@ -2002,8 +1993,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
98933 }
98934 EXPORT_SYMBOL(generic_file_remap_pages);
98935
98936-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98937- unsigned long addr, void *buf, int len, int write)
98938+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98939+ unsigned long addr, void *buf, size_t len, int write)
98940 {
98941 struct vm_area_struct *vma;
98942
98943@@ -2044,8 +2035,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98944 *
98945 * The caller must hold a reference on @mm.
98946 */
98947-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98948- void *buf, int len, int write)
98949+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
98950+ void *buf, size_t len, int write)
98951 {
98952 return __access_remote_vm(NULL, mm, addr, buf, len, write);
98953 }
98954@@ -2054,7 +2045,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98955 * Access another process' address space.
98956 * - source/target buffer must be kernel space
98957 */
98958-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
98959+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
98960 {
98961 struct mm_struct *mm;
98962
98963diff --git a/mm/page-writeback.c b/mm/page-writeback.c
98964index ba5fd97..5a95869 100644
98965--- a/mm/page-writeback.c
98966+++ b/mm/page-writeback.c
98967@@ -664,7 +664,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
98968 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
98969 * - the bdi dirty thresh drops quickly due to change of JBOD workload
98970 */
98971-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
98972+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
98973 unsigned long thresh,
98974 unsigned long bg_thresh,
98975 unsigned long dirty,
98976diff --git a/mm/page_alloc.c b/mm/page_alloc.c
98977index c5fe124..2cf7f17 100644
98978--- a/mm/page_alloc.c
98979+++ b/mm/page_alloc.c
98980@@ -61,6 +61,7 @@
98981 #include <linux/page-debug-flags.h>
98982 #include <linux/hugetlb.h>
98983 #include <linux/sched/rt.h>
98984+#include <linux/random.h>
98985
98986 #include <asm/sections.h>
98987 #include <asm/tlbflush.h>
98988@@ -357,7 +358,7 @@ out:
98989 * This usage means that zero-order pages may not be compound.
98990 */
98991
98992-static void free_compound_page(struct page *page)
98993+void free_compound_page(struct page *page)
98994 {
98995 __free_pages_ok(page, compound_order(page));
98996 }
98997@@ -740,6 +741,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98998 int i;
98999 int bad = 0;
99000
99001+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99002+ unsigned long index = 1UL << order;
99003+#endif
99004+
99005 trace_mm_page_free(page, order);
99006 kmemcheck_free_shadow(page, order);
99007
99008@@ -756,6 +761,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
99009 debug_check_no_obj_freed(page_address(page),
99010 PAGE_SIZE << order);
99011 }
99012+
99013+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99014+ for (; index; --index)
99015+ sanitize_highpage(page + index - 1);
99016+#endif
99017+
99018 arch_free_page(page, order);
99019 kernel_map_pages(page, 1 << order, 0);
99020
99021@@ -779,6 +790,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
99022 local_irq_restore(flags);
99023 }
99024
99025+#ifdef CONFIG_PAX_LATENT_ENTROPY
99026+bool __meminitdata extra_latent_entropy;
99027+
99028+static int __init setup_pax_extra_latent_entropy(char *str)
99029+{
99030+ extra_latent_entropy = true;
99031+ return 0;
99032+}
99033+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
99034+
99035+volatile u64 latent_entropy __latent_entropy;
99036+EXPORT_SYMBOL(latent_entropy);
99037+#endif
99038+
99039 void __init __free_pages_bootmem(struct page *page, unsigned int order)
99040 {
99041 unsigned int nr_pages = 1 << order;
99042@@ -794,6 +819,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
99043 __ClearPageReserved(p);
99044 set_page_count(p, 0);
99045
99046+#ifdef CONFIG_PAX_LATENT_ENTROPY
99047+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
99048+ u64 hash = 0;
99049+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
99050+ const u64 *data = lowmem_page_address(page);
99051+
99052+ for (index = 0; index < end; index++)
99053+ hash ^= hash + data[index];
99054+ latent_entropy ^= hash;
99055+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
99056+ }
99057+#endif
99058+
99059 page_zone(page)->managed_pages += nr_pages;
99060 set_page_refcounted(page);
99061 __free_pages(page, order);
99062@@ -922,8 +960,10 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags)
99063 arch_alloc_page(page, order);
99064 kernel_map_pages(page, 1 << order, 1);
99065
99066+#ifndef CONFIG_PAX_MEMORY_SANITIZE
99067 if (gfp_flags & __GFP_ZERO)
99068 prep_zero_page(page, order, gfp_flags);
99069+#endif
99070
99071 if (order && (gfp_flags & __GFP_COMP))
99072 prep_compound_page(page, order);
99073@@ -1601,7 +1641,7 @@ again:
99074 }
99075
99076 __mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
99077- if (atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
99078+ if (atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
99079 !zone_is_fair_depleted(zone))
99080 zone_set_flag(zone, ZONE_FAIR_DEPLETED);
99081
99082@@ -1922,7 +1962,7 @@ static void reset_alloc_batches(struct zone *preferred_zone)
99083 do {
99084 mod_zone_page_state(zone, NR_ALLOC_BATCH,
99085 high_wmark_pages(zone) - low_wmark_pages(zone) -
99086- atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
99087+ atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
99088 zone_clear_flag(zone, ZONE_FAIR_DEPLETED);
99089 } while (zone++ != preferred_zone);
99090 }
99091@@ -5699,7 +5739,7 @@ static void __setup_per_zone_wmarks(void)
99092
99093 __mod_zone_page_state(zone, NR_ALLOC_BATCH,
99094 high_wmark_pages(zone) - low_wmark_pages(zone) -
99095- atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
99096+ atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
99097
99098 setup_zone_migrate_reserve(zone);
99099 spin_unlock_irqrestore(&zone->lock, flags);
99100diff --git a/mm/percpu.c b/mm/percpu.c
99101index 2139e30..1d45bce 100644
99102--- a/mm/percpu.c
99103+++ b/mm/percpu.c
99104@@ -123,7 +123,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
99105 static unsigned int pcpu_high_unit_cpu __read_mostly;
99106
99107 /* the address of the first chunk which starts with the kernel static area */
99108-void *pcpu_base_addr __read_mostly;
99109+void *pcpu_base_addr __read_only;
99110 EXPORT_SYMBOL_GPL(pcpu_base_addr);
99111
99112 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
99113diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
99114index 5077afc..846c9ef 100644
99115--- a/mm/process_vm_access.c
99116+++ b/mm/process_vm_access.c
99117@@ -13,6 +13,7 @@
99118 #include <linux/uio.h>
99119 #include <linux/sched.h>
99120 #include <linux/highmem.h>
99121+#include <linux/security.h>
99122 #include <linux/ptrace.h>
99123 #include <linux/slab.h>
99124 #include <linux/syscalls.h>
99125@@ -157,19 +158,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
99126 ssize_t iov_len;
99127 size_t total_len = iov_iter_count(iter);
99128
99129+ return -ENOSYS; // PaX: until properly audited
99130+
99131 /*
99132 * Work out how many pages of struct pages we're going to need
99133 * when eventually calling get_user_pages
99134 */
99135 for (i = 0; i < riovcnt; i++) {
99136 iov_len = rvec[i].iov_len;
99137- if (iov_len > 0) {
99138- nr_pages_iov = ((unsigned long)rvec[i].iov_base
99139- + iov_len)
99140- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
99141- / PAGE_SIZE + 1;
99142- nr_pages = max(nr_pages, nr_pages_iov);
99143- }
99144+ if (iov_len <= 0)
99145+ continue;
99146+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
99147+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
99148+ nr_pages = max(nr_pages, nr_pages_iov);
99149 }
99150
99151 if (nr_pages == 0)
99152@@ -197,6 +198,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
99153 goto free_proc_pages;
99154 }
99155
99156+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
99157+ rc = -EPERM;
99158+ goto put_task_struct;
99159+ }
99160+
99161 mm = mm_access(task, PTRACE_MODE_ATTACH);
99162 if (!mm || IS_ERR(mm)) {
99163 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
99164diff --git a/mm/rmap.c b/mm/rmap.c
99165index e01318d..7a532bd 100644
99166--- a/mm/rmap.c
99167+++ b/mm/rmap.c
99168@@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
99169 struct anon_vma *anon_vma = vma->anon_vma;
99170 struct anon_vma_chain *avc;
99171
99172+#ifdef CONFIG_PAX_SEGMEXEC
99173+ struct anon_vma_chain *avc_m = NULL;
99174+#endif
99175+
99176 might_sleep();
99177 if (unlikely(!anon_vma)) {
99178 struct mm_struct *mm = vma->vm_mm;
99179@@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
99180 if (!avc)
99181 goto out_enomem;
99182
99183+#ifdef CONFIG_PAX_SEGMEXEC
99184+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
99185+ if (!avc_m)
99186+ goto out_enomem_free_avc;
99187+#endif
99188+
99189 anon_vma = find_mergeable_anon_vma(vma);
99190 allocated = NULL;
99191 if (!anon_vma) {
99192@@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
99193 /* page_table_lock to protect against threads */
99194 spin_lock(&mm->page_table_lock);
99195 if (likely(!vma->anon_vma)) {
99196+
99197+#ifdef CONFIG_PAX_SEGMEXEC
99198+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
99199+
99200+ if (vma_m) {
99201+ BUG_ON(vma_m->anon_vma);
99202+ vma_m->anon_vma = anon_vma;
99203+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
99204+ avc_m = NULL;
99205+ }
99206+#endif
99207+
99208 vma->anon_vma = anon_vma;
99209 anon_vma_chain_link(vma, avc, anon_vma);
99210 allocated = NULL;
99211@@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
99212
99213 if (unlikely(allocated))
99214 put_anon_vma(allocated);
99215+
99216+#ifdef CONFIG_PAX_SEGMEXEC
99217+ if (unlikely(avc_m))
99218+ anon_vma_chain_free(avc_m);
99219+#endif
99220+
99221 if (unlikely(avc))
99222 anon_vma_chain_free(avc);
99223 }
99224 return 0;
99225
99226 out_enomem_free_avc:
99227+
99228+#ifdef CONFIG_PAX_SEGMEXEC
99229+ if (avc_m)
99230+ anon_vma_chain_free(avc_m);
99231+#endif
99232+
99233 anon_vma_chain_free(avc);
99234 out_enomem:
99235 return -ENOMEM;
99236@@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
99237 * Attach the anon_vmas from src to dst.
99238 * Returns 0 on success, -ENOMEM on failure.
99239 */
99240-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
99241+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
99242 {
99243 struct anon_vma_chain *avc, *pavc;
99244 struct anon_vma *root = NULL;
99245@@ -270,10 +304,11 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
99246 * the corresponding VMA in the parent process is attached to.
99247 * Returns 0 on success, non-zero on failure.
99248 */
99249-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
99250+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
99251 {
99252 struct anon_vma_chain *avc;
99253 struct anon_vma *anon_vma;
99254+ int error;
99255
99256 /* Don't bother if the parent process has no anon_vma here. */
99257 if (!pvma->anon_vma)
99258@@ -283,8 +318,9 @@ int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
99259 * First, attach the new VMA to the parent VMA's anon_vmas,
99260 * so rmap can find non-COWed pages in child processes.
99261 */
99262- if (anon_vma_clone(vma, pvma))
99263- return -ENOMEM;
99264+ error = anon_vma_clone(vma, pvma);
99265+ if (error)
99266+ return error;
99267
99268 /* Then add our own anon_vma. */
99269 anon_vma = anon_vma_alloc();
99270@@ -374,8 +410,10 @@ static void anon_vma_ctor(void *data)
99271 void __init anon_vma_init(void)
99272 {
99273 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
99274- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
99275- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
99276+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
99277+ anon_vma_ctor);
99278+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
99279+ SLAB_PANIC|SLAB_NO_SANITIZE);
99280 }
99281
99282 /*
99283diff --git a/mm/shmem.c b/mm/shmem.c
99284index 469f90d..34a09ee 100644
99285--- a/mm/shmem.c
99286+++ b/mm/shmem.c
99287@@ -33,7 +33,7 @@
99288 #include <linux/swap.h>
99289 #include <linux/aio.h>
99290
99291-static struct vfsmount *shm_mnt;
99292+struct vfsmount *shm_mnt;
99293
99294 #ifdef CONFIG_SHMEM
99295 /*
99296@@ -80,7 +80,7 @@ static struct vfsmount *shm_mnt;
99297 #define BOGO_DIRENT_SIZE 20
99298
99299 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
99300-#define SHORT_SYMLINK_LEN 128
99301+#define SHORT_SYMLINK_LEN 64
99302
99303 /*
99304 * shmem_fallocate communicates with shmem_fault or shmem_writepage via
99305@@ -2524,6 +2524,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
99306 static int shmem_xattr_validate(const char *name)
99307 {
99308 struct { const char *prefix; size_t len; } arr[] = {
99309+
99310+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
99311+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
99312+#endif
99313+
99314 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
99315 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
99316 };
99317@@ -2579,6 +2584,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
99318 if (err)
99319 return err;
99320
99321+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
99322+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
99323+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
99324+ return -EOPNOTSUPP;
99325+ if (size > 8)
99326+ return -EINVAL;
99327+ }
99328+#endif
99329+
99330 return simple_xattr_set(&info->xattrs, name, value, size, flags);
99331 }
99332
99333@@ -2962,8 +2976,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
99334 int err = -ENOMEM;
99335
99336 /* Round up to L1_CACHE_BYTES to resist false sharing */
99337- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
99338- L1_CACHE_BYTES), GFP_KERNEL);
99339+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
99340 if (!sbinfo)
99341 return -ENOMEM;
99342
99343diff --git a/mm/slab.c b/mm/slab.c
99344index 7c52b38..3ccc17e 100644
99345--- a/mm/slab.c
99346+++ b/mm/slab.c
99347@@ -316,10 +316,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
99348 if ((x)->max_freeable < i) \
99349 (x)->max_freeable = i; \
99350 } while (0)
99351-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
99352-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
99353-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
99354-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
99355+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
99356+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
99357+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
99358+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
99359+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
99360+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
99361 #else
99362 #define STATS_INC_ACTIVE(x) do { } while (0)
99363 #define STATS_DEC_ACTIVE(x) do { } while (0)
99364@@ -336,6 +338,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
99365 #define STATS_INC_ALLOCMISS(x) do { } while (0)
99366 #define STATS_INC_FREEHIT(x) do { } while (0)
99367 #define STATS_INC_FREEMISS(x) do { } while (0)
99368+#define STATS_INC_SANITIZED(x) do { } while (0)
99369+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
99370 #endif
99371
99372 #if DEBUG
99373@@ -452,7 +456,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
99374 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
99375 */
99376 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
99377- const struct page *page, void *obj)
99378+ const struct page *page, const void *obj)
99379 {
99380 u32 offset = (obj - page->s_mem);
99381 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
99382@@ -1462,12 +1466,12 @@ void __init kmem_cache_init(void)
99383 */
99384
99385 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
99386- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
99387+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
99388
99389 if (INDEX_AC != INDEX_NODE)
99390 kmalloc_caches[INDEX_NODE] =
99391 create_kmalloc_cache("kmalloc-node",
99392- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
99393+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
99394
99395 slab_early_init = 0;
99396
99397@@ -3384,6 +3388,20 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
99398 struct array_cache *ac = cpu_cache_get(cachep);
99399
99400 check_irq_off();
99401+
99402+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99403+ if (cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))
99404+ STATS_INC_NOT_SANITIZED(cachep);
99405+ else {
99406+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
99407+
99408+ if (cachep->ctor)
99409+ cachep->ctor(objp);
99410+
99411+ STATS_INC_SANITIZED(cachep);
99412+ }
99413+#endif
99414+
99415 kmemleak_free_recursive(objp, cachep->flags);
99416 objp = cache_free_debugcheck(cachep, objp, caller);
99417
99418@@ -3607,6 +3625,7 @@ void kfree(const void *objp)
99419
99420 if (unlikely(ZERO_OR_NULL_PTR(objp)))
99421 return;
99422+ VM_BUG_ON(!virt_addr_valid(objp));
99423 local_irq_save(flags);
99424 kfree_debugcheck(objp);
99425 c = virt_to_cache(objp);
99426@@ -4056,14 +4075,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
99427 }
99428 /* cpu stats */
99429 {
99430- unsigned long allochit = atomic_read(&cachep->allochit);
99431- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
99432- unsigned long freehit = atomic_read(&cachep->freehit);
99433- unsigned long freemiss = atomic_read(&cachep->freemiss);
99434+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
99435+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
99436+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
99437+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
99438
99439 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
99440 allochit, allocmiss, freehit, freemiss);
99441 }
99442+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99443+ {
99444+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
99445+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
99446+
99447+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
99448+ }
99449+#endif
99450 #endif
99451 }
99452
99453@@ -4281,13 +4308,69 @@ static const struct file_operations proc_slabstats_operations = {
99454 static int __init slab_proc_init(void)
99455 {
99456 #ifdef CONFIG_DEBUG_SLAB_LEAK
99457- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
99458+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
99459 #endif
99460 return 0;
99461 }
99462 module_init(slab_proc_init);
99463 #endif
99464
99465+bool is_usercopy_object(const void *ptr)
99466+{
99467+ struct page *page;
99468+ struct kmem_cache *cachep;
99469+
99470+ if (ZERO_OR_NULL_PTR(ptr))
99471+ return false;
99472+
99473+ if (!slab_is_available())
99474+ return false;
99475+
99476+ if (!virt_addr_valid(ptr))
99477+ return false;
99478+
99479+ page = virt_to_head_page(ptr);
99480+
99481+ if (!PageSlab(page))
99482+ return false;
99483+
99484+ cachep = page->slab_cache;
99485+ return cachep->flags & SLAB_USERCOPY;
99486+}
99487+
99488+#ifdef CONFIG_PAX_USERCOPY
99489+const char *check_heap_object(const void *ptr, unsigned long n)
99490+{
99491+ struct page *page;
99492+ struct kmem_cache *cachep;
99493+ unsigned int objnr;
99494+ unsigned long offset;
99495+
99496+ if (ZERO_OR_NULL_PTR(ptr))
99497+ return "<null>";
99498+
99499+ if (!virt_addr_valid(ptr))
99500+ return NULL;
99501+
99502+ page = virt_to_head_page(ptr);
99503+
99504+ if (!PageSlab(page))
99505+ return NULL;
99506+
99507+ cachep = page->slab_cache;
99508+ if (!(cachep->flags & SLAB_USERCOPY))
99509+ return cachep->name;
99510+
99511+ objnr = obj_to_index(cachep, page, ptr);
99512+ BUG_ON(objnr >= cachep->num);
99513+ offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
99514+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
99515+ return NULL;
99516+
99517+ return cachep->name;
99518+}
99519+#endif
99520+
99521 /**
99522 * ksize - get the actual amount of memory allocated for a given object
99523 * @objp: Pointer to the object
99524diff --git a/mm/slab.h b/mm/slab.h
99525index 0e0fdd3..d0fd761 100644
99526--- a/mm/slab.h
99527+++ b/mm/slab.h
99528@@ -32,6 +32,20 @@ extern struct list_head slab_caches;
99529 /* The slab cache that manages slab cache information */
99530 extern struct kmem_cache *kmem_cache;
99531
99532+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99533+#ifdef CONFIG_X86_64
99534+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
99535+#else
99536+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
99537+#endif
99538+enum pax_sanitize_mode {
99539+ PAX_SANITIZE_SLAB_OFF = 0,
99540+ PAX_SANITIZE_SLAB_FAST,
99541+ PAX_SANITIZE_SLAB_FULL,
99542+};
99543+extern enum pax_sanitize_mode pax_sanitize_slab;
99544+#endif
99545+
99546 unsigned long calculate_alignment(unsigned long flags,
99547 unsigned long align, unsigned long size);
99548
99549@@ -67,7 +81,8 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99550
99551 /* Legal flag mask for kmem_cache_create(), for various configurations */
99552 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
99553- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
99554+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
99555+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
99556
99557 #if defined(CONFIG_DEBUG_SLAB)
99558 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
99559@@ -251,6 +266,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
99560 return s;
99561
99562 page = virt_to_head_page(x);
99563+
99564+ BUG_ON(!PageSlab(page));
99565+
99566 cachep = page->slab_cache;
99567 if (slab_equal_or_root(cachep, s))
99568 return cachep;
99569diff --git a/mm/slab_common.c b/mm/slab_common.c
99570index d319502..da7714e 100644
99571--- a/mm/slab_common.c
99572+++ b/mm/slab_common.c
99573@@ -25,11 +25,35 @@
99574
99575 #include "slab.h"
99576
99577-enum slab_state slab_state;
99578+enum slab_state slab_state __read_only;
99579 LIST_HEAD(slab_caches);
99580 DEFINE_MUTEX(slab_mutex);
99581 struct kmem_cache *kmem_cache;
99582
99583+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99584+enum pax_sanitize_mode pax_sanitize_slab __read_only = PAX_SANITIZE_SLAB_FAST;
99585+static int __init pax_sanitize_slab_setup(char *str)
99586+{
99587+ if (!str)
99588+ return 0;
99589+
99590+ if (!strcmp(str, "0") || !strcmp(str, "off")) {
99591+ pr_info("PaX slab sanitization: %s\n", "disabled");
99592+ pax_sanitize_slab = PAX_SANITIZE_SLAB_OFF;
99593+ } else if (!strcmp(str, "1") || !strcmp(str, "fast")) {
99594+ pr_info("PaX slab sanitization: %s\n", "fast");
99595+ pax_sanitize_slab = PAX_SANITIZE_SLAB_FAST;
99596+ } else if (!strcmp(str, "full")) {
99597+ pr_info("PaX slab sanitization: %s\n", "full");
99598+ pax_sanitize_slab = PAX_SANITIZE_SLAB_FULL;
99599+ } else
99600+ pr_err("PaX slab sanitization: unsupported option '%s'\n", str);
99601+
99602+ return 0;
99603+}
99604+early_param("pax_sanitize_slab", pax_sanitize_slab_setup);
99605+#endif
99606+
99607 #ifdef CONFIG_DEBUG_VM
99608 static int kmem_cache_sanity_check(const char *name, size_t size)
99609 {
99610@@ -160,7 +184,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
99611 if (err)
99612 goto out_free_cache;
99613
99614- s->refcount = 1;
99615+ atomic_set(&s->refcount, 1);
99616 list_add(&s->list, &slab_caches);
99617 out:
99618 if (err)
99619@@ -222,6 +246,13 @@ kmem_cache_create(const char *name, size_t size, size_t align,
99620 */
99621 flags &= CACHE_CREATE_MASK;
99622
99623+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99624+ if (pax_sanitize_slab == PAX_SANITIZE_SLAB_OFF || (flags & SLAB_DESTROY_BY_RCU))
99625+ flags |= SLAB_NO_SANITIZE;
99626+ else if (pax_sanitize_slab == PAX_SANITIZE_SLAB_FULL)
99627+ flags &= ~SLAB_NO_SANITIZE;
99628+#endif
99629+
99630 s = __kmem_cache_alias(name, size, align, flags, ctor);
99631 if (s)
99632 goto out_unlock;
99633@@ -341,8 +372,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
99634
99635 mutex_lock(&slab_mutex);
99636
99637- s->refcount--;
99638- if (s->refcount)
99639+ if (!atomic_dec_and_test(&s->refcount))
99640 goto out_unlock;
99641
99642 if (memcg_cleanup_cache_params(s) != 0)
99643@@ -362,7 +392,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
99644 rcu_barrier();
99645
99646 memcg_free_cache_params(s);
99647-#ifdef SLAB_SUPPORTS_SYSFS
99648+#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99649 sysfs_slab_remove(s);
99650 #else
99651 slab_kmem_cache_release(s);
99652@@ -418,7 +448,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
99653 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
99654 name, size, err);
99655
99656- s->refcount = -1; /* Exempt from merging for now */
99657+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
99658 }
99659
99660 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
99661@@ -431,7 +461,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
99662
99663 create_boot_cache(s, name, size, flags);
99664 list_add(&s->list, &slab_caches);
99665- s->refcount = 1;
99666+ atomic_set(&s->refcount, 1);
99667 return s;
99668 }
99669
99670@@ -443,6 +473,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
99671 EXPORT_SYMBOL(kmalloc_dma_caches);
99672 #endif
99673
99674+#ifdef CONFIG_PAX_USERCOPY_SLABS
99675+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
99676+EXPORT_SYMBOL(kmalloc_usercopy_caches);
99677+#endif
99678+
99679 /*
99680 * Conversion table for small slabs sizes / 8 to the index in the
99681 * kmalloc array. This is necessary for slabs < 192 since we have non power
99682@@ -507,6 +542,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
99683 return kmalloc_dma_caches[index];
99684
99685 #endif
99686+
99687+#ifdef CONFIG_PAX_USERCOPY_SLABS
99688+ if (unlikely((flags & GFP_USERCOPY)))
99689+ return kmalloc_usercopy_caches[index];
99690+
99691+#endif
99692+
99693 return kmalloc_caches[index];
99694 }
99695
99696@@ -563,7 +605,7 @@ void __init create_kmalloc_caches(unsigned long flags)
99697 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
99698 if (!kmalloc_caches[i]) {
99699 kmalloc_caches[i] = create_kmalloc_cache(NULL,
99700- 1 << i, flags);
99701+ 1 << i, SLAB_USERCOPY | flags);
99702 }
99703
99704 /*
99705@@ -572,10 +614,10 @@ void __init create_kmalloc_caches(unsigned long flags)
99706 * earlier power of two caches
99707 */
99708 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
99709- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
99710+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
99711
99712 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
99713- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
99714+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
99715 }
99716
99717 /* Kmalloc array is now usable */
99718@@ -608,6 +650,23 @@ void __init create_kmalloc_caches(unsigned long flags)
99719 }
99720 }
99721 #endif
99722+
99723+#ifdef CONFIG_PAX_USERCOPY_SLABS
99724+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
99725+ struct kmem_cache *s = kmalloc_caches[i];
99726+
99727+ if (s) {
99728+ int size = kmalloc_size(i);
99729+ char *n = kasprintf(GFP_NOWAIT,
99730+ "usercopy-kmalloc-%d", size);
99731+
99732+ BUG_ON(!n);
99733+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
99734+ size, SLAB_USERCOPY | flags);
99735+ }
99736+ }
99737+#endif
99738+
99739 }
99740 #endif /* !CONFIG_SLOB */
99741
99742@@ -666,6 +725,9 @@ void print_slabinfo_header(struct seq_file *m)
99743 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
99744 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
99745 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
99746+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99747+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
99748+#endif
99749 #endif
99750 seq_putc(m, '\n');
99751 }
99752diff --git a/mm/slob.c b/mm/slob.c
99753index 21980e0..975f1bf 100644
99754--- a/mm/slob.c
99755+++ b/mm/slob.c
99756@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
99757 /*
99758 * Return the size of a slob block.
99759 */
99760-static slobidx_t slob_units(slob_t *s)
99761+static slobidx_t slob_units(const slob_t *s)
99762 {
99763 if (s->units > 0)
99764 return s->units;
99765@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
99766 /*
99767 * Return the next free slob block pointer after this one.
99768 */
99769-static slob_t *slob_next(slob_t *s)
99770+static slob_t *slob_next(const slob_t *s)
99771 {
99772 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
99773 slobidx_t next;
99774@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
99775 /*
99776 * Returns true if s is the last free block in its page.
99777 */
99778-static int slob_last(slob_t *s)
99779+static int slob_last(const slob_t *s)
99780 {
99781 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
99782 }
99783
99784-static void *slob_new_pages(gfp_t gfp, int order, int node)
99785+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
99786 {
99787- void *page;
99788+ struct page *page;
99789
99790 #ifdef CONFIG_NUMA
99791 if (node != NUMA_NO_NODE)
99792@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
99793 if (!page)
99794 return NULL;
99795
99796- return page_address(page);
99797+ __SetPageSlab(page);
99798+ return page;
99799 }
99800
99801-static void slob_free_pages(void *b, int order)
99802+static void slob_free_pages(struct page *sp, int order)
99803 {
99804 if (current->reclaim_state)
99805 current->reclaim_state->reclaimed_slab += 1 << order;
99806- free_pages((unsigned long)b, order);
99807+ __ClearPageSlab(sp);
99808+ page_mapcount_reset(sp);
99809+ sp->private = 0;
99810+ __free_pages(sp, order);
99811 }
99812
99813 /*
99814@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99815
99816 /* Not enough space: must allocate a new page */
99817 if (!b) {
99818- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99819- if (!b)
99820+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99821+ if (!sp)
99822 return NULL;
99823- sp = virt_to_page(b);
99824- __SetPageSlab(sp);
99825+ b = page_address(sp);
99826
99827 spin_lock_irqsave(&slob_lock, flags);
99828 sp->units = SLOB_UNITS(PAGE_SIZE);
99829 sp->freelist = b;
99830+ sp->private = 0;
99831 INIT_LIST_HEAD(&sp->lru);
99832 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
99833 set_slob_page_free(sp, slob_list);
99834@@ -337,7 +341,7 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99835 /*
99836 * slob_free: entry point into the slob allocator.
99837 */
99838-static void slob_free(void *block, int size)
99839+static void slob_free(struct kmem_cache *c, void *block, int size)
99840 {
99841 struct page *sp;
99842 slob_t *prev, *next, *b = (slob_t *)block;
99843@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
99844 if (slob_page_free(sp))
99845 clear_slob_page_free(sp);
99846 spin_unlock_irqrestore(&slob_lock, flags);
99847- __ClearPageSlab(sp);
99848- page_mapcount_reset(sp);
99849- slob_free_pages(b, 0);
99850+ slob_free_pages(sp, 0);
99851 return;
99852 }
99853
99854+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99855+ if (pax_sanitize_slab && !(c && (c->flags & SLAB_NO_SANITIZE)))
99856+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
99857+#endif
99858+
99859 if (!slob_page_free(sp)) {
99860 /* This slob page is about to become partially free. Easy! */
99861 sp->units = units;
99862@@ -424,11 +431,10 @@ out:
99863 */
99864
99865 static __always_inline void *
99866-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99867+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
99868 {
99869- unsigned int *m;
99870- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99871- void *ret;
99872+ slob_t *m;
99873+ void *ret = NULL;
99874
99875 gfp &= gfp_allowed_mask;
99876
99877@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99878
99879 if (!m)
99880 return NULL;
99881- *m = size;
99882+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
99883+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
99884+ m[0].units = size;
99885+ m[1].units = align;
99886 ret = (void *)m + align;
99887
99888 trace_kmalloc_node(caller, ret,
99889 size, size + align, gfp, node);
99890 } else {
99891 unsigned int order = get_order(size);
99892+ struct page *page;
99893
99894 if (likely(order))
99895 gfp |= __GFP_COMP;
99896- ret = slob_new_pages(gfp, order, node);
99897+ page = slob_new_pages(gfp, order, node);
99898+ if (page) {
99899+ ret = page_address(page);
99900+ page->private = size;
99901+ }
99902
99903 trace_kmalloc_node(caller, ret,
99904 size, PAGE_SIZE << order, gfp, node);
99905 }
99906
99907- kmemleak_alloc(ret, size, 1, gfp);
99908+ return ret;
99909+}
99910+
99911+static __always_inline void *
99912+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99913+{
99914+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99915+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
99916+
99917+ if (!ZERO_OR_NULL_PTR(ret))
99918+ kmemleak_alloc(ret, size, 1, gfp);
99919 return ret;
99920 }
99921
99922@@ -493,34 +517,112 @@ void kfree(const void *block)
99923 return;
99924 kmemleak_free(block);
99925
99926+ VM_BUG_ON(!virt_addr_valid(block));
99927 sp = virt_to_page(block);
99928- if (PageSlab(sp)) {
99929+ VM_BUG_ON(!PageSlab(sp));
99930+ if (!sp->private) {
99931 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99932- unsigned int *m = (unsigned int *)(block - align);
99933- slob_free(m, *m + align);
99934- } else
99935+ slob_t *m = (slob_t *)(block - align);
99936+ slob_free(NULL, m, m[0].units + align);
99937+ } else {
99938+ __ClearPageSlab(sp);
99939+ page_mapcount_reset(sp);
99940+ sp->private = 0;
99941 __free_pages(sp, compound_order(sp));
99942+ }
99943 }
99944 EXPORT_SYMBOL(kfree);
99945
99946+bool is_usercopy_object(const void *ptr)
99947+{
99948+ if (!slab_is_available())
99949+ return false;
99950+
99951+ // PAX: TODO
99952+
99953+ return false;
99954+}
99955+
99956+#ifdef CONFIG_PAX_USERCOPY
99957+const char *check_heap_object(const void *ptr, unsigned long n)
99958+{
99959+ struct page *page;
99960+ const slob_t *free;
99961+ const void *base;
99962+ unsigned long flags;
99963+
99964+ if (ZERO_OR_NULL_PTR(ptr))
99965+ return "<null>";
99966+
99967+ if (!virt_addr_valid(ptr))
99968+ return NULL;
99969+
99970+ page = virt_to_head_page(ptr);
99971+ if (!PageSlab(page))
99972+ return NULL;
99973+
99974+ if (page->private) {
99975+ base = page;
99976+ if (base <= ptr && n <= page->private - (ptr - base))
99977+ return NULL;
99978+ return "<slob>";
99979+ }
99980+
99981+ /* some tricky double walking to find the chunk */
99982+ spin_lock_irqsave(&slob_lock, flags);
99983+ base = (void *)((unsigned long)ptr & PAGE_MASK);
99984+ free = page->freelist;
99985+
99986+ while (!slob_last(free) && (void *)free <= ptr) {
99987+ base = free + slob_units(free);
99988+ free = slob_next(free);
99989+ }
99990+
99991+ while (base < (void *)free) {
99992+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
99993+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
99994+ int offset;
99995+
99996+ if (ptr < base + align)
99997+ break;
99998+
99999+ offset = ptr - base - align;
100000+ if (offset >= m) {
100001+ base += size;
100002+ continue;
100003+ }
100004+
100005+ if (n > m - offset)
100006+ break;
100007+
100008+ spin_unlock_irqrestore(&slob_lock, flags);
100009+ return NULL;
100010+ }
100011+
100012+ spin_unlock_irqrestore(&slob_lock, flags);
100013+ return "<slob>";
100014+}
100015+#endif
100016+
100017 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
100018 size_t ksize(const void *block)
100019 {
100020 struct page *sp;
100021 int align;
100022- unsigned int *m;
100023+ slob_t *m;
100024
100025 BUG_ON(!block);
100026 if (unlikely(block == ZERO_SIZE_PTR))
100027 return 0;
100028
100029 sp = virt_to_page(block);
100030- if (unlikely(!PageSlab(sp)))
100031- return PAGE_SIZE << compound_order(sp);
100032+ VM_BUG_ON(!PageSlab(sp));
100033+ if (sp->private)
100034+ return sp->private;
100035
100036 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
100037- m = (unsigned int *)(block - align);
100038- return SLOB_UNITS(*m) * SLOB_UNIT;
100039+ m = (slob_t *)(block - align);
100040+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
100041 }
100042 EXPORT_SYMBOL(ksize);
100043
100044@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
100045
100046 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
100047 {
100048- void *b;
100049+ void *b = NULL;
100050
100051 flags &= gfp_allowed_mask;
100052
100053 lockdep_trace_alloc(flags);
100054
100055+#ifdef CONFIG_PAX_USERCOPY_SLABS
100056+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
100057+#else
100058 if (c->size < PAGE_SIZE) {
100059 b = slob_alloc(c->size, flags, c->align, node);
100060 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
100061 SLOB_UNITS(c->size) * SLOB_UNIT,
100062 flags, node);
100063 } else {
100064- b = slob_new_pages(flags, get_order(c->size), node);
100065+ struct page *sp;
100066+
100067+ sp = slob_new_pages(flags, get_order(c->size), node);
100068+ if (sp) {
100069+ b = page_address(sp);
100070+ sp->private = c->size;
100071+ }
100072 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
100073 PAGE_SIZE << get_order(c->size),
100074 flags, node);
100075 }
100076+#endif
100077
100078 if (b && c->ctor)
100079 c->ctor(b);
100080@@ -582,12 +694,16 @@ void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t gfp, int node)
100081 EXPORT_SYMBOL(kmem_cache_alloc_node);
100082 #endif
100083
100084-static void __kmem_cache_free(void *b, int size)
100085+static void __kmem_cache_free(struct kmem_cache *c, void *b, int size)
100086 {
100087- if (size < PAGE_SIZE)
100088- slob_free(b, size);
100089+ struct page *sp;
100090+
100091+ sp = virt_to_page(b);
100092+ BUG_ON(!PageSlab(sp));
100093+ if (!sp->private)
100094+ slob_free(c, b, size);
100095 else
100096- slob_free_pages(b, get_order(size));
100097+ slob_free_pages(sp, get_order(size));
100098 }
100099
100100 static void kmem_rcu_free(struct rcu_head *head)
100101@@ -595,22 +711,36 @@ static void kmem_rcu_free(struct rcu_head *head)
100102 struct slob_rcu *slob_rcu = (struct slob_rcu *)head;
100103 void *b = (void *)slob_rcu - (slob_rcu->size - sizeof(struct slob_rcu));
100104
100105- __kmem_cache_free(b, slob_rcu->size);
100106+ __kmem_cache_free(NULL, b, slob_rcu->size);
100107 }
100108
100109 void kmem_cache_free(struct kmem_cache *c, void *b)
100110 {
100111+ int size = c->size;
100112+
100113+#ifdef CONFIG_PAX_USERCOPY_SLABS
100114+ if (size + c->align < PAGE_SIZE) {
100115+ size += c->align;
100116+ b -= c->align;
100117+ }
100118+#endif
100119+
100120 kmemleak_free_recursive(b, c->flags);
100121 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
100122 struct slob_rcu *slob_rcu;
100123- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
100124- slob_rcu->size = c->size;
100125+ slob_rcu = b + (size - sizeof(struct slob_rcu));
100126+ slob_rcu->size = size;
100127 call_rcu(&slob_rcu->head, kmem_rcu_free);
100128 } else {
100129- __kmem_cache_free(b, c->size);
100130+ __kmem_cache_free(c, b, size);
100131 }
100132
100133+#ifdef CONFIG_PAX_USERCOPY_SLABS
100134+ trace_kfree(_RET_IP_, b);
100135+#else
100136 trace_kmem_cache_free(_RET_IP_, b);
100137+#endif
100138+
100139 }
100140 EXPORT_SYMBOL(kmem_cache_free);
100141
100142diff --git a/mm/slub.c b/mm/slub.c
100143index 3e8afcc..d6e2c89 100644
100144--- a/mm/slub.c
100145+++ b/mm/slub.c
100146@@ -207,7 +207,7 @@ struct track {
100147
100148 enum track_item { TRACK_ALLOC, TRACK_FREE };
100149
100150-#ifdef CONFIG_SYSFS
100151+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100152 static int sysfs_slab_add(struct kmem_cache *);
100153 static int sysfs_slab_alias(struct kmem_cache *, const char *);
100154 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
100155@@ -545,7 +545,7 @@ static void print_track(const char *s, struct track *t)
100156 if (!t->addr)
100157 return;
100158
100159- pr_err("INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
100160+ pr_err("INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
100161 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
100162 #ifdef CONFIG_STACKTRACE
100163 {
100164@@ -2643,6 +2643,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
100165
100166 slab_free_hook(s, x);
100167
100168+#ifdef CONFIG_PAX_MEMORY_SANITIZE
100169+ if (!(s->flags & SLAB_NO_SANITIZE)) {
100170+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
100171+ if (s->ctor)
100172+ s->ctor(x);
100173+ }
100174+#endif
100175+
100176 redo:
100177 /*
100178 * Determine the currently cpus per cpu slab.
100179@@ -2710,7 +2718,7 @@ static int slub_min_objects;
100180 * Merge control. If this is set then no merging of slab caches will occur.
100181 * (Could be removed. This was introduced to pacify the merge skeptics.)
100182 */
100183-static int slub_nomerge;
100184+static int slub_nomerge = 1;
100185
100186 /*
100187 * Calculate the order of allocation given an slab object size.
100188@@ -2986,6 +2994,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
100189 s->inuse = size;
100190
100191 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
100192+#ifdef CONFIG_PAX_MEMORY_SANITIZE
100193+ (!(flags & SLAB_NO_SANITIZE)) ||
100194+#endif
100195 s->ctor)) {
100196 /*
100197 * Relocate free pointer after the object if it is not
100198@@ -3313,6 +3324,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
100199 EXPORT_SYMBOL(__kmalloc_node);
100200 #endif
100201
100202+bool is_usercopy_object(const void *ptr)
100203+{
100204+ struct page *page;
100205+ struct kmem_cache *s;
100206+
100207+ if (ZERO_OR_NULL_PTR(ptr))
100208+ return false;
100209+
100210+ if (!slab_is_available())
100211+ return false;
100212+
100213+ if (!virt_addr_valid(ptr))
100214+ return false;
100215+
100216+ page = virt_to_head_page(ptr);
100217+
100218+ if (!PageSlab(page))
100219+ return false;
100220+
100221+ s = page->slab_cache;
100222+ return s->flags & SLAB_USERCOPY;
100223+}
100224+
100225+#ifdef CONFIG_PAX_USERCOPY
100226+const char *check_heap_object(const void *ptr, unsigned long n)
100227+{
100228+ struct page *page;
100229+ struct kmem_cache *s;
100230+ unsigned long offset;
100231+
100232+ if (ZERO_OR_NULL_PTR(ptr))
100233+ return "<null>";
100234+
100235+ if (!virt_addr_valid(ptr))
100236+ return NULL;
100237+
100238+ page = virt_to_head_page(ptr);
100239+
100240+ if (!PageSlab(page))
100241+ return NULL;
100242+
100243+ s = page->slab_cache;
100244+ if (!(s->flags & SLAB_USERCOPY))
100245+ return s->name;
100246+
100247+ offset = (ptr - page_address(page)) % s->size;
100248+ if (offset <= s->object_size && n <= s->object_size - offset)
100249+ return NULL;
100250+
100251+ return s->name;
100252+}
100253+#endif
100254+
100255 size_t ksize(const void *object)
100256 {
100257 struct page *page;
100258@@ -3341,6 +3405,7 @@ void kfree(const void *x)
100259 if (unlikely(ZERO_OR_NULL_PTR(x)))
100260 return;
100261
100262+ VM_BUG_ON(!virt_addr_valid(x));
100263 page = virt_to_head_page(x);
100264 if (unlikely(!PageSlab(page))) {
100265 BUG_ON(!PageCompound(page));
100266@@ -3642,7 +3707,7 @@ static int slab_unmergeable(struct kmem_cache *s)
100267 /*
100268 * We may have set a slab to be unmergeable during bootstrap.
100269 */
100270- if (s->refcount < 0)
100271+ if (atomic_read(&s->refcount) < 0)
100272 return 1;
100273
100274 return 0;
100275@@ -3699,7 +3764,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
100276 int i;
100277 struct kmem_cache *c;
100278
100279- s->refcount++;
100280+ atomic_inc(&s->refcount);
100281
100282 /*
100283 * Adjust the object sizes so that we clear
100284@@ -3718,7 +3783,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
100285 }
100286
100287 if (sysfs_slab_alias(s, name)) {
100288- s->refcount--;
100289+ atomic_dec(&s->refcount);
100290 s = NULL;
100291 }
100292 }
100293@@ -3835,7 +3900,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
100294 }
100295 #endif
100296
100297-#ifdef CONFIG_SYSFS
100298+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100299 static int count_inuse(struct page *page)
100300 {
100301 return page->inuse;
100302@@ -4116,7 +4181,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
100303 len += sprintf(buf + len, "%7ld ", l->count);
100304
100305 if (l->addr)
100306+#ifdef CONFIG_GRKERNSEC_HIDESYM
100307+ len += sprintf(buf + len, "%pS", NULL);
100308+#else
100309 len += sprintf(buf + len, "%pS", (void *)l->addr);
100310+#endif
100311 else
100312 len += sprintf(buf + len, "<not-available>");
100313
100314@@ -4218,12 +4287,12 @@ static void __init resiliency_test(void)
100315 validate_slab_cache(kmalloc_caches[9]);
100316 }
100317 #else
100318-#ifdef CONFIG_SYSFS
100319+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100320 static void resiliency_test(void) {};
100321 #endif
100322 #endif
100323
100324-#ifdef CONFIG_SYSFS
100325+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100326 enum slab_stat_type {
100327 SL_ALL, /* All slabs */
100328 SL_PARTIAL, /* Only partially allocated slabs */
100329@@ -4460,13 +4529,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
100330 {
100331 if (!s->ctor)
100332 return 0;
100333+#ifdef CONFIG_GRKERNSEC_HIDESYM
100334+ return sprintf(buf, "%pS\n", NULL);
100335+#else
100336 return sprintf(buf, "%pS\n", s->ctor);
100337+#endif
100338 }
100339 SLAB_ATTR_RO(ctor);
100340
100341 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
100342 {
100343- return sprintf(buf, "%d\n", s->refcount < 0 ? 0 : s->refcount - 1);
100344+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) < 0 ? 0 : atomic_read(&s->refcount) - 1);
100345 }
100346 SLAB_ATTR_RO(aliases);
100347
100348@@ -4554,6 +4627,22 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
100349 SLAB_ATTR_RO(cache_dma);
100350 #endif
100351
100352+#ifdef CONFIG_PAX_USERCOPY_SLABS
100353+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
100354+{
100355+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
100356+}
100357+SLAB_ATTR_RO(usercopy);
100358+#endif
100359+
100360+#ifdef CONFIG_PAX_MEMORY_SANITIZE
100361+static ssize_t sanitize_show(struct kmem_cache *s, char *buf)
100362+{
100363+ return sprintf(buf, "%d\n", !(s->flags & SLAB_NO_SANITIZE));
100364+}
100365+SLAB_ATTR_RO(sanitize);
100366+#endif
100367+
100368 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
100369 {
100370 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
100371@@ -4888,6 +4977,12 @@ static struct attribute *slab_attrs[] = {
100372 #ifdef CONFIG_ZONE_DMA
100373 &cache_dma_attr.attr,
100374 #endif
100375+#ifdef CONFIG_PAX_USERCOPY_SLABS
100376+ &usercopy_attr.attr,
100377+#endif
100378+#ifdef CONFIG_PAX_MEMORY_SANITIZE
100379+ &sanitize_attr.attr,
100380+#endif
100381 #ifdef CONFIG_NUMA
100382 &remote_node_defrag_ratio_attr.attr,
100383 #endif
100384@@ -5132,6 +5227,7 @@ static char *create_unique_id(struct kmem_cache *s)
100385 return name;
100386 }
100387
100388+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100389 static int sysfs_slab_add(struct kmem_cache *s)
100390 {
100391 int err;
100392@@ -5205,6 +5301,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
100393 kobject_del(&s->kobj);
100394 kobject_put(&s->kobj);
100395 }
100396+#endif
100397
100398 /*
100399 * Need to buffer aliases during bootup until sysfs becomes
100400@@ -5218,6 +5315,7 @@ struct saved_alias {
100401
100402 static struct saved_alias *alias_list;
100403
100404+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
100405 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
100406 {
100407 struct saved_alias *al;
100408@@ -5240,6 +5338,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
100409 alias_list = al;
100410 return 0;
100411 }
100412+#endif
100413
100414 static int __init slab_sysfs_init(void)
100415 {
100416diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
100417index 4cba9c2..b4f9fcc 100644
100418--- a/mm/sparse-vmemmap.c
100419+++ b/mm/sparse-vmemmap.c
100420@@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
100421 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
100422 if (!p)
100423 return NULL;
100424- pud_populate(&init_mm, pud, p);
100425+ pud_populate_kernel(&init_mm, pud, p);
100426 }
100427 return pud;
100428 }
100429@@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
100430 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
100431 if (!p)
100432 return NULL;
100433- pgd_populate(&init_mm, pgd, p);
100434+ pgd_populate_kernel(&init_mm, pgd, p);
100435 }
100436 return pgd;
100437 }
100438diff --git a/mm/sparse.c b/mm/sparse.c
100439index d1b48b6..6e8590e 100644
100440--- a/mm/sparse.c
100441+++ b/mm/sparse.c
100442@@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
100443
100444 for (i = 0; i < PAGES_PER_SECTION; i++) {
100445 if (PageHWPoison(&memmap[i])) {
100446- atomic_long_sub(1, &num_poisoned_pages);
100447+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
100448 ClearPageHWPoison(&memmap[i]);
100449 }
100450 }
100451diff --git a/mm/swap.c b/mm/swap.c
100452index 6b2dc38..46b79ba 100644
100453--- a/mm/swap.c
100454+++ b/mm/swap.c
100455@@ -31,6 +31,7 @@
100456 #include <linux/memcontrol.h>
100457 #include <linux/gfp.h>
100458 #include <linux/uio.h>
100459+#include <linux/hugetlb.h>
100460
100461 #include "internal.h"
100462
100463@@ -77,6 +78,8 @@ static void __put_compound_page(struct page *page)
100464
100465 __page_cache_release(page);
100466 dtor = get_compound_page_dtor(page);
100467+ if (!PageHuge(page))
100468+ BUG_ON(dtor != free_compound_page);
100469 (*dtor)(page);
100470 }
100471
100472diff --git a/mm/swapfile.c b/mm/swapfile.c
100473index 8798b2e..348f9dd 100644
100474--- a/mm/swapfile.c
100475+++ b/mm/swapfile.c
100476@@ -84,7 +84,7 @@ static DEFINE_MUTEX(swapon_mutex);
100477
100478 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
100479 /* Activity counter to indicate that a swapon or swapoff has occurred */
100480-static atomic_t proc_poll_event = ATOMIC_INIT(0);
100481+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
100482
100483 static inline unsigned char swap_count(unsigned char ent)
100484 {
100485@@ -1944,7 +1944,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
100486 spin_unlock(&swap_lock);
100487
100488 err = 0;
100489- atomic_inc(&proc_poll_event);
100490+ atomic_inc_unchecked(&proc_poll_event);
100491 wake_up_interruptible(&proc_poll_wait);
100492
100493 out_dput:
100494@@ -1961,8 +1961,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
100495
100496 poll_wait(file, &proc_poll_wait, wait);
100497
100498- if (seq->poll_event != atomic_read(&proc_poll_event)) {
100499- seq->poll_event = atomic_read(&proc_poll_event);
100500+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
100501+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
100502 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
100503 }
100504
100505@@ -2060,7 +2060,7 @@ static int swaps_open(struct inode *inode, struct file *file)
100506 return ret;
100507
100508 seq = file->private_data;
100509- seq->poll_event = atomic_read(&proc_poll_event);
100510+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
100511 return 0;
100512 }
100513
100514@@ -2520,7 +2520,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
100515 (frontswap_map) ? "FS" : "");
100516
100517 mutex_unlock(&swapon_mutex);
100518- atomic_inc(&proc_poll_event);
100519+ atomic_inc_unchecked(&proc_poll_event);
100520 wake_up_interruptible(&proc_poll_wait);
100521
100522 if (S_ISREG(inode->i_mode))
100523diff --git a/mm/util.c b/mm/util.c
100524index 093c973..b70a268 100644
100525--- a/mm/util.c
100526+++ b/mm/util.c
100527@@ -202,6 +202,12 @@ done:
100528 void arch_pick_mmap_layout(struct mm_struct *mm)
100529 {
100530 mm->mmap_base = TASK_UNMAPPED_BASE;
100531+
100532+#ifdef CONFIG_PAX_RANDMMAP
100533+ if (mm->pax_flags & MF_PAX_RANDMMAP)
100534+ mm->mmap_base += mm->delta_mmap;
100535+#endif
100536+
100537 mm->get_unmapped_area = arch_get_unmapped_area;
100538 }
100539 #endif
100540@@ -378,6 +384,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
100541 if (!mm->arg_end)
100542 goto out_mm; /* Shh! No looking before we're done */
100543
100544+ if (gr_acl_handle_procpidmem(task))
100545+ goto out_mm;
100546+
100547 len = mm->arg_end - mm->arg_start;
100548
100549 if (len > buflen)
100550diff --git a/mm/vmalloc.c b/mm/vmalloc.c
100551index 2b0aa54..b451f74 100644
100552--- a/mm/vmalloc.c
100553+++ b/mm/vmalloc.c
100554@@ -40,6 +40,21 @@ struct vfree_deferred {
100555 };
100556 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
100557
100558+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100559+struct stack_deferred_llist {
100560+ struct llist_head list;
100561+ void *stack;
100562+ void *lowmem_stack;
100563+};
100564+
100565+struct stack_deferred {
100566+ struct stack_deferred_llist list;
100567+ struct work_struct wq;
100568+};
100569+
100570+static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
100571+#endif
100572+
100573 static void __vunmap(const void *, int);
100574
100575 static void free_work(struct work_struct *w)
100576@@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
100577 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
100578 struct llist_node *llnode = llist_del_all(&p->list);
100579 while (llnode) {
100580- void *p = llnode;
100581+ void *x = llnode;
100582 llnode = llist_next(llnode);
100583- __vunmap(p, 1);
100584+ __vunmap(x, 1);
100585 }
100586 }
100587
100588+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100589+static void unmap_work(struct work_struct *w)
100590+{
100591+ struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
100592+ struct llist_node *llnode = llist_del_all(&p->list.list);
100593+ while (llnode) {
100594+ struct stack_deferred_llist *x =
100595+ llist_entry((struct llist_head *)llnode,
100596+ struct stack_deferred_llist, list);
100597+ void *stack = ACCESS_ONCE(x->stack);
100598+ void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
100599+ llnode = llist_next(llnode);
100600+ __vunmap(stack, 0);
100601+ free_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
100602+ }
100603+}
100604+#endif
100605+
100606 /*** Page table manipulation functions ***/
100607
100608 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
100609@@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
100610
100611 pte = pte_offset_kernel(pmd, addr);
100612 do {
100613- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
100614- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
100615+
100616+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100617+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
100618+ BUG_ON(!pte_exec(*pte));
100619+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
100620+ continue;
100621+ }
100622+#endif
100623+
100624+ {
100625+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
100626+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
100627+ }
100628 } while (pte++, addr += PAGE_SIZE, addr != end);
100629 }
100630
100631@@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
100632 pte = pte_alloc_kernel(pmd, addr);
100633 if (!pte)
100634 return -ENOMEM;
100635+
100636+ pax_open_kernel();
100637 do {
100638 struct page *page = pages[*nr];
100639
100640- if (WARN_ON(!pte_none(*pte)))
100641+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100642+ if (pgprot_val(prot) & _PAGE_NX)
100643+#endif
100644+
100645+ if (!pte_none(*pte)) {
100646+ pax_close_kernel();
100647+ WARN_ON(1);
100648 return -EBUSY;
100649- if (WARN_ON(!page))
100650+ }
100651+ if (!page) {
100652+ pax_close_kernel();
100653+ WARN_ON(1);
100654 return -ENOMEM;
100655+ }
100656 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
100657 (*nr)++;
100658 } while (pte++, addr += PAGE_SIZE, addr != end);
100659+ pax_close_kernel();
100660 return 0;
100661 }
100662
100663@@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
100664 pmd_t *pmd;
100665 unsigned long next;
100666
100667- pmd = pmd_alloc(&init_mm, pud, addr);
100668+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
100669 if (!pmd)
100670 return -ENOMEM;
100671 do {
100672@@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
100673 pud_t *pud;
100674 unsigned long next;
100675
100676- pud = pud_alloc(&init_mm, pgd, addr);
100677+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
100678 if (!pud)
100679 return -ENOMEM;
100680 do {
100681@@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
100682 if (addr >= MODULES_VADDR && addr < MODULES_END)
100683 return 1;
100684 #endif
100685+
100686+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100687+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
100688+ return 1;
100689+#endif
100690+
100691 return is_vmalloc_addr(x);
100692 }
100693
100694@@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
100695
100696 if (!pgd_none(*pgd)) {
100697 pud_t *pud = pud_offset(pgd, addr);
100698+#ifdef CONFIG_X86
100699+ if (!pud_large(*pud))
100700+#endif
100701 if (!pud_none(*pud)) {
100702 pmd_t *pmd = pmd_offset(pud, addr);
100703+#ifdef CONFIG_X86
100704+ if (!pmd_large(*pmd))
100705+#endif
100706 if (!pmd_none(*pmd)) {
100707 pte_t *ptep, pte;
100708
100709@@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
100710 for_each_possible_cpu(i) {
100711 struct vmap_block_queue *vbq;
100712 struct vfree_deferred *p;
100713+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100714+ struct stack_deferred *p2;
100715+#endif
100716
100717 vbq = &per_cpu(vmap_block_queue, i);
100718 spin_lock_init(&vbq->lock);
100719 INIT_LIST_HEAD(&vbq->free);
100720+
100721 p = &per_cpu(vfree_deferred, i);
100722 init_llist_head(&p->list);
100723 INIT_WORK(&p->wq, free_work);
100724+
100725+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100726+ p2 = &per_cpu(stack_deferred, i);
100727+ init_llist_head(&p2->list.list);
100728+ INIT_WORK(&p2->wq, unmap_work);
100729+#endif
100730 }
100731
100732 /* Import existing vmlist entries. */
100733@@ -1314,6 +1393,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
100734 struct vm_struct *area;
100735
100736 BUG_ON(in_interrupt());
100737+
100738+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100739+ if (flags & VM_KERNEXEC) {
100740+ if (start != VMALLOC_START || end != VMALLOC_END)
100741+ return NULL;
100742+ start = (unsigned long)MODULES_EXEC_VADDR;
100743+ end = (unsigned long)MODULES_EXEC_END;
100744+ }
100745+#endif
100746+
100747 if (flags & VM_IOREMAP)
100748 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
100749
100750@@ -1519,6 +1608,23 @@ void vunmap(const void *addr)
100751 }
100752 EXPORT_SYMBOL(vunmap);
100753
100754+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100755+void unmap_process_stacks(struct task_struct *task)
100756+{
100757+ if (unlikely(in_interrupt())) {
100758+ struct stack_deferred *p = &__get_cpu_var(stack_deferred);
100759+ struct stack_deferred_llist *list = task->stack;
100760+ list->stack = task->stack;
100761+ list->lowmem_stack = task->lowmem_stack;
100762+ if (llist_add((struct llist_node *)&list->list, &p->list.list))
100763+ schedule_work(&p->wq);
100764+ } else {
100765+ __vunmap(task->stack, 0);
100766+ free_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
100767+ }
100768+}
100769+#endif
100770+
100771 /**
100772 * vmap - map an array of pages into virtually contiguous space
100773 * @pages: array of page pointers
100774@@ -1539,6 +1645,11 @@ void *vmap(struct page **pages, unsigned int count,
100775 if (count > totalram_pages)
100776 return NULL;
100777
100778+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100779+ if (!(pgprot_val(prot) & _PAGE_NX))
100780+ flags |= VM_KERNEXEC;
100781+#endif
100782+
100783 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
100784 __builtin_return_address(0));
100785 if (!area)
100786@@ -1641,6 +1752,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
100787 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
100788 goto fail;
100789
100790+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100791+ if (!(pgprot_val(prot) & _PAGE_NX))
100792+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
100793+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
100794+ else
100795+#endif
100796+
100797 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
100798 start, end, node, gfp_mask, caller);
100799 if (!area)
100800@@ -1817,10 +1935,9 @@ EXPORT_SYMBOL(vzalloc_node);
100801 * For tight control over page level allocator and protection flags
100802 * use __vmalloc() instead.
100803 */
100804-
100805 void *vmalloc_exec(unsigned long size)
100806 {
100807- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
100808+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
100809 NUMA_NO_NODE, __builtin_return_address(0));
100810 }
100811
100812@@ -2127,6 +2244,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
100813 {
100814 struct vm_struct *area;
100815
100816+ BUG_ON(vma->vm_mirror);
100817+
100818 size = PAGE_ALIGN(size);
100819
100820 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
100821@@ -2609,7 +2728,11 @@ static int s_show(struct seq_file *m, void *p)
100822 v->addr, v->addr + v->size, v->size);
100823
100824 if (v->caller)
100825+#ifdef CONFIG_GRKERNSEC_HIDESYM
100826+ seq_printf(m, " %pK", v->caller);
100827+#else
100828 seq_printf(m, " %pS", v->caller);
100829+#endif
100830
100831 if (v->nr_pages)
100832 seq_printf(m, " pages=%d", v->nr_pages);
100833diff --git a/mm/vmpressure.c b/mm/vmpressure.c
100834index d4042e7..c5afd57 100644
100835--- a/mm/vmpressure.c
100836+++ b/mm/vmpressure.c
100837@@ -165,6 +165,7 @@ static void vmpressure_work_fn(struct work_struct *work)
100838 unsigned long scanned;
100839 unsigned long reclaimed;
100840
100841+ spin_lock(&vmpr->sr_lock);
100842 /*
100843 * Several contexts might be calling vmpressure(), so it is
100844 * possible that the work was rescheduled again before the old
100845@@ -173,11 +174,12 @@ static void vmpressure_work_fn(struct work_struct *work)
100846 * here. No need for any locks here since we don't care if
100847 * vmpr->reclaimed is in sync.
100848 */
100849- if (!vmpr->scanned)
100850+ scanned = vmpr->scanned;
100851+ if (!scanned) {
100852+ spin_unlock(&vmpr->sr_lock);
100853 return;
100854+ }
100855
100856- spin_lock(&vmpr->sr_lock);
100857- scanned = vmpr->scanned;
100858 reclaimed = vmpr->reclaimed;
100859 vmpr->scanned = 0;
100860 vmpr->reclaimed = 0;
100861diff --git a/mm/vmstat.c b/mm/vmstat.c
100862index e9ab104..de275bd 100644
100863--- a/mm/vmstat.c
100864+++ b/mm/vmstat.c
100865@@ -20,6 +20,7 @@
100866 #include <linux/writeback.h>
100867 #include <linux/compaction.h>
100868 #include <linux/mm_inline.h>
100869+#include <linux/grsecurity.h>
100870
100871 #include "internal.h"
100872
100873@@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
100874 *
100875 * vm_stat contains the global counters
100876 */
100877-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100878+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100879 EXPORT_SYMBOL(vm_stat);
100880
100881 #ifdef CONFIG_SMP
100882@@ -425,7 +426,7 @@ static inline void fold_diff(int *diff)
100883
100884 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100885 if (diff[i])
100886- atomic_long_add(diff[i], &vm_stat[i]);
100887+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
100888 }
100889
100890 /*
100891@@ -457,7 +458,7 @@ static void refresh_cpu_vm_stats(void)
100892 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
100893 if (v) {
100894
100895- atomic_long_add(v, &zone->vm_stat[i]);
100896+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100897 global_diff[i] += v;
100898 #ifdef CONFIG_NUMA
100899 /* 3 seconds idle till flush */
100900@@ -519,7 +520,7 @@ void cpu_vm_stats_fold(int cpu)
100901
100902 v = p->vm_stat_diff[i];
100903 p->vm_stat_diff[i] = 0;
100904- atomic_long_add(v, &zone->vm_stat[i]);
100905+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100906 global_diff[i] += v;
100907 }
100908 }
100909@@ -539,8 +540,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
100910 if (pset->vm_stat_diff[i]) {
100911 int v = pset->vm_stat_diff[i];
100912 pset->vm_stat_diff[i] = 0;
100913- atomic_long_add(v, &zone->vm_stat[i]);
100914- atomic_long_add(v, &vm_stat[i]);
100915+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100916+ atomic_long_add_unchecked(v, &vm_stat[i]);
100917 }
100918 }
100919 #endif
100920@@ -1163,10 +1164,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
100921 stat_items_size += sizeof(struct vm_event_state);
100922 #endif
100923
100924- v = kmalloc(stat_items_size, GFP_KERNEL);
100925+ v = kzalloc(stat_items_size, GFP_KERNEL);
100926 m->private = v;
100927 if (!v)
100928 return ERR_PTR(-ENOMEM);
100929+
100930+#ifdef CONFIG_GRKERNSEC_PROC_ADD
100931+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
100932+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
100933+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
100934+ && !in_group_p(grsec_proc_gid)
100935+#endif
100936+ )
100937+ return (unsigned long *)m->private + *pos;
100938+#endif
100939+#endif
100940+
100941 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100942 v[i] = global_page_state(i);
100943 v += NR_VM_ZONE_STAT_ITEMS;
100944@@ -1315,10 +1328,16 @@ static int __init setup_vmstat(void)
100945 cpu_notifier_register_done();
100946 #endif
100947 #ifdef CONFIG_PROC_FS
100948- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
100949- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
100950- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100951- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
100952+ {
100953+ mode_t gr_mode = S_IRUGO;
100954+#ifdef CONFIG_GRKERNSEC_PROC_ADD
100955+ gr_mode = S_IRUSR;
100956+#endif
100957+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
100958+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
100959+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100960+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
100961+ }
100962 #endif
100963 return 0;
100964 }
100965diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
100966index 64c6bed..b79a5de 100644
100967--- a/net/8021q/vlan.c
100968+++ b/net/8021q/vlan.c
100969@@ -481,7 +481,7 @@ out:
100970 return NOTIFY_DONE;
100971 }
100972
100973-static struct notifier_block vlan_notifier_block __read_mostly = {
100974+static struct notifier_block vlan_notifier_block = {
100975 .notifier_call = vlan_device_event,
100976 };
100977
100978@@ -556,8 +556,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
100979 err = -EPERM;
100980 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
100981 break;
100982- if ((args.u.name_type >= 0) &&
100983- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
100984+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
100985 struct vlan_net *vn;
100986
100987 vn = net_generic(net, vlan_net_id);
100988diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c
100989index 8ac8a5c..991defc 100644
100990--- a/net/8021q/vlan_netlink.c
100991+++ b/net/8021q/vlan_netlink.c
100992@@ -238,7 +238,7 @@ nla_put_failure:
100993 return -EMSGSIZE;
100994 }
100995
100996-struct rtnl_link_ops vlan_link_ops __read_mostly = {
100997+struct rtnl_link_ops vlan_link_ops = {
100998 .kind = "vlan",
100999 .maxtype = IFLA_VLAN_MAX,
101000 .policy = vlan_policy,
101001diff --git a/net/9p/client.c b/net/9p/client.c
101002index e86a9bea..e91f70e 100644
101003--- a/net/9p/client.c
101004+++ b/net/9p/client.c
101005@@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
101006 len - inline_len);
101007 } else {
101008 err = copy_from_user(ename + inline_len,
101009- uidata, len - inline_len);
101010+ (char __force_user *)uidata, len - inline_len);
101011 if (err) {
101012 err = -EFAULT;
101013 goto out_err;
101014@@ -1570,7 +1570,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
101015 kernel_buf = 1;
101016 indata = data;
101017 } else
101018- indata = (__force char *)udata;
101019+ indata = (__force_kernel char *)udata;
101020 /*
101021 * response header len is 11
101022 * PDU Header(7) + IO Size (4)
101023@@ -1645,7 +1645,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
101024 kernel_buf = 1;
101025 odata = data;
101026 } else
101027- odata = (char *)udata;
101028+ odata = (char __force_kernel *)udata;
101029 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
101030 P9_ZC_HDR_SZ, kernel_buf, "dqd",
101031 fid->fid, offset, rsize);
101032diff --git a/net/9p/mod.c b/net/9p/mod.c
101033index 6ab36ae..6f1841b 100644
101034--- a/net/9p/mod.c
101035+++ b/net/9p/mod.c
101036@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
101037 void v9fs_register_trans(struct p9_trans_module *m)
101038 {
101039 spin_lock(&v9fs_trans_lock);
101040- list_add_tail(&m->list, &v9fs_trans_list);
101041+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
101042 spin_unlock(&v9fs_trans_lock);
101043 }
101044 EXPORT_SYMBOL(v9fs_register_trans);
101045@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
101046 void v9fs_unregister_trans(struct p9_trans_module *m)
101047 {
101048 spin_lock(&v9fs_trans_lock);
101049- list_del_init(&m->list);
101050+ pax_list_del_init((struct list_head *)&m->list);
101051 spin_unlock(&v9fs_trans_lock);
101052 }
101053 EXPORT_SYMBOL(v9fs_unregister_trans);
101054diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
101055index 80d08f6..de63fd1 100644
101056--- a/net/9p/trans_fd.c
101057+++ b/net/9p/trans_fd.c
101058@@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
101059 oldfs = get_fs();
101060 set_fs(get_ds());
101061 /* The cast to a user pointer is valid due to the set_fs() */
101062- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
101063+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
101064 set_fs(oldfs);
101065
101066 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
101067diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
101068index af46bc4..f9adfcd 100644
101069--- a/net/appletalk/atalk_proc.c
101070+++ b/net/appletalk/atalk_proc.c
101071@@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
101072 struct proc_dir_entry *p;
101073 int rc = -ENOMEM;
101074
101075- atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
101076+ atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
101077 if (!atalk_proc_dir)
101078 goto out;
101079
101080diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
101081index 876fbe8..8bbea9f 100644
101082--- a/net/atm/atm_misc.c
101083+++ b/net/atm/atm_misc.c
101084@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
101085 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
101086 return 1;
101087 atm_return(vcc, truesize);
101088- atomic_inc(&vcc->stats->rx_drop);
101089+ atomic_inc_unchecked(&vcc->stats->rx_drop);
101090 return 0;
101091 }
101092 EXPORT_SYMBOL(atm_charge);
101093@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
101094 }
101095 }
101096 atm_return(vcc, guess);
101097- atomic_inc(&vcc->stats->rx_drop);
101098+ atomic_inc_unchecked(&vcc->stats->rx_drop);
101099 return NULL;
101100 }
101101 EXPORT_SYMBOL(atm_alloc_charge);
101102@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
101103
101104 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
101105 {
101106-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
101107+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
101108 __SONET_ITEMS
101109 #undef __HANDLE_ITEM
101110 }
101111@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
101112
101113 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
101114 {
101115-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
101116+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
101117 __SONET_ITEMS
101118 #undef __HANDLE_ITEM
101119 }
101120diff --git a/net/atm/lec.c b/net/atm/lec.c
101121index 4b98f89..5a2f6cb 100644
101122--- a/net/atm/lec.c
101123+++ b/net/atm/lec.c
101124@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
101125 }
101126
101127 static struct lane2_ops lane2_ops = {
101128- lane2_resolve, /* resolve, spec 3.1.3 */
101129- lane2_associate_req, /* associate_req, spec 3.1.4 */
101130- NULL /* associate indicator, spec 3.1.5 */
101131+ .resolve = lane2_resolve,
101132+ .associate_req = lane2_associate_req,
101133+ .associate_indicator = NULL
101134 };
101135
101136 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
101137diff --git a/net/atm/lec.h b/net/atm/lec.h
101138index 4149db1..f2ab682 100644
101139--- a/net/atm/lec.h
101140+++ b/net/atm/lec.h
101141@@ -48,7 +48,7 @@ struct lane2_ops {
101142 const u8 *tlvs, u32 sizeoftlvs);
101143 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
101144 const u8 *tlvs, u32 sizeoftlvs);
101145-};
101146+} __no_const;
101147
101148 /*
101149 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
101150diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
101151index d1b2d9a..d549f7f 100644
101152--- a/net/atm/mpoa_caches.c
101153+++ b/net/atm/mpoa_caches.c
101154@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
101155
101156
101157 static struct in_cache_ops ingress_ops = {
101158- in_cache_add_entry, /* add_entry */
101159- in_cache_get, /* get */
101160- in_cache_get_with_mask, /* get_with_mask */
101161- in_cache_get_by_vcc, /* get_by_vcc */
101162- in_cache_put, /* put */
101163- in_cache_remove_entry, /* remove_entry */
101164- cache_hit, /* cache_hit */
101165- clear_count_and_expired, /* clear_count */
101166- check_resolving_entries, /* check_resolving */
101167- refresh_entries, /* refresh */
101168- in_destroy_cache /* destroy_cache */
101169+ .add_entry = in_cache_add_entry,
101170+ .get = in_cache_get,
101171+ .get_with_mask = in_cache_get_with_mask,
101172+ .get_by_vcc = in_cache_get_by_vcc,
101173+ .put = in_cache_put,
101174+ .remove_entry = in_cache_remove_entry,
101175+ .cache_hit = cache_hit,
101176+ .clear_count = clear_count_and_expired,
101177+ .check_resolving = check_resolving_entries,
101178+ .refresh = refresh_entries,
101179+ .destroy_cache = in_destroy_cache
101180 };
101181
101182 static struct eg_cache_ops egress_ops = {
101183- eg_cache_add_entry, /* add_entry */
101184- eg_cache_get_by_cache_id, /* get_by_cache_id */
101185- eg_cache_get_by_tag, /* get_by_tag */
101186- eg_cache_get_by_vcc, /* get_by_vcc */
101187- eg_cache_get_by_src_ip, /* get_by_src_ip */
101188- eg_cache_put, /* put */
101189- eg_cache_remove_entry, /* remove_entry */
101190- update_eg_cache_entry, /* update */
101191- clear_expired, /* clear_expired */
101192- eg_destroy_cache /* destroy_cache */
101193+ .add_entry = eg_cache_add_entry,
101194+ .get_by_cache_id = eg_cache_get_by_cache_id,
101195+ .get_by_tag = eg_cache_get_by_tag,
101196+ .get_by_vcc = eg_cache_get_by_vcc,
101197+ .get_by_src_ip = eg_cache_get_by_src_ip,
101198+ .put = eg_cache_put,
101199+ .remove_entry = eg_cache_remove_entry,
101200+ .update = update_eg_cache_entry,
101201+ .clear_expired = clear_expired,
101202+ .destroy_cache = eg_destroy_cache
101203 };
101204
101205
101206diff --git a/net/atm/proc.c b/net/atm/proc.c
101207index bbb6461..cf04016 100644
101208--- a/net/atm/proc.c
101209+++ b/net/atm/proc.c
101210@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
101211 const struct k_atm_aal_stats *stats)
101212 {
101213 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
101214- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
101215- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
101216- atomic_read(&stats->rx_drop));
101217+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
101218+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
101219+ atomic_read_unchecked(&stats->rx_drop));
101220 }
101221
101222 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
101223diff --git a/net/atm/resources.c b/net/atm/resources.c
101224index 0447d5d..3cf4728 100644
101225--- a/net/atm/resources.c
101226+++ b/net/atm/resources.c
101227@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
101228 static void copy_aal_stats(struct k_atm_aal_stats *from,
101229 struct atm_aal_stats *to)
101230 {
101231-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
101232+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
101233 __AAL_STAT_ITEMS
101234 #undef __HANDLE_ITEM
101235 }
101236@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
101237 static void subtract_aal_stats(struct k_atm_aal_stats *from,
101238 struct atm_aal_stats *to)
101239 {
101240-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
101241+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
101242 __AAL_STAT_ITEMS
101243 #undef __HANDLE_ITEM
101244 }
101245diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
101246index 919a5ce..cc6b444 100644
101247--- a/net/ax25/sysctl_net_ax25.c
101248+++ b/net/ax25/sysctl_net_ax25.c
101249@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
101250 {
101251 char path[sizeof("net/ax25/") + IFNAMSIZ];
101252 int k;
101253- struct ctl_table *table;
101254+ ctl_table_no_const *table;
101255
101256 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
101257 if (!table)
101258diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
101259index 1e80539..676c37a 100644
101260--- a/net/batman-adv/bat_iv_ogm.c
101261+++ b/net/batman-adv/bat_iv_ogm.c
101262@@ -313,7 +313,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
101263
101264 /* randomize initial seqno to avoid collision */
101265 get_random_bytes(&random_seqno, sizeof(random_seqno));
101266- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
101267+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
101268
101269 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
101270 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
101271@@ -918,9 +918,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
101272 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
101273
101274 /* change sequence number to network order */
101275- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
101276+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
101277 batadv_ogm_packet->seqno = htonl(seqno);
101278- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
101279+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
101280
101281 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
101282
101283@@ -1597,7 +1597,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
101284 return;
101285
101286 /* could be changed by schedule_own_packet() */
101287- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
101288+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
101289
101290 if (ogm_packet->flags & BATADV_DIRECTLINK)
101291 has_directlink_flag = true;
101292diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
101293index fc1835c..eead856 100644
101294--- a/net/batman-adv/fragmentation.c
101295+++ b/net/batman-adv/fragmentation.c
101296@@ -450,7 +450,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
101297 frag_header.packet_type = BATADV_UNICAST_FRAG;
101298 frag_header.version = BATADV_COMPAT_VERSION;
101299 frag_header.ttl = BATADV_TTL;
101300- frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
101301+ frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
101302 frag_header.reserved = 0;
101303 frag_header.no = 0;
101304 frag_header.total_size = htons(skb->len);
101305diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
101306index 5467955..75ad4e3 100644
101307--- a/net/batman-adv/soft-interface.c
101308+++ b/net/batman-adv/soft-interface.c
101309@@ -296,7 +296,7 @@ send:
101310 primary_if->net_dev->dev_addr);
101311
101312 /* set broadcast sequence number */
101313- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
101314+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
101315 bcast_packet->seqno = htonl(seqno);
101316
101317 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
101318@@ -761,7 +761,7 @@ static int batadv_softif_init_late(struct net_device *dev)
101319 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
101320
101321 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
101322- atomic_set(&bat_priv->bcast_seqno, 1);
101323+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
101324 atomic_set(&bat_priv->tt.vn, 0);
101325 atomic_set(&bat_priv->tt.local_changes, 0);
101326 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
101327@@ -775,7 +775,7 @@ static int batadv_softif_init_late(struct net_device *dev)
101328
101329 /* randomize initial seqno to avoid collision */
101330 get_random_bytes(&random_seqno, sizeof(random_seqno));
101331- atomic_set(&bat_priv->frag_seqno, random_seqno);
101332+ atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
101333
101334 bat_priv->primary_if = NULL;
101335 bat_priv->num_ifaces = 0;
101336@@ -983,7 +983,7 @@ int batadv_softif_is_valid(const struct net_device *net_dev)
101337 return 0;
101338 }
101339
101340-struct rtnl_link_ops batadv_link_ops __read_mostly = {
101341+struct rtnl_link_ops batadv_link_ops = {
101342 .kind = "batadv",
101343 .priv_size = sizeof(struct batadv_priv),
101344 .setup = batadv_softif_init_early,
101345diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
101346index 8854c05..ee5d5497 100644
101347--- a/net/batman-adv/types.h
101348+++ b/net/batman-adv/types.h
101349@@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
101350 struct batadv_hard_iface_bat_iv {
101351 unsigned char *ogm_buff;
101352 int ogm_buff_len;
101353- atomic_t ogm_seqno;
101354+ atomic_unchecked_t ogm_seqno;
101355 };
101356
101357 /**
101358@@ -768,7 +768,7 @@ struct batadv_priv {
101359 atomic_t bonding;
101360 atomic_t fragmentation;
101361 atomic_t packet_size_max;
101362- atomic_t frag_seqno;
101363+ atomic_unchecked_t frag_seqno;
101364 #ifdef CONFIG_BATMAN_ADV_BLA
101365 atomic_t bridge_loop_avoidance;
101366 #endif
101367@@ -787,7 +787,7 @@ struct batadv_priv {
101368 #endif
101369 uint32_t isolation_mark;
101370 uint32_t isolation_mark_mask;
101371- atomic_t bcast_seqno;
101372+ atomic_unchecked_t bcast_seqno;
101373 atomic_t bcast_queue_left;
101374 atomic_t batman_queue_left;
101375 char num_ifaces;
101376diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
101377index 115f149..f0ba286 100644
101378--- a/net/bluetooth/hci_sock.c
101379+++ b/net/bluetooth/hci_sock.c
101380@@ -1067,7 +1067,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
101381 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
101382 }
101383
101384- len = min_t(unsigned int, len, sizeof(uf));
101385+ len = min((size_t)len, sizeof(uf));
101386 if (copy_from_user(&uf, optval, len)) {
101387 err = -EFAULT;
101388 break;
101389diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
101390index 14ca8ae..262d49a 100644
101391--- a/net/bluetooth/l2cap_core.c
101392+++ b/net/bluetooth/l2cap_core.c
101393@@ -3565,8 +3565,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
101394 break;
101395
101396 case L2CAP_CONF_RFC:
101397- if (olen == sizeof(rfc))
101398- memcpy(&rfc, (void *)val, olen);
101399+ if (olen != sizeof(rfc))
101400+ break;
101401+
101402+ memcpy(&rfc, (void *)val, olen);
101403
101404 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
101405 rfc.mode != chan->mode)
101406diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
101407index 1884f72..b3b71f9 100644
101408--- a/net/bluetooth/l2cap_sock.c
101409+++ b/net/bluetooth/l2cap_sock.c
101410@@ -629,7 +629,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
101411 struct sock *sk = sock->sk;
101412 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
101413 struct l2cap_options opts;
101414- int len, err = 0;
101415+ int err = 0;
101416+ size_t len = optlen;
101417 u32 opt;
101418
101419 BT_DBG("sk %p", sk);
101420@@ -656,7 +657,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
101421 opts.max_tx = chan->max_tx;
101422 opts.txwin_size = chan->tx_win;
101423
101424- len = min_t(unsigned int, sizeof(opts), optlen);
101425+ len = min(sizeof(opts), len);
101426 if (copy_from_user((char *) &opts, optval, len)) {
101427 err = -EFAULT;
101428 break;
101429@@ -743,7 +744,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101430 struct bt_security sec;
101431 struct bt_power pwr;
101432 struct l2cap_conn *conn;
101433- int len, err = 0;
101434+ int err = 0;
101435+ size_t len = optlen;
101436 u32 opt;
101437
101438 BT_DBG("sk %p", sk);
101439@@ -767,7 +769,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101440
101441 sec.level = BT_SECURITY_LOW;
101442
101443- len = min_t(unsigned int, sizeof(sec), optlen);
101444+ len = min(sizeof(sec), len);
101445 if (copy_from_user((char *) &sec, optval, len)) {
101446 err = -EFAULT;
101447 break;
101448@@ -862,7 +864,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
101449
101450 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
101451
101452- len = min_t(unsigned int, sizeof(pwr), optlen);
101453+ len = min(sizeof(pwr), len);
101454 if (copy_from_user((char *) &pwr, optval, len)) {
101455 err = -EFAULT;
101456 break;
101457diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
101458index 8bbbb5e..6fc0950 100644
101459--- a/net/bluetooth/rfcomm/sock.c
101460+++ b/net/bluetooth/rfcomm/sock.c
101461@@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
101462 struct sock *sk = sock->sk;
101463 struct bt_security sec;
101464 int err = 0;
101465- size_t len;
101466+ size_t len = optlen;
101467 u32 opt;
101468
101469 BT_DBG("sk %p", sk);
101470@@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
101471
101472 sec.level = BT_SECURITY_LOW;
101473
101474- len = min_t(unsigned int, sizeof(sec), optlen);
101475+ len = min(sizeof(sec), len);
101476 if (copy_from_user((char *) &sec, optval, len)) {
101477 err = -EFAULT;
101478 break;
101479diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
101480index 8e385a0..a5bdd8e 100644
101481--- a/net/bluetooth/rfcomm/tty.c
101482+++ b/net/bluetooth/rfcomm/tty.c
101483@@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
101484 BT_DBG("tty %p id %d", tty, tty->index);
101485
101486 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
101487- dev->channel, dev->port.count);
101488+ dev->channel, atomic_read(&dev->port.count));
101489
101490 err = tty_port_open(&dev->port, tty, filp);
101491 if (err)
101492@@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
101493 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
101494
101495 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
101496- dev->port.count);
101497+ atomic_read(&dev->port.count));
101498
101499 tty_port_close(&dev->port, tty, filp);
101500 }
101501diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
101502index cb5fcf6..ad0a1a5 100644
101503--- a/net/bridge/br_netlink.c
101504+++ b/net/bridge/br_netlink.c
101505@@ -484,7 +484,7 @@ static struct rtnl_af_ops br_af_ops = {
101506 .get_link_af_size = br_get_link_af_size,
101507 };
101508
101509-struct rtnl_link_ops br_link_ops __read_mostly = {
101510+struct rtnl_link_ops br_link_ops = {
101511 .kind = "bridge",
101512 .priv_size = sizeof(struct net_bridge),
101513 .setup = br_dev_setup,
101514diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
101515index 6d69631..b8fdc85 100644
101516--- a/net/bridge/netfilter/ebtables.c
101517+++ b/net/bridge/netfilter/ebtables.c
101518@@ -1518,7 +1518,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
101519 tmp.valid_hooks = t->table->valid_hooks;
101520 }
101521 mutex_unlock(&ebt_mutex);
101522- if (copy_to_user(user, &tmp, *len) != 0) {
101523+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101524 BUGPRINT("c2u Didn't work\n");
101525 ret = -EFAULT;
101526 break;
101527@@ -2324,7 +2324,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
101528 goto out;
101529 tmp.valid_hooks = t->valid_hooks;
101530
101531- if (copy_to_user(user, &tmp, *len) != 0) {
101532+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101533 ret = -EFAULT;
101534 break;
101535 }
101536@@ -2335,7 +2335,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
101537 tmp.entries_size = t->table->entries_size;
101538 tmp.valid_hooks = t->table->valid_hooks;
101539
101540- if (copy_to_user(user, &tmp, *len) != 0) {
101541+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101542 ret = -EFAULT;
101543 break;
101544 }
101545diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
101546index f5afda1..dcf770a 100644
101547--- a/net/caif/cfctrl.c
101548+++ b/net/caif/cfctrl.c
101549@@ -10,6 +10,7 @@
101550 #include <linux/spinlock.h>
101551 #include <linux/slab.h>
101552 #include <linux/pkt_sched.h>
101553+#include <linux/sched.h>
101554 #include <net/caif/caif_layer.h>
101555 #include <net/caif/cfpkt.h>
101556 #include <net/caif/cfctrl.h>
101557@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
101558 memset(&dev_info, 0, sizeof(dev_info));
101559 dev_info.id = 0xff;
101560 cfsrvl_init(&this->serv, 0, &dev_info, false);
101561- atomic_set(&this->req_seq_no, 1);
101562- atomic_set(&this->rsp_seq_no, 1);
101563+ atomic_set_unchecked(&this->req_seq_no, 1);
101564+ atomic_set_unchecked(&this->rsp_seq_no, 1);
101565 this->serv.layer.receive = cfctrl_recv;
101566 sprintf(this->serv.layer.name, "ctrl");
101567 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
101568@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
101569 struct cfctrl_request_info *req)
101570 {
101571 spin_lock_bh(&ctrl->info_list_lock);
101572- atomic_inc(&ctrl->req_seq_no);
101573- req->sequence_no = atomic_read(&ctrl->req_seq_no);
101574+ atomic_inc_unchecked(&ctrl->req_seq_no);
101575+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
101576 list_add_tail(&req->list, &ctrl->list);
101577 spin_unlock_bh(&ctrl->info_list_lock);
101578 }
101579@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
101580 if (p != first)
101581 pr_warn("Requests are not received in order\n");
101582
101583- atomic_set(&ctrl->rsp_seq_no,
101584+ atomic_set_unchecked(&ctrl->rsp_seq_no,
101585 p->sequence_no);
101586 list_del(&p->list);
101587 goto out;
101588diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
101589index 4589ff67..46d6b8f 100644
101590--- a/net/caif/chnl_net.c
101591+++ b/net/caif/chnl_net.c
101592@@ -516,7 +516,7 @@ static const struct nla_policy ipcaif_policy[IFLA_CAIF_MAX + 1] = {
101593 };
101594
101595
101596-static struct rtnl_link_ops ipcaif_link_ops __read_mostly = {
101597+static struct rtnl_link_ops ipcaif_link_ops = {
101598 .kind = "caif",
101599 .priv_size = sizeof(struct chnl_net),
101600 .setup = ipcaif_net_setup,
101601diff --git a/net/can/af_can.c b/net/can/af_can.c
101602index ce82337..5d17b4d 100644
101603--- a/net/can/af_can.c
101604+++ b/net/can/af_can.c
101605@@ -884,7 +884,7 @@ static const struct net_proto_family can_family_ops = {
101606 };
101607
101608 /* notifier block for netdevice event */
101609-static struct notifier_block can_netdev_notifier __read_mostly = {
101610+static struct notifier_block can_netdev_notifier = {
101611 .notifier_call = can_notifier,
101612 };
101613
101614diff --git a/net/can/bcm.c b/net/can/bcm.c
101615index dcb75c0..24b1b43 100644
101616--- a/net/can/bcm.c
101617+++ b/net/can/bcm.c
101618@@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
101619 }
101620
101621 /* create /proc/net/can-bcm directory */
101622- proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
101623+ proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
101624 return 0;
101625 }
101626
101627diff --git a/net/can/gw.c b/net/can/gw.c
101628index 050a211..bb9fe33 100644
101629--- a/net/can/gw.c
101630+++ b/net/can/gw.c
101631@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
101632 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
101633
101634 static HLIST_HEAD(cgw_list);
101635-static struct notifier_block notifier;
101636
101637 static struct kmem_cache *cgw_cache __read_mostly;
101638
101639@@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
101640 return err;
101641 }
101642
101643+static struct notifier_block notifier = {
101644+ .notifier_call = cgw_notifier
101645+};
101646+
101647 static __init int cgw_module_init(void)
101648 {
101649 /* sanitize given module parameter */
101650@@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
101651 return -ENOMEM;
101652
101653 /* set notifier */
101654- notifier.notifier_call = cgw_notifier;
101655 register_netdevice_notifier(&notifier);
101656
101657 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
101658diff --git a/net/can/proc.c b/net/can/proc.c
101659index 1a19b98..df2b4ec 100644
101660--- a/net/can/proc.c
101661+++ b/net/can/proc.c
101662@@ -514,7 +514,7 @@ static void can_remove_proc_readentry(const char *name)
101663 void can_init_proc(void)
101664 {
101665 /* create /proc/net/can directory */
101666- can_dir = proc_mkdir("can", init_net.proc_net);
101667+ can_dir = proc_mkdir_restrict("can", init_net.proc_net);
101668
101669 if (!can_dir) {
101670 printk(KERN_INFO "can: failed to create /proc/net/can . "
101671diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
101672index 9f02369..e6160e9 100644
101673--- a/net/ceph/messenger.c
101674+++ b/net/ceph/messenger.c
101675@@ -188,7 +188,7 @@ static void con_fault(struct ceph_connection *con);
101676 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
101677
101678 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
101679-static atomic_t addr_str_seq = ATOMIC_INIT(0);
101680+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
101681
101682 static struct page *zero_page; /* used in certain error cases */
101683
101684@@ -199,7 +199,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
101685 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
101686 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
101687
101688- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101689+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101690 s = addr_str[i];
101691
101692 switch (ss->ss_family) {
101693diff --git a/net/compat.c b/net/compat.c
101694index bc8aeef..f9c070c 100644
101695--- a/net/compat.c
101696+++ b/net/compat.c
101697@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
101698 return -EFAULT;
101699 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
101700 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
101701- kmsg->msg_name = compat_ptr(tmp1);
101702- kmsg->msg_iov = compat_ptr(tmp2);
101703- kmsg->msg_control = compat_ptr(tmp3);
101704+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
101705+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
101706+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
101707 return 0;
101708 }
101709
101710@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101711
101712 if (kern_msg->msg_name && kern_msg->msg_namelen) {
101713 if (mode == VERIFY_READ) {
101714- int err = move_addr_to_kernel(kern_msg->msg_name,
101715+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
101716 kern_msg->msg_namelen,
101717 kern_address);
101718 if (err < 0)
101719@@ -100,7 +100,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101720 }
101721
101722 tot_len = iov_from_user_compat_to_kern(kern_iov,
101723- (struct compat_iovec __user *)kern_msg->msg_iov,
101724+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
101725 kern_msg->msg_iovlen);
101726 if (tot_len >= 0)
101727 kern_msg->msg_iov = kern_iov;
101728@@ -120,20 +120,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101729
101730 #define CMSG_COMPAT_FIRSTHDR(msg) \
101731 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
101732- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
101733+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
101734 (struct compat_cmsghdr __user *)NULL)
101735
101736 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
101737 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
101738 (ucmlen) <= (unsigned long) \
101739 ((mhdr)->msg_controllen - \
101740- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
101741+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
101742
101743 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
101744 struct compat_cmsghdr __user *cmsg, int cmsg_len)
101745 {
101746 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
101747- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
101748+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
101749 msg->msg_controllen)
101750 return NULL;
101751 return (struct compat_cmsghdr __user *)ptr;
101752@@ -223,7 +223,7 @@ Efault:
101753
101754 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
101755 {
101756- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101757+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101758 struct compat_cmsghdr cmhdr;
101759 struct compat_timeval ctv;
101760 struct compat_timespec cts[3];
101761@@ -279,7 +279,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
101762
101763 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
101764 {
101765- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101766+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101767 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
101768 int fdnum = scm->fp->count;
101769 struct file **fp = scm->fp->fp;
101770@@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
101771 return -EFAULT;
101772 old_fs = get_fs();
101773 set_fs(KERNEL_DS);
101774- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
101775+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
101776 set_fs(old_fs);
101777
101778 return err;
101779@@ -428,7 +428,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
101780 len = sizeof(ktime);
101781 old_fs = get_fs();
101782 set_fs(KERNEL_DS);
101783- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
101784+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
101785 set_fs(old_fs);
101786
101787 if (!err) {
101788@@ -571,7 +571,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101789 case MCAST_JOIN_GROUP:
101790 case MCAST_LEAVE_GROUP:
101791 {
101792- struct compat_group_req __user *gr32 = (void *)optval;
101793+ struct compat_group_req __user *gr32 = (void __user *)optval;
101794 struct group_req __user *kgr =
101795 compat_alloc_user_space(sizeof(struct group_req));
101796 u32 interface;
101797@@ -592,7 +592,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101798 case MCAST_BLOCK_SOURCE:
101799 case MCAST_UNBLOCK_SOURCE:
101800 {
101801- struct compat_group_source_req __user *gsr32 = (void *)optval;
101802+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
101803 struct group_source_req __user *kgsr = compat_alloc_user_space(
101804 sizeof(struct group_source_req));
101805 u32 interface;
101806@@ -613,7 +613,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101807 }
101808 case MCAST_MSFILTER:
101809 {
101810- struct compat_group_filter __user *gf32 = (void *)optval;
101811+ struct compat_group_filter __user *gf32 = (void __user *)optval;
101812 struct group_filter __user *kgf;
101813 u32 interface, fmode, numsrc;
101814
101815@@ -651,7 +651,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
101816 char __user *optval, int __user *optlen,
101817 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
101818 {
101819- struct compat_group_filter __user *gf32 = (void *)optval;
101820+ struct compat_group_filter __user *gf32 = (void __user *)optval;
101821 struct group_filter __user *kgf;
101822 int __user *koptlen;
101823 u32 interface, fmode, numsrc;
101824@@ -804,7 +804,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
101825
101826 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
101827 return -EINVAL;
101828- if (copy_from_user(a, args, nas[call]))
101829+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
101830 return -EFAULT;
101831 a0 = a[0];
101832 a1 = a[1];
101833diff --git a/net/core/datagram.c b/net/core/datagram.c
101834index fdbc9a8..cd6972c 100644
101835--- a/net/core/datagram.c
101836+++ b/net/core/datagram.c
101837@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
101838 }
101839
101840 kfree_skb(skb);
101841- atomic_inc(&sk->sk_drops);
101842+ atomic_inc_unchecked(&sk->sk_drops);
101843 sk_mem_reclaim_partial(sk);
101844
101845 return err;
101846diff --git a/net/core/dev.c b/net/core/dev.c
101847index cf8a95f..2837211 100644
101848--- a/net/core/dev.c
101849+++ b/net/core/dev.c
101850@@ -1683,14 +1683,14 @@ int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
101851 {
101852 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
101853 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
101854- atomic_long_inc(&dev->rx_dropped);
101855+ atomic_long_inc_unchecked(&dev->rx_dropped);
101856 kfree_skb(skb);
101857 return NET_RX_DROP;
101858 }
101859 }
101860
101861 if (unlikely(!is_skb_forwardable(dev, skb))) {
101862- atomic_long_inc(&dev->rx_dropped);
101863+ atomic_long_inc_unchecked(&dev->rx_dropped);
101864 kfree_skb(skb);
101865 return NET_RX_DROP;
101866 }
101867@@ -2487,7 +2487,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
101868
101869 struct dev_gso_cb {
101870 void (*destructor)(struct sk_buff *skb);
101871-};
101872+} __no_const;
101873
101874 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
101875
101876@@ -2952,7 +2952,7 @@ recursion_alert:
101877 rc = -ENETDOWN;
101878 rcu_read_unlock_bh();
101879
101880- atomic_long_inc(&dev->tx_dropped);
101881+ atomic_long_inc_unchecked(&dev->tx_dropped);
101882 kfree_skb(skb);
101883 return rc;
101884 out:
101885@@ -3296,7 +3296,7 @@ enqueue:
101886
101887 local_irq_restore(flags);
101888
101889- atomic_long_inc(&skb->dev->rx_dropped);
101890+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101891 kfree_skb(skb);
101892 return NET_RX_DROP;
101893 }
101894@@ -3373,7 +3373,7 @@ int netif_rx_ni(struct sk_buff *skb)
101895 }
101896 EXPORT_SYMBOL(netif_rx_ni);
101897
101898-static void net_tx_action(struct softirq_action *h)
101899+static __latent_entropy void net_tx_action(void)
101900 {
101901 struct softnet_data *sd = &__get_cpu_var(softnet_data);
101902
101903@@ -3706,7 +3706,7 @@ ncls:
101904 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
101905 } else {
101906 drop:
101907- atomic_long_inc(&skb->dev->rx_dropped);
101908+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101909 kfree_skb(skb);
101910 /* Jamal, now you will not able to escape explaining
101911 * me how you were going to use this. :-)
101912@@ -4426,7 +4426,7 @@ void netif_napi_del(struct napi_struct *napi)
101913 }
101914 EXPORT_SYMBOL(netif_napi_del);
101915
101916-static void net_rx_action(struct softirq_action *h)
101917+static __latent_entropy void net_rx_action(void)
101918 {
101919 struct softnet_data *sd = &__get_cpu_var(softnet_data);
101920 unsigned long time_limit = jiffies + 2;
101921@@ -6480,8 +6480,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
101922 } else {
101923 netdev_stats_to_stats64(storage, &dev->stats);
101924 }
101925- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
101926- storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
101927+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
101928+ storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
101929 return storage;
101930 }
101931 EXPORT_SYMBOL(dev_get_stats);
101932diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
101933index cf999e0..c59a9754 100644
101934--- a/net/core/dev_ioctl.c
101935+++ b/net/core/dev_ioctl.c
101936@@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
101937 if (no_module && capable(CAP_NET_ADMIN))
101938 no_module = request_module("netdev-%s", name);
101939 if (no_module && capable(CAP_SYS_MODULE)) {
101940+#ifdef CONFIG_GRKERNSEC_MODHARDEN
101941+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
101942+#else
101943 if (!request_module("%s", name))
101944 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
101945 name);
101946+#endif
101947 }
101948 }
101949 EXPORT_SYMBOL(dev_load);
101950diff --git a/net/core/filter.c b/net/core/filter.c
101951index d814b8a..b5ab778 100644
101952--- a/net/core/filter.c
101953+++ b/net/core/filter.c
101954@@ -559,7 +559,11 @@ do_pass:
101955
101956 /* Unkown instruction. */
101957 default:
101958- goto err;
101959+ WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
101960+ fp->code, fp->jt, fp->jf, fp->k);
101961+ kfree(addrs);
101962+ BUG();
101963+ return -EINVAL;
101964 }
101965
101966 insn++;
101967@@ -606,7 +610,7 @@ static int check_load_and_stores(const struct sock_filter *filter, int flen)
101968 u16 *masks, memvalid = 0; /* One bit per cell, 16 cells */
101969 int pc, ret = 0;
101970
101971- BUILD_BUG_ON(BPF_MEMWORDS > 16);
101972+ BUILD_BUG_ON(BPF_MEMWORDS != 16);
101973
101974 masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL);
101975 if (!masks)
101976@@ -933,7 +937,7 @@ static struct bpf_prog *bpf_migrate_filter(struct bpf_prog *fp)
101977
101978 /* Expand fp for appending the new filter representation. */
101979 old_fp = fp;
101980- fp = krealloc(old_fp, bpf_prog_size(new_len), GFP_KERNEL);
101981+ fp = bpf_prog_realloc(old_fp, bpf_prog_size(new_len), 0);
101982 if (!fp) {
101983 /* The old_fp is still around in case we couldn't
101984 * allocate new memory, so uncharge on that one.
101985@@ -1013,11 +1017,11 @@ int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog)
101986 if (fprog->filter == NULL)
101987 return -EINVAL;
101988
101989- fp = kmalloc(bpf_prog_size(fprog->len), GFP_KERNEL);
101990+ fp = bpf_prog_alloc(bpf_prog_size(fprog->len), 0);
101991 if (!fp)
101992 return -ENOMEM;
101993
101994- memcpy(fp->insns, fprog->filter, fsize);
101995+ memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
101996
101997 fp->len = fprog->len;
101998 /* Since unattached filters are not copied back to user
101999@@ -1069,12 +1073,12 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
102000 if (fprog->filter == NULL)
102001 return -EINVAL;
102002
102003- prog = kmalloc(bpf_fsize, GFP_KERNEL);
102004+ prog = bpf_prog_alloc(bpf_fsize, 0);
102005 if (!prog)
102006 return -ENOMEM;
102007
102008 if (copy_from_user(prog->insns, fprog->filter, fsize)) {
102009- kfree(prog);
102010+ __bpf_prog_free(prog);
102011 return -EFAULT;
102012 }
102013
102014@@ -1082,7 +1086,7 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
102015
102016 err = bpf_prog_store_orig_filter(prog, fprog);
102017 if (err) {
102018- kfree(prog);
102019+ __bpf_prog_free(prog);
102020 return -ENOMEM;
102021 }
102022
102023diff --git a/net/core/flow.c b/net/core/flow.c
102024index a0348fd..6951c76 100644
102025--- a/net/core/flow.c
102026+++ b/net/core/flow.c
102027@@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
102028 static int flow_entry_valid(struct flow_cache_entry *fle,
102029 struct netns_xfrm *xfrm)
102030 {
102031- if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
102032+ if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
102033 return 0;
102034 if (fle->object && !fle->object->ops->check(fle->object))
102035 return 0;
102036@@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
102037 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
102038 fcp->hash_count++;
102039 }
102040- } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
102041+ } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
102042 flo = fle->object;
102043 if (!flo)
102044 goto ret_object;
102045@@ -263,7 +263,7 @@ nocache:
102046 }
102047 flo = resolver(net, key, family, dir, flo, ctx);
102048 if (fle) {
102049- fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
102050+ fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
102051 if (!IS_ERR(flo))
102052 fle->object = flo;
102053 else
102054diff --git a/net/core/iovec.c b/net/core/iovec.c
102055index e1ec45a..e5c6f16 100644
102056--- a/net/core/iovec.c
102057+++ b/net/core/iovec.c
102058@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
102059 if (m->msg_name && m->msg_namelen) {
102060 if (mode == VERIFY_READ) {
102061 void __user *namep;
102062- namep = (void __user __force *) m->msg_name;
102063+ namep = (void __force_user *) m->msg_name;
102064 err = move_addr_to_kernel(namep, m->msg_namelen,
102065 address);
102066 if (err < 0)
102067@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
102068 }
102069
102070 size = m->msg_iovlen * sizeof(struct iovec);
102071- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
102072+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
102073 return -EFAULT;
102074
102075 m->msg_iov = iov;
102076diff --git a/net/core/neighbour.c b/net/core/neighbour.c
102077index ef31fef..8be66d9 100644
102078--- a/net/core/neighbour.c
102079+++ b/net/core/neighbour.c
102080@@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
102081 void __user *buffer, size_t *lenp, loff_t *ppos)
102082 {
102083 int size, ret;
102084- struct ctl_table tmp = *ctl;
102085+ ctl_table_no_const tmp = *ctl;
102086
102087 tmp.extra1 = &zero;
102088 tmp.extra2 = &unres_qlen_max;
102089@@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
102090 void __user *buffer,
102091 size_t *lenp, loff_t *ppos)
102092 {
102093- struct ctl_table tmp = *ctl;
102094+ ctl_table_no_const tmp = *ctl;
102095 int ret;
102096
102097 tmp.extra1 = &zero;
102098diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
102099index 2bf8329..2eb1423 100644
102100--- a/net/core/net-procfs.c
102101+++ b/net/core/net-procfs.c
102102@@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
102103 struct rtnl_link_stats64 temp;
102104 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
102105
102106- seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
102107+ if (gr_proc_is_restricted())
102108+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
102109+ "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
102110+ dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
102111+ 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
102112+ else
102113+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
102114 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
102115 dev->name, stats->rx_bytes, stats->rx_packets,
102116 stats->rx_errors,
102117@@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
102118 return 0;
102119 }
102120
102121-static const struct seq_operations dev_seq_ops = {
102122+const struct seq_operations dev_seq_ops = {
102123 .start = dev_seq_start,
102124 .next = dev_seq_next,
102125 .stop = dev_seq_stop,
102126@@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
102127
102128 static int softnet_seq_open(struct inode *inode, struct file *file)
102129 {
102130- return seq_open(file, &softnet_seq_ops);
102131+ return seq_open_restrict(file, &softnet_seq_ops);
102132 }
102133
102134 static const struct file_operations softnet_seq_fops = {
102135@@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
102136 else
102137 seq_printf(seq, "%04x", ntohs(pt->type));
102138
102139+#ifdef CONFIG_GRKERNSEC_HIDESYM
102140+ seq_printf(seq, " %-8s %pf\n",
102141+ pt->dev ? pt->dev->name : "", NULL);
102142+#else
102143 seq_printf(seq, " %-8s %pf\n",
102144 pt->dev ? pt->dev->name : "", pt->func);
102145+#endif
102146 }
102147
102148 return 0;
102149diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
102150index 9dd0669..c52fb1b 100644
102151--- a/net/core/net-sysfs.c
102152+++ b/net/core/net-sysfs.c
102153@@ -278,7 +278,7 @@ static ssize_t carrier_changes_show(struct device *dev,
102154 {
102155 struct net_device *netdev = to_net_dev(dev);
102156 return sprintf(buf, fmt_dec,
102157- atomic_read(&netdev->carrier_changes));
102158+ atomic_read_unchecked(&netdev->carrier_changes));
102159 }
102160 static DEVICE_ATTR_RO(carrier_changes);
102161
102162diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
102163index 7c6b51a..e9dd57f 100644
102164--- a/net/core/net_namespace.c
102165+++ b/net/core/net_namespace.c
102166@@ -445,7 +445,7 @@ static int __register_pernet_operations(struct list_head *list,
102167 int error;
102168 LIST_HEAD(net_exit_list);
102169
102170- list_add_tail(&ops->list, list);
102171+ pax_list_add_tail((struct list_head *)&ops->list, list);
102172 if (ops->init || (ops->id && ops->size)) {
102173 for_each_net(net) {
102174 error = ops_init(ops, net);
102175@@ -458,7 +458,7 @@ static int __register_pernet_operations(struct list_head *list,
102176
102177 out_undo:
102178 /* If I have an error cleanup all namespaces I initialized */
102179- list_del(&ops->list);
102180+ pax_list_del((struct list_head *)&ops->list);
102181 ops_exit_list(ops, &net_exit_list);
102182 ops_free_list(ops, &net_exit_list);
102183 return error;
102184@@ -469,7 +469,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
102185 struct net *net;
102186 LIST_HEAD(net_exit_list);
102187
102188- list_del(&ops->list);
102189+ pax_list_del((struct list_head *)&ops->list);
102190 for_each_net(net)
102191 list_add_tail(&net->exit_list, &net_exit_list);
102192 ops_exit_list(ops, &net_exit_list);
102193@@ -603,7 +603,7 @@ int register_pernet_device(struct pernet_operations *ops)
102194 mutex_lock(&net_mutex);
102195 error = register_pernet_operations(&pernet_list, ops);
102196 if (!error && (first_device == &pernet_list))
102197- first_device = &ops->list;
102198+ first_device = (struct list_head *)&ops->list;
102199 mutex_unlock(&net_mutex);
102200 return error;
102201 }
102202diff --git a/net/core/netpoll.c b/net/core/netpoll.c
102203index 907fb5e..8260f040b 100644
102204--- a/net/core/netpoll.c
102205+++ b/net/core/netpoll.c
102206@@ -382,7 +382,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
102207 struct udphdr *udph;
102208 struct iphdr *iph;
102209 struct ethhdr *eth;
102210- static atomic_t ip_ident;
102211+ static atomic_unchecked_t ip_ident;
102212 struct ipv6hdr *ip6h;
102213
102214 udp_len = len + sizeof(*udph);
102215@@ -453,7 +453,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
102216 put_unaligned(0x45, (unsigned char *)iph);
102217 iph->tos = 0;
102218 put_unaligned(htons(ip_len), &(iph->tot_len));
102219- iph->id = htons(atomic_inc_return(&ip_ident));
102220+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
102221 iph->frag_off = 0;
102222 iph->ttl = 64;
102223 iph->protocol = IPPROTO_UDP;
102224diff --git a/net/core/pktgen.c b/net/core/pktgen.c
102225index 8b849dd..cd88bfc 100644
102226--- a/net/core/pktgen.c
102227+++ b/net/core/pktgen.c
102228@@ -3723,7 +3723,7 @@ static int __net_init pg_net_init(struct net *net)
102229 pn->net = net;
102230 INIT_LIST_HEAD(&pn->pktgen_threads);
102231 pn->pktgen_exiting = false;
102232- pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
102233+ pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
102234 if (!pn->proc_dir) {
102235 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
102236 return -ENODEV;
102237diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
102238index f0493e3..c3ffd7f 100644
102239--- a/net/core/rtnetlink.c
102240+++ b/net/core/rtnetlink.c
102241@@ -58,7 +58,7 @@ struct rtnl_link {
102242 rtnl_doit_func doit;
102243 rtnl_dumpit_func dumpit;
102244 rtnl_calcit_func calcit;
102245-};
102246+} __no_const;
102247
102248 static DEFINE_MUTEX(rtnl_mutex);
102249
102250@@ -304,10 +304,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
102251 * to use the ops for creating device. So do not
102252 * fill up dellink as well. That disables rtnl_dellink.
102253 */
102254- if (ops->setup && !ops->dellink)
102255- ops->dellink = unregister_netdevice_queue;
102256+ if (ops->setup && !ops->dellink) {
102257+ pax_open_kernel();
102258+ *(void **)&ops->dellink = unregister_netdevice_queue;
102259+ pax_close_kernel();
102260+ }
102261
102262- list_add_tail(&ops->list, &link_ops);
102263+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
102264 return 0;
102265 }
102266 EXPORT_SYMBOL_GPL(__rtnl_link_register);
102267@@ -354,7 +357,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
102268 for_each_net(net) {
102269 __rtnl_kill_links(net, ops);
102270 }
102271- list_del(&ops->list);
102272+ pax_list_del((struct list_head *)&ops->list);
102273 }
102274 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
102275
102276@@ -1014,7 +1017,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
102277 (dev->ifalias &&
102278 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
102279 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
102280- atomic_read(&dev->carrier_changes)))
102281+ atomic_read_unchecked(&dev->carrier_changes)))
102282 goto nla_put_failure;
102283
102284 if (1) {
102285@@ -2780,6 +2783,9 @@ static int rtnl_bridge_setlink(struct sk_buff *skb, struct nlmsghdr *nlh)
102286 if (br_spec) {
102287 nla_for_each_nested(attr, br_spec, rem) {
102288 if (nla_type(attr) == IFLA_BRIDGE_FLAGS) {
102289+ if (nla_len(attr) < sizeof(flags))
102290+ return -EINVAL;
102291+
102292 have_flags = true;
102293 flags = nla_get_u16(attr);
102294 break;
102295@@ -2850,6 +2856,9 @@ static int rtnl_bridge_dellink(struct sk_buff *skb, struct nlmsghdr *nlh)
102296 if (br_spec) {
102297 nla_for_each_nested(attr, br_spec, rem) {
102298 if (nla_type(attr) == IFLA_BRIDGE_FLAGS) {
102299+ if (nla_len(attr) < sizeof(flags))
102300+ return -EINVAL;
102301+
102302 have_flags = true;
102303 flags = nla_get_u16(attr);
102304 break;
102305diff --git a/net/core/scm.c b/net/core/scm.c
102306index b442e7e..6f5b5a2 100644
102307--- a/net/core/scm.c
102308+++ b/net/core/scm.c
102309@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
102310 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
102311 {
102312 struct cmsghdr __user *cm
102313- = (__force struct cmsghdr __user *)msg->msg_control;
102314+ = (struct cmsghdr __force_user *)msg->msg_control;
102315 struct cmsghdr cmhdr;
102316 int cmlen = CMSG_LEN(len);
102317 int err;
102318@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
102319 err = -EFAULT;
102320 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
102321 goto out;
102322- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
102323+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
102324 goto out;
102325 cmlen = CMSG_SPACE(len);
102326 if (msg->msg_controllen < cmlen)
102327@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
102328 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
102329 {
102330 struct cmsghdr __user *cm
102331- = (__force struct cmsghdr __user*)msg->msg_control;
102332+ = (struct cmsghdr __force_user *)msg->msg_control;
102333
102334 int fdmax = 0;
102335 int fdnum = scm->fp->count;
102336@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
102337 if (fdnum < fdmax)
102338 fdmax = fdnum;
102339
102340- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
102341+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
102342 i++, cmfptr++)
102343 {
102344 struct socket *sock;
102345diff --git a/net/core/skbuff.c b/net/core/skbuff.c
102346index 8d28969..4d36260 100644
102347--- a/net/core/skbuff.c
102348+++ b/net/core/skbuff.c
102349@@ -360,18 +360,29 @@ refill:
102350 goto end;
102351 }
102352 nc->frag.size = PAGE_SIZE << order;
102353-recycle:
102354- atomic_set(&nc->frag.page->_count, NETDEV_PAGECNT_MAX_BIAS);
102355+ /* Even if we own the page, we do not use atomic_set().
102356+ * This would break get_page_unless_zero() users.
102357+ */
102358+ atomic_add(NETDEV_PAGECNT_MAX_BIAS - 1,
102359+ &nc->frag.page->_count);
102360 nc->pagecnt_bias = NETDEV_PAGECNT_MAX_BIAS;
102361 nc->frag.offset = 0;
102362 }
102363
102364 if (nc->frag.offset + fragsz > nc->frag.size) {
102365- /* avoid unnecessary locked operations if possible */
102366- if ((atomic_read(&nc->frag.page->_count) == nc->pagecnt_bias) ||
102367- atomic_sub_and_test(nc->pagecnt_bias, &nc->frag.page->_count))
102368- goto recycle;
102369- goto refill;
102370+ if (atomic_read(&nc->frag.page->_count) != nc->pagecnt_bias) {
102371+ if (!atomic_sub_and_test(nc->pagecnt_bias,
102372+ &nc->frag.page->_count))
102373+ goto refill;
102374+ /* OK, page count is 0, we can safely set it */
102375+ atomic_set(&nc->frag.page->_count,
102376+ NETDEV_PAGECNT_MAX_BIAS);
102377+ } else {
102378+ atomic_add(NETDEV_PAGECNT_MAX_BIAS - nc->pagecnt_bias,
102379+ &nc->frag.page->_count);
102380+ }
102381+ nc->pagecnt_bias = NETDEV_PAGECNT_MAX_BIAS;
102382+ nc->frag.offset = 0;
102383 }
102384
102385 data = page_address(nc->frag.page) + nc->frag.offset;
102386@@ -2011,7 +2022,7 @@ EXPORT_SYMBOL(__skb_checksum);
102387 __wsum skb_checksum(const struct sk_buff *skb, int offset,
102388 int len, __wsum csum)
102389 {
102390- const struct skb_checksum_ops ops = {
102391+ static const struct skb_checksum_ops ops = {
102392 .update = csum_partial_ext,
102393 .combine = csum_block_add_ext,
102394 };
102395@@ -3237,13 +3248,15 @@ void __init skb_init(void)
102396 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
102397 sizeof(struct sk_buff),
102398 0,
102399- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
102400+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
102401+ SLAB_NO_SANITIZE,
102402 NULL);
102403 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
102404 (2*sizeof(struct sk_buff)) +
102405 sizeof(atomic_t),
102406 0,
102407- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
102408+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
102409+ SLAB_NO_SANITIZE,
102410 NULL);
102411 }
102412
102413diff --git a/net/core/sock.c b/net/core/sock.c
102414index 9c3f823..bd8c884 100644
102415--- a/net/core/sock.c
102416+++ b/net/core/sock.c
102417@@ -442,7 +442,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102418 struct sk_buff_head *list = &sk->sk_receive_queue;
102419
102420 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
102421- atomic_inc(&sk->sk_drops);
102422+ atomic_inc_unchecked(&sk->sk_drops);
102423 trace_sock_rcvqueue_full(sk, skb);
102424 return -ENOMEM;
102425 }
102426@@ -452,7 +452,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102427 return err;
102428
102429 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
102430- atomic_inc(&sk->sk_drops);
102431+ atomic_inc_unchecked(&sk->sk_drops);
102432 return -ENOBUFS;
102433 }
102434
102435@@ -472,7 +472,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102436 skb_dst_force(skb);
102437
102438 spin_lock_irqsave(&list->lock, flags);
102439- skb->dropcount = atomic_read(&sk->sk_drops);
102440+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
102441 __skb_queue_tail(list, skb);
102442 spin_unlock_irqrestore(&list->lock, flags);
102443
102444@@ -492,7 +492,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
102445 skb->dev = NULL;
102446
102447 if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
102448- atomic_inc(&sk->sk_drops);
102449+ atomic_inc_unchecked(&sk->sk_drops);
102450 goto discard_and_relse;
102451 }
102452 if (nested)
102453@@ -510,7 +510,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
102454 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
102455 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
102456 bh_unlock_sock(sk);
102457- atomic_inc(&sk->sk_drops);
102458+ atomic_inc_unchecked(&sk->sk_drops);
102459 goto discard_and_relse;
102460 }
102461
102462@@ -999,12 +999,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102463 struct timeval tm;
102464 } v;
102465
102466- int lv = sizeof(int);
102467- int len;
102468+ unsigned int lv = sizeof(int);
102469+ unsigned int len;
102470
102471 if (get_user(len, optlen))
102472 return -EFAULT;
102473- if (len < 0)
102474+ if (len > INT_MAX)
102475 return -EINVAL;
102476
102477 memset(&v, 0, sizeof(v));
102478@@ -1142,11 +1142,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102479
102480 case SO_PEERNAME:
102481 {
102482- char address[128];
102483+ char address[_K_SS_MAXSIZE];
102484
102485 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
102486 return -ENOTCONN;
102487- if (lv < len)
102488+ if (lv < len || sizeof address < len)
102489 return -EINVAL;
102490 if (copy_to_user(optval, address, len))
102491 return -EFAULT;
102492@@ -1227,7 +1227,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102493
102494 if (len > lv)
102495 len = lv;
102496- if (copy_to_user(optval, &v, len))
102497+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
102498 return -EFAULT;
102499 lenout:
102500 if (put_user(len, optlen))
102501@@ -1723,6 +1723,8 @@ EXPORT_SYMBOL(sock_kmalloc);
102502 */
102503 void sock_kfree_s(struct sock *sk, void *mem, int size)
102504 {
102505+ if (WARN_ON_ONCE(!mem))
102506+ return;
102507 kfree(mem);
102508 atomic_sub(size, &sk->sk_omem_alloc);
102509 }
102510@@ -2369,7 +2371,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
102511 */
102512 smp_wmb();
102513 atomic_set(&sk->sk_refcnt, 1);
102514- atomic_set(&sk->sk_drops, 0);
102515+ atomic_set_unchecked(&sk->sk_drops, 0);
102516 }
102517 EXPORT_SYMBOL(sock_init_data);
102518
102519@@ -2497,6 +2499,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
102520 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
102521 int level, int type)
102522 {
102523+ struct sock_extended_err ee;
102524 struct sock_exterr_skb *serr;
102525 struct sk_buff *skb, *skb2;
102526 int copied, err;
102527@@ -2518,7 +2521,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
102528 sock_recv_timestamp(msg, sk, skb);
102529
102530 serr = SKB_EXT_ERR(skb);
102531- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
102532+ ee = serr->ee;
102533+ put_cmsg(msg, level, type, sizeof ee, &ee);
102534
102535 msg->msg_flags |= MSG_ERRQUEUE;
102536 err = copied;
102537diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
102538index ad704c7..ca48aff 100644
102539--- a/net/core/sock_diag.c
102540+++ b/net/core/sock_diag.c
102541@@ -9,26 +9,33 @@
102542 #include <linux/inet_diag.h>
102543 #include <linux/sock_diag.h>
102544
102545-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
102546+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
102547 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
102548 static DEFINE_MUTEX(sock_diag_table_mutex);
102549
102550 int sock_diag_check_cookie(void *sk, __u32 *cookie)
102551 {
102552+#ifndef CONFIG_GRKERNSEC_HIDESYM
102553 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
102554 cookie[1] != INET_DIAG_NOCOOKIE) &&
102555 ((u32)(unsigned long)sk != cookie[0] ||
102556 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
102557 return -ESTALE;
102558 else
102559+#endif
102560 return 0;
102561 }
102562 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
102563
102564 void sock_diag_save_cookie(void *sk, __u32 *cookie)
102565 {
102566+#ifdef CONFIG_GRKERNSEC_HIDESYM
102567+ cookie[0] = 0;
102568+ cookie[1] = 0;
102569+#else
102570 cookie[0] = (u32)(unsigned long)sk;
102571 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
102572+#endif
102573 }
102574 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
102575
102576@@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
102577 mutex_lock(&sock_diag_table_mutex);
102578 if (sock_diag_handlers[hndl->family])
102579 err = -EBUSY;
102580- else
102581+ else {
102582+ pax_open_kernel();
102583 sock_diag_handlers[hndl->family] = hndl;
102584+ pax_close_kernel();
102585+ }
102586 mutex_unlock(&sock_diag_table_mutex);
102587
102588 return err;
102589@@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
102590
102591 mutex_lock(&sock_diag_table_mutex);
102592 BUG_ON(sock_diag_handlers[family] != hnld);
102593+ pax_open_kernel();
102594 sock_diag_handlers[family] = NULL;
102595+ pax_close_kernel();
102596 mutex_unlock(&sock_diag_table_mutex);
102597 }
102598 EXPORT_SYMBOL_GPL(sock_diag_unregister);
102599diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
102600index cf9cd13..50683950 100644
102601--- a/net/core/sysctl_net_core.c
102602+++ b/net/core/sysctl_net_core.c
102603@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
102604 {
102605 unsigned int orig_size, size;
102606 int ret, i;
102607- struct ctl_table tmp = {
102608+ ctl_table_no_const tmp = {
102609 .data = &size,
102610 .maxlen = sizeof(size),
102611 .mode = table->mode
102612@@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
102613 void __user *buffer, size_t *lenp, loff_t *ppos)
102614 {
102615 char id[IFNAMSIZ];
102616- struct ctl_table tbl = {
102617+ ctl_table_no_const tbl = {
102618 .data = id,
102619 .maxlen = IFNAMSIZ,
102620 };
102621@@ -263,7 +263,7 @@ static struct ctl_table net_core_table[] = {
102622 .mode = 0644,
102623 .proc_handler = proc_dointvec
102624 },
102625-#ifdef CONFIG_BPF_JIT
102626+#if defined(CONFIG_BPF_JIT) && !defined(CONFIG_GRKERNSEC_BPF_HARDEN)
102627 {
102628 .procname = "bpf_jit_enable",
102629 .data = &bpf_jit_enable,
102630@@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
102631
102632 static __net_init int sysctl_core_net_init(struct net *net)
102633 {
102634- struct ctl_table *tbl;
102635+ ctl_table_no_const *tbl = NULL;
102636
102637 net->core.sysctl_somaxconn = SOMAXCONN;
102638
102639- tbl = netns_core_table;
102640 if (!net_eq(net, &init_net)) {
102641- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
102642+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
102643 if (tbl == NULL)
102644 goto err_dup;
102645
102646@@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
102647 if (net->user_ns != &init_user_ns) {
102648 tbl[0].procname = NULL;
102649 }
102650- }
102651-
102652- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
102653+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
102654+ } else
102655+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
102656 if (net->core.sysctl_hdr == NULL)
102657 goto err_reg;
102658
102659 return 0;
102660
102661 err_reg:
102662- if (tbl != netns_core_table)
102663- kfree(tbl);
102664+ kfree(tbl);
102665 err_dup:
102666 return -ENOMEM;
102667 }
102668@@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
102669 kfree(tbl);
102670 }
102671
102672-static __net_initdata struct pernet_operations sysctl_core_ops = {
102673+static __net_initconst struct pernet_operations sysctl_core_ops = {
102674 .init = sysctl_core_net_init,
102675 .exit = sysctl_core_net_exit,
102676 };
102677diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
102678index ae011b4..d2d18bf 100644
102679--- a/net/decnet/af_decnet.c
102680+++ b/net/decnet/af_decnet.c
102681@@ -465,6 +465,7 @@ static struct proto dn_proto = {
102682 .sysctl_rmem = sysctl_decnet_rmem,
102683 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
102684 .obj_size = sizeof(struct dn_sock),
102685+ .slab_flags = SLAB_USERCOPY,
102686 };
102687
102688 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
102689diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
102690index 3b726f3..1af6368 100644
102691--- a/net/decnet/dn_dev.c
102692+++ b/net/decnet/dn_dev.c
102693@@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
102694 .extra1 = &min_t3,
102695 .extra2 = &max_t3
102696 },
102697- {0}
102698+ { }
102699 },
102700 };
102701
102702diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
102703index 5325b54..a0d4d69 100644
102704--- a/net/decnet/sysctl_net_decnet.c
102705+++ b/net/decnet/sysctl_net_decnet.c
102706@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
102707
102708 if (len > *lenp) len = *lenp;
102709
102710- if (copy_to_user(buffer, addr, len))
102711+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
102712 return -EFAULT;
102713
102714 *lenp = len;
102715@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
102716
102717 if (len > *lenp) len = *lenp;
102718
102719- if (copy_to_user(buffer, devname, len))
102720+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
102721 return -EFAULT;
102722
102723 *lenp = len;
102724diff --git a/net/hsr/hsr_netlink.c b/net/hsr/hsr_netlink.c
102725index a2c7e4c..3dc9f67 100644
102726--- a/net/hsr/hsr_netlink.c
102727+++ b/net/hsr/hsr_netlink.c
102728@@ -102,7 +102,7 @@ nla_put_failure:
102729 return -EMSGSIZE;
102730 }
102731
102732-static struct rtnl_link_ops hsr_link_ops __read_mostly = {
102733+static struct rtnl_link_ops hsr_link_ops = {
102734 .kind = "hsr",
102735 .maxtype = IFLA_HSR_MAX,
102736 .policy = hsr_policy,
102737diff --git a/net/ieee802154/6lowpan_rtnl.c b/net/ieee802154/6lowpan_rtnl.c
102738index 6591d27..499b971 100644
102739--- a/net/ieee802154/6lowpan_rtnl.c
102740+++ b/net/ieee802154/6lowpan_rtnl.c
102741@@ -590,7 +590,7 @@ static void lowpan_dellink(struct net_device *dev, struct list_head *head)
102742 dev_put(real_dev);
102743 }
102744
102745-static struct rtnl_link_ops lowpan_link_ops __read_mostly = {
102746+static struct rtnl_link_ops lowpan_link_ops = {
102747 .kind = "lowpan",
102748 .priv_size = sizeof(struct lowpan_dev_info),
102749 .setup = lowpan_setup,
102750diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
102751index 32755cb..236d827 100644
102752--- a/net/ieee802154/reassembly.c
102753+++ b/net/ieee802154/reassembly.c
102754@@ -433,14 +433,13 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
102755
102756 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102757 {
102758- struct ctl_table *table;
102759+ ctl_table_no_const *table = NULL;
102760 struct ctl_table_header *hdr;
102761 struct netns_ieee802154_lowpan *ieee802154_lowpan =
102762 net_ieee802154_lowpan(net);
102763
102764- table = lowpan_frags_ns_ctl_table;
102765 if (!net_eq(net, &init_net)) {
102766- table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
102767+ table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
102768 GFP_KERNEL);
102769 if (table == NULL)
102770 goto err_alloc;
102771@@ -455,9 +454,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102772 /* Don't export sysctls to unprivileged users */
102773 if (net->user_ns != &init_user_ns)
102774 table[0].procname = NULL;
102775- }
102776-
102777- hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102778+ hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102779+ } else
102780+ hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
102781 if (hdr == NULL)
102782 goto err_reg;
102783
102784@@ -465,8 +464,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102785 return 0;
102786
102787 err_reg:
102788- if (!net_eq(net, &init_net))
102789- kfree(table);
102790+ kfree(table);
102791 err_alloc:
102792 return -ENOMEM;
102793 }
102794diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
102795index 214882e..ec032f6 100644
102796--- a/net/ipv4/devinet.c
102797+++ b/net/ipv4/devinet.c
102798@@ -69,7 +69,8 @@
102799
102800 static struct ipv4_devconf ipv4_devconf = {
102801 .data = {
102802- [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
102803+ [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
102804+ [IPV4_DEVCONF_RP_FILTER - 1] = 1,
102805 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
102806 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
102807 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
102808@@ -80,7 +81,8 @@ static struct ipv4_devconf ipv4_devconf = {
102809
102810 static struct ipv4_devconf ipv4_devconf_dflt = {
102811 .data = {
102812- [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
102813+ [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 0,
102814+ [IPV4_DEVCONF_RP_FILTER - 1] = 1,
102815 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
102816 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
102817 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
102818@@ -1548,7 +1550,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
102819 idx = 0;
102820 head = &net->dev_index_head[h];
102821 rcu_read_lock();
102822- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102823+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102824 net->dev_base_seq;
102825 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102826 if (idx < s_idx)
102827@@ -1866,7 +1868,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
102828 idx = 0;
102829 head = &net->dev_index_head[h];
102830 rcu_read_lock();
102831- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102832+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102833 net->dev_base_seq;
102834 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102835 if (idx < s_idx)
102836@@ -2101,7 +2103,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
102837 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
102838 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
102839
102840-static struct devinet_sysctl_table {
102841+static const struct devinet_sysctl_table {
102842 struct ctl_table_header *sysctl_header;
102843 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
102844 } devinet_sysctl = {
102845@@ -2233,7 +2235,7 @@ static __net_init int devinet_init_net(struct net *net)
102846 int err;
102847 struct ipv4_devconf *all, *dflt;
102848 #ifdef CONFIG_SYSCTL
102849- struct ctl_table *tbl = ctl_forward_entry;
102850+ ctl_table_no_const *tbl = NULL;
102851 struct ctl_table_header *forw_hdr;
102852 #endif
102853
102854@@ -2251,7 +2253,7 @@ static __net_init int devinet_init_net(struct net *net)
102855 goto err_alloc_dflt;
102856
102857 #ifdef CONFIG_SYSCTL
102858- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
102859+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
102860 if (tbl == NULL)
102861 goto err_alloc_ctl;
102862
102863@@ -2271,7 +2273,10 @@ static __net_init int devinet_init_net(struct net *net)
102864 goto err_reg_dflt;
102865
102866 err = -ENOMEM;
102867- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102868+ if (!net_eq(net, &init_net))
102869+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102870+ else
102871+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
102872 if (forw_hdr == NULL)
102873 goto err_reg_ctl;
102874 net->ipv4.forw_hdr = forw_hdr;
102875@@ -2287,8 +2292,7 @@ err_reg_ctl:
102876 err_reg_dflt:
102877 __devinet_sysctl_unregister(all);
102878 err_reg_all:
102879- if (tbl != ctl_forward_entry)
102880- kfree(tbl);
102881+ kfree(tbl);
102882 err_alloc_ctl:
102883 #endif
102884 if (dflt != &ipv4_devconf_dflt)
102885diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
102886index 255aa99..45c78f8 100644
102887--- a/net/ipv4/fib_frontend.c
102888+++ b/net/ipv4/fib_frontend.c
102889@@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
102890 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102891 fib_sync_up(dev);
102892 #endif
102893- atomic_inc(&net->ipv4.dev_addr_genid);
102894+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102895 rt_cache_flush(dev_net(dev));
102896 break;
102897 case NETDEV_DOWN:
102898 fib_del_ifaddr(ifa, NULL);
102899- atomic_inc(&net->ipv4.dev_addr_genid);
102900+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102901 if (ifa->ifa_dev->ifa_list == NULL) {
102902 /* Last address was deleted from this interface.
102903 * Disable IP.
102904@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
102905 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102906 fib_sync_up(dev);
102907 #endif
102908- atomic_inc(&net->ipv4.dev_addr_genid);
102909+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102910 rt_cache_flush(net);
102911 break;
102912 case NETDEV_DOWN:
102913diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
102914index 4a74ea8..32335a7 100644
102915--- a/net/ipv4/fib_semantics.c
102916+++ b/net/ipv4/fib_semantics.c
102917@@ -768,7 +768,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
102918 nh->nh_saddr = inet_select_addr(nh->nh_dev,
102919 nh->nh_gw,
102920 nh->nh_parent->fib_scope);
102921- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
102922+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
102923
102924 return nh->nh_saddr;
102925 }
102926diff --git a/net/ipv4/gre_offload.c b/net/ipv4/gre_offload.c
102927index dd73bea..a2eec02 100644
102928--- a/net/ipv4/gre_offload.c
102929+++ b/net/ipv4/gre_offload.c
102930@@ -59,13 +59,13 @@ static struct sk_buff *gre_gso_segment(struct sk_buff *skb,
102931 if (csum)
102932 skb->encap_hdr_csum = 1;
102933
102934- if (unlikely(!pskb_may_pull(skb, ghl)))
102935- goto out;
102936-
102937 /* setup inner skb. */
102938 skb->protocol = greh->protocol;
102939 skb->encapsulation = 0;
102940
102941+ if (unlikely(!pskb_may_pull(skb, ghl)))
102942+ goto out;
102943+
102944 __skb_pull(skb, ghl);
102945 skb_reset_mac_header(skb);
102946 skb_set_network_header(skb, skb_inner_network_offset(skb));
102947diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
102948index 43116e8..ba0916a8 100644
102949--- a/net/ipv4/inet_hashtables.c
102950+++ b/net/ipv4/inet_hashtables.c
102951@@ -18,6 +18,7 @@
102952 #include <linux/sched.h>
102953 #include <linux/slab.h>
102954 #include <linux/wait.h>
102955+#include <linux/security.h>
102956
102957 #include <net/inet_connection_sock.h>
102958 #include <net/inet_hashtables.h>
102959@@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
102960 return inet_ehashfn(net, laddr, lport, faddr, fport);
102961 }
102962
102963+extern void gr_update_task_in_ip_table(const struct inet_sock *inet);
102964+
102965 /*
102966 * Allocate and initialize a new local port bind bucket.
102967 * The bindhash mutex for snum's hash chain must be held here.
102968@@ -554,6 +557,8 @@ ok:
102969 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
102970 spin_unlock(&head->lock);
102971
102972+ gr_update_task_in_ip_table(inet_sk(sk));
102973+
102974 if (tw) {
102975 inet_twsk_deschedule(tw, death_row);
102976 while (twrefcnt) {
102977diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
102978index bd5f592..e80e605 100644
102979--- a/net/ipv4/inetpeer.c
102980+++ b/net/ipv4/inetpeer.c
102981@@ -482,7 +482,7 @@ relookup:
102982 if (p) {
102983 p->daddr = *daddr;
102984 atomic_set(&p->refcnt, 1);
102985- atomic_set(&p->rid, 0);
102986+ atomic_set_unchecked(&p->rid, 0);
102987 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
102988 p->rate_tokens = 0;
102989 /* 60*HZ is arbitrary, but chosen enough high so that the first
102990diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
102991index 15f0e2b..8cf8177 100644
102992--- a/net/ipv4/ip_fragment.c
102993+++ b/net/ipv4/ip_fragment.c
102994@@ -268,7 +268,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
102995 return 0;
102996
102997 start = qp->rid;
102998- end = atomic_inc_return(&peer->rid);
102999+ end = atomic_inc_return_unchecked(&peer->rid);
103000 qp->rid = end;
103001
103002 rc = qp->q.fragments && (end - start) > max;
103003@@ -746,12 +746,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
103004
103005 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
103006 {
103007- struct ctl_table *table;
103008+ ctl_table_no_const *table = NULL;
103009 struct ctl_table_header *hdr;
103010
103011- table = ip4_frags_ns_ctl_table;
103012 if (!net_eq(net, &init_net)) {
103013- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
103014+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
103015 if (table == NULL)
103016 goto err_alloc;
103017
103018@@ -765,9 +764,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
103019 /* Don't export sysctls to unprivileged users */
103020 if (net->user_ns != &init_user_ns)
103021 table[0].procname = NULL;
103022- }
103023+ hdr = register_net_sysctl(net, "net/ipv4", table);
103024+ } else
103025+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
103026
103027- hdr = register_net_sysctl(net, "net/ipv4", table);
103028 if (hdr == NULL)
103029 goto err_reg;
103030
103031@@ -775,8 +775,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
103032 return 0;
103033
103034 err_reg:
103035- if (!net_eq(net, &init_net))
103036- kfree(table);
103037+ kfree(table);
103038 err_alloc:
103039 return -ENOMEM;
103040 }
103041diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
103042index 9b84254..c776611 100644
103043--- a/net/ipv4/ip_gre.c
103044+++ b/net/ipv4/ip_gre.c
103045@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
103046 module_param(log_ecn_error, bool, 0644);
103047 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
103048
103049-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
103050+static struct rtnl_link_ops ipgre_link_ops;
103051 static int ipgre_tunnel_init(struct net_device *dev);
103052
103053 static int ipgre_net_id __read_mostly;
103054@@ -733,7 +733,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
103055 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
103056 };
103057
103058-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
103059+static struct rtnl_link_ops ipgre_link_ops = {
103060 .kind = "gre",
103061 .maxtype = IFLA_GRE_MAX,
103062 .policy = ipgre_policy,
103063@@ -747,7 +747,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
103064 .fill_info = ipgre_fill_info,
103065 };
103066
103067-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
103068+static struct rtnl_link_ops ipgre_tap_ops = {
103069 .kind = "gretap",
103070 .maxtype = IFLA_GRE_MAX,
103071 .policy = ipgre_policy,
103072diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
103073index 3d4da2c..40f9c29 100644
103074--- a/net/ipv4/ip_input.c
103075+++ b/net/ipv4/ip_input.c
103076@@ -147,6 +147,10 @@
103077 #include <linux/mroute.h>
103078 #include <linux/netlink.h>
103079
103080+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103081+extern int grsec_enable_blackhole;
103082+#endif
103083+
103084 /*
103085 * Process Router Attention IP option (RFC 2113)
103086 */
103087@@ -223,6 +227,9 @@ static int ip_local_deliver_finish(struct sk_buff *skb)
103088 if (!raw) {
103089 if (xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
103090 IP_INC_STATS_BH(net, IPSTATS_MIB_INUNKNOWNPROTOS);
103091+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103092+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
103093+#endif
103094 icmp_send(skb, ICMP_DEST_UNREACH,
103095 ICMP_PROT_UNREACH, 0);
103096 }
103097diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
103098index c43a1e2..73cbbe1 100644
103099--- a/net/ipv4/ip_output.c
103100+++ b/net/ipv4/ip_output.c
103101@@ -231,7 +231,7 @@ static int ip_finish_output_gso(struct sk_buff *skb)
103102 */
103103 features = netif_skb_features(skb);
103104 segs = skb_gso_segment(skb, features & ~NETIF_F_GSO_MASK);
103105- if (IS_ERR(segs)) {
103106+ if (IS_ERR_OR_NULL(segs)) {
103107 kfree_skb(skb);
103108 return -ENOMEM;
103109 }
103110diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
103111index 2407e5d..edc2f1a 100644
103112--- a/net/ipv4/ip_sockglue.c
103113+++ b/net/ipv4/ip_sockglue.c
103114@@ -1188,7 +1188,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
103115 len = min_t(unsigned int, len, opt->optlen);
103116 if (put_user(len, optlen))
103117 return -EFAULT;
103118- if (copy_to_user(optval, opt->__data, len))
103119+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
103120+ copy_to_user(optval, opt->__data, len))
103121 return -EFAULT;
103122 return 0;
103123 }
103124@@ -1319,7 +1320,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
103125 if (sk->sk_type != SOCK_STREAM)
103126 return -ENOPROTOOPT;
103127
103128- msg.msg_control = (__force void *) optval;
103129+ msg.msg_control = (__force_kernel void *) optval;
103130 msg.msg_controllen = len;
103131 msg.msg_flags = flags;
103132
103133diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
103134index e453cb7..3c8d952 100644
103135--- a/net/ipv4/ip_vti.c
103136+++ b/net/ipv4/ip_vti.c
103137@@ -45,7 +45,7 @@
103138 #include <net/net_namespace.h>
103139 #include <net/netns/generic.h>
103140
103141-static struct rtnl_link_ops vti_link_ops __read_mostly;
103142+static struct rtnl_link_ops vti_link_ops;
103143
103144 static int vti_net_id __read_mostly;
103145 static int vti_tunnel_init(struct net_device *dev);
103146@@ -519,7 +519,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
103147 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
103148 };
103149
103150-static struct rtnl_link_ops vti_link_ops __read_mostly = {
103151+static struct rtnl_link_ops vti_link_ops = {
103152 .kind = "vti",
103153 .maxtype = IFLA_VTI_MAX,
103154 .policy = vti_policy,
103155diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
103156index 5bbef4f..5bc4fb6 100644
103157--- a/net/ipv4/ipconfig.c
103158+++ b/net/ipv4/ipconfig.c
103159@@ -332,7 +332,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
103160
103161 mm_segment_t oldfs = get_fs();
103162 set_fs(get_ds());
103163- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
103164+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
103165 set_fs(oldfs);
103166 return res;
103167 }
103168@@ -343,7 +343,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
103169
103170 mm_segment_t oldfs = get_fs();
103171 set_fs(get_ds());
103172- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
103173+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
103174 set_fs(oldfs);
103175 return res;
103176 }
103177@@ -354,7 +354,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
103178
103179 mm_segment_t oldfs = get_fs();
103180 set_fs(get_ds());
103181- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
103182+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
103183 set_fs(oldfs);
103184 return res;
103185 }
103186diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
103187index 62eaa00..29b2dc2 100644
103188--- a/net/ipv4/ipip.c
103189+++ b/net/ipv4/ipip.c
103190@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
103191 static int ipip_net_id __read_mostly;
103192
103193 static int ipip_tunnel_init(struct net_device *dev);
103194-static struct rtnl_link_ops ipip_link_ops __read_mostly;
103195+static struct rtnl_link_ops ipip_link_ops;
103196
103197 static int ipip_err(struct sk_buff *skb, u32 info)
103198 {
103199@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
103200 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
103201 };
103202
103203-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
103204+static struct rtnl_link_ops ipip_link_ops = {
103205 .kind = "ipip",
103206 .maxtype = IFLA_IPTUN_MAX,
103207 .policy = ipip_policy,
103208diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
103209index f95b6f9..2ee2097 100644
103210--- a/net/ipv4/netfilter/arp_tables.c
103211+++ b/net/ipv4/netfilter/arp_tables.c
103212@@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
103213 #endif
103214
103215 static int get_info(struct net *net, void __user *user,
103216- const int *len, int compat)
103217+ int len, int compat)
103218 {
103219 char name[XT_TABLE_MAXNAMELEN];
103220 struct xt_table *t;
103221 int ret;
103222
103223- if (*len != sizeof(struct arpt_getinfo)) {
103224- duprintf("length %u != %Zu\n", *len,
103225+ if (len != sizeof(struct arpt_getinfo)) {
103226+ duprintf("length %u != %Zu\n", len,
103227 sizeof(struct arpt_getinfo));
103228 return -EINVAL;
103229 }
103230@@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
103231 info.size = private->size;
103232 strcpy(info.name, name);
103233
103234- if (copy_to_user(user, &info, *len) != 0)
103235+ if (copy_to_user(user, &info, len) != 0)
103236 ret = -EFAULT;
103237 else
103238 ret = 0;
103239@@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
103240
103241 switch (cmd) {
103242 case ARPT_SO_GET_INFO:
103243- ret = get_info(sock_net(sk), user, len, 1);
103244+ ret = get_info(sock_net(sk), user, *len, 1);
103245 break;
103246 case ARPT_SO_GET_ENTRIES:
103247 ret = compat_get_entries(sock_net(sk), user, len);
103248@@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
103249
103250 switch (cmd) {
103251 case ARPT_SO_GET_INFO:
103252- ret = get_info(sock_net(sk), user, len, 0);
103253+ ret = get_info(sock_net(sk), user, *len, 0);
103254 break;
103255
103256 case ARPT_SO_GET_ENTRIES:
103257diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
103258index 99e810f..3711b81 100644
103259--- a/net/ipv4/netfilter/ip_tables.c
103260+++ b/net/ipv4/netfilter/ip_tables.c
103261@@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
103262 #endif
103263
103264 static int get_info(struct net *net, void __user *user,
103265- const int *len, int compat)
103266+ int len, int compat)
103267 {
103268 char name[XT_TABLE_MAXNAMELEN];
103269 struct xt_table *t;
103270 int ret;
103271
103272- if (*len != sizeof(struct ipt_getinfo)) {
103273- duprintf("length %u != %zu\n", *len,
103274+ if (len != sizeof(struct ipt_getinfo)) {
103275+ duprintf("length %u != %zu\n", len,
103276 sizeof(struct ipt_getinfo));
103277 return -EINVAL;
103278 }
103279@@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
103280 info.size = private->size;
103281 strcpy(info.name, name);
103282
103283- if (copy_to_user(user, &info, *len) != 0)
103284+ if (copy_to_user(user, &info, len) != 0)
103285 ret = -EFAULT;
103286 else
103287 ret = 0;
103288@@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103289
103290 switch (cmd) {
103291 case IPT_SO_GET_INFO:
103292- ret = get_info(sock_net(sk), user, len, 1);
103293+ ret = get_info(sock_net(sk), user, *len, 1);
103294 break;
103295 case IPT_SO_GET_ENTRIES:
103296 ret = compat_get_entries(sock_net(sk), user, len);
103297@@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103298
103299 switch (cmd) {
103300 case IPT_SO_GET_INFO:
103301- ret = get_info(sock_net(sk), user, len, 0);
103302+ ret = get_info(sock_net(sk), user, *len, 0);
103303 break;
103304
103305 case IPT_SO_GET_ENTRIES:
103306diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
103307index 2510c02..cfb34fa 100644
103308--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
103309+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
103310@@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
103311 spin_lock_init(&cn->lock);
103312
103313 #ifdef CONFIG_PROC_FS
103314- cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
103315+ cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
103316 if (!cn->procdir) {
103317 pr_err("Unable to proc dir entry\n");
103318 return -ENOMEM;
103319diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
103320index 3524762..2e88bfd 100644
103321--- a/net/ipv4/ping.c
103322+++ b/net/ipv4/ping.c
103323@@ -59,7 +59,7 @@ struct ping_table {
103324 };
103325
103326 static struct ping_table ping_table;
103327-struct pingv6_ops pingv6_ops;
103328+struct pingv6_ops *pingv6_ops;
103329 EXPORT_SYMBOL_GPL(pingv6_ops);
103330
103331 static u16 ping_port_rover;
103332@@ -350,7 +350,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
103333 return -ENODEV;
103334 }
103335 }
103336- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
103337+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
103338 scoped);
103339 rcu_read_unlock();
103340
103341@@ -558,7 +558,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
103342 }
103343 #if IS_ENABLED(CONFIG_IPV6)
103344 } else if (skb->protocol == htons(ETH_P_IPV6)) {
103345- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
103346+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
103347 #endif
103348 }
103349
103350@@ -576,7 +576,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
103351 info, (u8 *)icmph);
103352 #if IS_ENABLED(CONFIG_IPV6)
103353 } else if (family == AF_INET6) {
103354- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
103355+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
103356 info, (u8 *)icmph);
103357 #endif
103358 }
103359@@ -860,7 +860,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
103360 return ip_recv_error(sk, msg, len, addr_len);
103361 #if IS_ENABLED(CONFIG_IPV6)
103362 } else if (family == AF_INET6) {
103363- return pingv6_ops.ipv6_recv_error(sk, msg, len,
103364+ return pingv6_ops->ipv6_recv_error(sk, msg, len,
103365 addr_len);
103366 #endif
103367 }
103368@@ -918,10 +918,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
103369 }
103370
103371 if (inet6_sk(sk)->rxopt.all)
103372- pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
103373+ pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
103374 if (skb->protocol == htons(ETH_P_IPV6) &&
103375 inet6_sk(sk)->rxopt.all)
103376- pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
103377+ pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
103378 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
103379 ip_cmsg_recv(msg, skb);
103380 #endif
103381@@ -1113,7 +1113,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
103382 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
103383 0, sock_i_ino(sp),
103384 atomic_read(&sp->sk_refcnt), sp,
103385- atomic_read(&sp->sk_drops));
103386+ atomic_read_unchecked(&sp->sk_drops));
103387 }
103388
103389 static int ping_v4_seq_show(struct seq_file *seq, void *v)
103390diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
103391index 739db31..74f0210 100644
103392--- a/net/ipv4/raw.c
103393+++ b/net/ipv4/raw.c
103394@@ -314,7 +314,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
103395 int raw_rcv(struct sock *sk, struct sk_buff *skb)
103396 {
103397 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
103398- atomic_inc(&sk->sk_drops);
103399+ atomic_inc_unchecked(&sk->sk_drops);
103400 kfree_skb(skb);
103401 return NET_RX_DROP;
103402 }
103403@@ -755,16 +755,20 @@ static int raw_init(struct sock *sk)
103404
103405 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
103406 {
103407+ struct icmp_filter filter;
103408+
103409 if (optlen > sizeof(struct icmp_filter))
103410 optlen = sizeof(struct icmp_filter);
103411- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
103412+ if (copy_from_user(&filter, optval, optlen))
103413 return -EFAULT;
103414+ raw_sk(sk)->filter = filter;
103415 return 0;
103416 }
103417
103418 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
103419 {
103420 int len, ret = -EFAULT;
103421+ struct icmp_filter filter;
103422
103423 if (get_user(len, optlen))
103424 goto out;
103425@@ -774,8 +778,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
103426 if (len > sizeof(struct icmp_filter))
103427 len = sizeof(struct icmp_filter);
103428 ret = -EFAULT;
103429- if (put_user(len, optlen) ||
103430- copy_to_user(optval, &raw_sk(sk)->filter, len))
103431+ filter = raw_sk(sk)->filter;
103432+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
103433 goto out;
103434 ret = 0;
103435 out: return ret;
103436@@ -1004,7 +1008,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
103437 0, 0L, 0,
103438 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
103439 0, sock_i_ino(sp),
103440- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
103441+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
103442 }
103443
103444 static int raw_seq_show(struct seq_file *seq, void *v)
103445diff --git a/net/ipv4/route.c b/net/ipv4/route.c
103446index 29836f8..bd1e2ba 100644
103447--- a/net/ipv4/route.c
103448+++ b/net/ipv4/route.c
103449@@ -228,7 +228,7 @@ static const struct seq_operations rt_cache_seq_ops = {
103450
103451 static int rt_cache_seq_open(struct inode *inode, struct file *file)
103452 {
103453- return seq_open(file, &rt_cache_seq_ops);
103454+ return seq_open_restrict(file, &rt_cache_seq_ops);
103455 }
103456
103457 static const struct file_operations rt_cache_seq_fops = {
103458@@ -319,7 +319,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
103459
103460 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
103461 {
103462- return seq_open(file, &rt_cpu_seq_ops);
103463+ return seq_open_restrict(file, &rt_cpu_seq_ops);
103464 }
103465
103466 static const struct file_operations rt_cpu_seq_fops = {
103467@@ -357,7 +357,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
103468
103469 static int rt_acct_proc_open(struct inode *inode, struct file *file)
103470 {
103471- return single_open(file, rt_acct_proc_show, NULL);
103472+ return single_open_restrict(file, rt_acct_proc_show, NULL);
103473 }
103474
103475 static const struct file_operations rt_acct_proc_fops = {
103476@@ -459,11 +459,11 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
103477
103478 #define IP_IDENTS_SZ 2048u
103479 struct ip_ident_bucket {
103480- atomic_t id;
103481+ atomic_unchecked_t id;
103482 u32 stamp32;
103483 };
103484
103485-static struct ip_ident_bucket *ip_idents __read_mostly;
103486+static struct ip_ident_bucket ip_idents[IP_IDENTS_SZ] __read_mostly;
103487
103488 /* In order to protect privacy, we add a perturbation to identifiers
103489 * if one generator is seldom used. This makes hard for an attacker
103490@@ -479,7 +479,7 @@ u32 ip_idents_reserve(u32 hash, int segs)
103491 if (old != now && cmpxchg(&bucket->stamp32, old, now) == old)
103492 delta = prandom_u32_max(now - old);
103493
103494- return atomic_add_return(segs + delta, &bucket->id) - segs;
103495+ return atomic_add_return_unchecked(segs + delta, &bucket->id) - segs;
103496 }
103497 EXPORT_SYMBOL(ip_idents_reserve);
103498
103499@@ -2624,34 +2624,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
103500 .maxlen = sizeof(int),
103501 .mode = 0200,
103502 .proc_handler = ipv4_sysctl_rtcache_flush,
103503+ .extra1 = &init_net,
103504 },
103505 { },
103506 };
103507
103508 static __net_init int sysctl_route_net_init(struct net *net)
103509 {
103510- struct ctl_table *tbl;
103511+ ctl_table_no_const *tbl = NULL;
103512
103513- tbl = ipv4_route_flush_table;
103514 if (!net_eq(net, &init_net)) {
103515- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
103516+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
103517 if (tbl == NULL)
103518 goto err_dup;
103519
103520 /* Don't export sysctls to unprivileged users */
103521 if (net->user_ns != &init_user_ns)
103522 tbl[0].procname = NULL;
103523- }
103524- tbl[0].extra1 = net;
103525+ tbl[0].extra1 = net;
103526+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
103527+ } else
103528+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
103529
103530- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
103531 if (net->ipv4.route_hdr == NULL)
103532 goto err_reg;
103533 return 0;
103534
103535 err_reg:
103536- if (tbl != ipv4_route_flush_table)
103537- kfree(tbl);
103538+ kfree(tbl);
103539 err_dup:
103540 return -ENOMEM;
103541 }
103542@@ -2674,8 +2674,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
103543
103544 static __net_init int rt_genid_init(struct net *net)
103545 {
103546- atomic_set(&net->ipv4.rt_genid, 0);
103547- atomic_set(&net->fnhe_genid, 0);
103548+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
103549+ atomic_set_unchecked(&net->fnhe_genid, 0);
103550 get_random_bytes(&net->ipv4.dev_addr_genid,
103551 sizeof(net->ipv4.dev_addr_genid));
103552 return 0;
103553@@ -2718,11 +2718,7 @@ int __init ip_rt_init(void)
103554 {
103555 int rc = 0;
103556
103557- ip_idents = kmalloc(IP_IDENTS_SZ * sizeof(*ip_idents), GFP_KERNEL);
103558- if (!ip_idents)
103559- panic("IP: failed to allocate ip_idents\n");
103560-
103561- prandom_bytes(ip_idents, IP_IDENTS_SZ * sizeof(*ip_idents));
103562+ prandom_bytes(ip_idents, sizeof(ip_idents));
103563
103564 #ifdef CONFIG_IP_ROUTE_CLASSID
103565 ip_rt_acct = __alloc_percpu(256 * sizeof(struct ip_rt_acct), __alignof__(struct ip_rt_acct));
103566diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
103567index 79a007c..5023029 100644
103568--- a/net/ipv4/sysctl_net_ipv4.c
103569+++ b/net/ipv4/sysctl_net_ipv4.c
103570@@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
103571 container_of(table->data, struct net, ipv4.ip_local_ports.range);
103572 int ret;
103573 int range[2];
103574- struct ctl_table tmp = {
103575+ ctl_table_no_const tmp = {
103576 .data = &range,
103577 .maxlen = sizeof(range),
103578 .mode = table->mode,
103579@@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
103580 int ret;
103581 gid_t urange[2];
103582 kgid_t low, high;
103583- struct ctl_table tmp = {
103584+ ctl_table_no_const tmp = {
103585 .data = &urange,
103586 .maxlen = sizeof(urange),
103587 .mode = table->mode,
103588@@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
103589 void __user *buffer, size_t *lenp, loff_t *ppos)
103590 {
103591 char val[TCP_CA_NAME_MAX];
103592- struct ctl_table tbl = {
103593+ ctl_table_no_const tbl = {
103594 .data = val,
103595 .maxlen = TCP_CA_NAME_MAX,
103596 };
103597@@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
103598 void __user *buffer, size_t *lenp,
103599 loff_t *ppos)
103600 {
103601- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
103602+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
103603 int ret;
103604
103605 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
103606@@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
103607 void __user *buffer, size_t *lenp,
103608 loff_t *ppos)
103609 {
103610- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
103611+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
103612 int ret;
103613
103614 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
103615@@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
103616 void __user *buffer, size_t *lenp,
103617 loff_t *ppos)
103618 {
103619- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
103620+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
103621 struct tcp_fastopen_context *ctxt;
103622 int ret;
103623 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
103624@@ -857,13 +857,12 @@ static struct ctl_table ipv4_net_table[] = {
103625
103626 static __net_init int ipv4_sysctl_init_net(struct net *net)
103627 {
103628- struct ctl_table *table;
103629+ ctl_table_no_const *table = NULL;
103630
103631- table = ipv4_net_table;
103632 if (!net_eq(net, &init_net)) {
103633 int i;
103634
103635- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
103636+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
103637 if (table == NULL)
103638 goto err_alloc;
103639
103640@@ -872,7 +871,10 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
103641 table[i].data += (void *)net - (void *)&init_net;
103642 }
103643
103644- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
103645+ if (!net_eq(net, &init_net))
103646+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
103647+ else
103648+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
103649 if (net->ipv4.ipv4_hdr == NULL)
103650 goto err_reg;
103651
103652diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
103653index a906e02..f3b6a0f 100644
103654--- a/net/ipv4/tcp_input.c
103655+++ b/net/ipv4/tcp_input.c
103656@@ -755,7 +755,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
103657 * without any lock. We want to make sure compiler wont store
103658 * intermediate values in this location.
103659 */
103660- ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
103661+ ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
103662 sk->sk_max_pacing_rate);
103663 }
103664
103665@@ -4488,7 +4488,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
103666 * simplifies code)
103667 */
103668 static void
103669-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
103670+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
103671 struct sk_buff *head, struct sk_buff *tail,
103672 u32 start, u32 end)
103673 {
103674@@ -5546,6 +5546,7 @@ discard:
103675 tcp_paws_reject(&tp->rx_opt, 0))
103676 goto discard_and_undo;
103677
103678+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
103679 if (th->syn) {
103680 /* We see SYN without ACK. It is attempt of
103681 * simultaneous connect with crossed SYNs.
103682@@ -5596,6 +5597,7 @@ discard:
103683 goto discard;
103684 #endif
103685 }
103686+#endif
103687 /* "fifth, if neither of the SYN or RST bits is set then
103688 * drop the segment and return."
103689 */
103690@@ -5642,7 +5644,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
103691 goto discard;
103692
103693 if (th->syn) {
103694- if (th->fin)
103695+ if (th->fin || th->urg || th->psh)
103696 goto discard;
103697 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
103698 return 1;
103699diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
103700index 3f49eae..bde687a 100644
103701--- a/net/ipv4/tcp_ipv4.c
103702+++ b/net/ipv4/tcp_ipv4.c
103703@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
103704 EXPORT_SYMBOL(sysctl_tcp_low_latency);
103705
103706
103707+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103708+extern int grsec_enable_blackhole;
103709+#endif
103710+
103711 #ifdef CONFIG_TCP_MD5SIG
103712 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
103713 __be32 daddr, __be32 saddr, const struct tcphdr *th);
103714@@ -1487,6 +1491,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
103715 return 0;
103716
103717 reset:
103718+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103719+ if (!grsec_enable_blackhole)
103720+#endif
103721 tcp_v4_send_reset(rsk, skb);
103722 discard:
103723 kfree_skb(skb);
103724@@ -1633,12 +1640,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
103725 TCP_SKB_CB(skb)->sacked = 0;
103726
103727 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
103728- if (!sk)
103729+ if (!sk) {
103730+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103731+ ret = 1;
103732+#endif
103733 goto no_tcp_socket;
103734-
103735+ }
103736 process:
103737- if (sk->sk_state == TCP_TIME_WAIT)
103738+ if (sk->sk_state == TCP_TIME_WAIT) {
103739+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103740+ ret = 2;
103741+#endif
103742 goto do_time_wait;
103743+ }
103744
103745 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
103746 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
103747@@ -1704,6 +1718,10 @@ csum_error:
103748 bad_packet:
103749 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
103750 } else {
103751+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103752+ if (!grsec_enable_blackhole || (ret == 1 &&
103753+ (skb->dev->flags & IFF_LOOPBACK)))
103754+#endif
103755 tcp_v4_send_reset(NULL, skb);
103756 }
103757
103758diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
103759index 1649988..6251843 100644
103760--- a/net/ipv4/tcp_minisocks.c
103761+++ b/net/ipv4/tcp_minisocks.c
103762@@ -27,6 +27,10 @@
103763 #include <net/inet_common.h>
103764 #include <net/xfrm.h>
103765
103766+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103767+extern int grsec_enable_blackhole;
103768+#endif
103769+
103770 int sysctl_tcp_syncookies __read_mostly = 1;
103771 EXPORT_SYMBOL(sysctl_tcp_syncookies);
103772
103773@@ -740,7 +744,10 @@ embryonic_reset:
103774 * avoid becoming vulnerable to outside attack aiming at
103775 * resetting legit local connections.
103776 */
103777- req->rsk_ops->send_reset(sk, skb);
103778+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103779+ if (!grsec_enable_blackhole)
103780+#endif
103781+ req->rsk_ops->send_reset(sk, skb);
103782 } else if (fastopen) { /* received a valid RST pkt */
103783 reqsk_fastopen_remove(sk, req, true);
103784 tcp_reset(sk);
103785diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
103786index 3b66610..bfbe23a 100644
103787--- a/net/ipv4/tcp_probe.c
103788+++ b/net/ipv4/tcp_probe.c
103789@@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
103790 if (cnt + width >= len)
103791 break;
103792
103793- if (copy_to_user(buf + cnt, tbuf, width))
103794+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
103795 return -EFAULT;
103796 cnt += width;
103797 }
103798diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
103799index df90cd1..9ab2c9b 100644
103800--- a/net/ipv4/tcp_timer.c
103801+++ b/net/ipv4/tcp_timer.c
103802@@ -22,6 +22,10 @@
103803 #include <linux/gfp.h>
103804 #include <net/tcp.h>
103805
103806+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103807+extern int grsec_lastack_retries;
103808+#endif
103809+
103810 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
103811 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
103812 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
103813@@ -192,6 +196,13 @@ static int tcp_write_timeout(struct sock *sk)
103814 }
103815 }
103816
103817+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103818+ if ((sk->sk_state == TCP_LAST_ACK) &&
103819+ (grsec_lastack_retries > 0) &&
103820+ (grsec_lastack_retries < retry_until))
103821+ retry_until = grsec_lastack_retries;
103822+#endif
103823+
103824 if (retransmits_timed_out(sk, retry_until,
103825 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
103826 /* Has it gone just too far? */
103827diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
103828index f57c0e4..cf24bd0 100644
103829--- a/net/ipv4/udp.c
103830+++ b/net/ipv4/udp.c
103831@@ -87,6 +87,7 @@
103832 #include <linux/types.h>
103833 #include <linux/fcntl.h>
103834 #include <linux/module.h>
103835+#include <linux/security.h>
103836 #include <linux/socket.h>
103837 #include <linux/sockios.h>
103838 #include <linux/igmp.h>
103839@@ -113,6 +114,10 @@
103840 #include <net/busy_poll.h>
103841 #include "udp_impl.h"
103842
103843+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103844+extern int grsec_enable_blackhole;
103845+#endif
103846+
103847 struct udp_table udp_table __read_mostly;
103848 EXPORT_SYMBOL(udp_table);
103849
103850@@ -594,6 +599,9 @@ static inline bool __udp_is_mcast_sock(struct net *net, struct sock *sk,
103851 return true;
103852 }
103853
103854+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
103855+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
103856+
103857 /*
103858 * This routine is called by the ICMP module when it gets some
103859 * sort of error condition. If err < 0 then the socket should
103860@@ -931,9 +939,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
103861 dport = usin->sin_port;
103862 if (dport == 0)
103863 return -EINVAL;
103864+
103865+ err = gr_search_udp_sendmsg(sk, usin);
103866+ if (err)
103867+ return err;
103868 } else {
103869 if (sk->sk_state != TCP_ESTABLISHED)
103870 return -EDESTADDRREQ;
103871+
103872+ err = gr_search_udp_sendmsg(sk, NULL);
103873+ if (err)
103874+ return err;
103875+
103876 daddr = inet->inet_daddr;
103877 dport = inet->inet_dport;
103878 /* Open fast path for connected socket.
103879@@ -1181,7 +1198,7 @@ static unsigned int first_packet_length(struct sock *sk)
103880 IS_UDPLITE(sk));
103881 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103882 IS_UDPLITE(sk));
103883- atomic_inc(&sk->sk_drops);
103884+ atomic_inc_unchecked(&sk->sk_drops);
103885 __skb_unlink(skb, rcvq);
103886 __skb_queue_tail(&list_kill, skb);
103887 }
103888@@ -1261,6 +1278,10 @@ try_again:
103889 if (!skb)
103890 goto out;
103891
103892+ err = gr_search_udp_recvmsg(sk, skb);
103893+ if (err)
103894+ goto out_free;
103895+
103896 ulen = skb->len - sizeof(struct udphdr);
103897 copied = len;
103898 if (copied > ulen)
103899@@ -1294,7 +1315,7 @@ try_again:
103900 if (unlikely(err)) {
103901 trace_kfree_skb(skb, udp_recvmsg);
103902 if (!peeked) {
103903- atomic_inc(&sk->sk_drops);
103904+ atomic_inc_unchecked(&sk->sk_drops);
103905 UDP_INC_STATS_USER(sock_net(sk),
103906 UDP_MIB_INERRORS, is_udplite);
103907 }
103908@@ -1591,7 +1612,7 @@ csum_error:
103909 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
103910 drop:
103911 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
103912- atomic_inc(&sk->sk_drops);
103913+ atomic_inc_unchecked(&sk->sk_drops);
103914 kfree_skb(skb);
103915 return -1;
103916 }
103917@@ -1610,7 +1631,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
103918 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
103919
103920 if (!skb1) {
103921- atomic_inc(&sk->sk_drops);
103922+ atomic_inc_unchecked(&sk->sk_drops);
103923 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
103924 IS_UDPLITE(sk));
103925 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103926@@ -1807,6 +1828,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
103927 goto csum_error;
103928
103929 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
103930+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103931+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
103932+#endif
103933 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
103934
103935 /*
103936@@ -2393,7 +2417,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
103937 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
103938 0, sock_i_ino(sp),
103939 atomic_read(&sp->sk_refcnt), sp,
103940- atomic_read(&sp->sk_drops));
103941+ atomic_read_unchecked(&sp->sk_drops));
103942 }
103943
103944 int udp4_seq_show(struct seq_file *seq, void *v)
103945diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
103946index 6156f68..d6ab46d 100644
103947--- a/net/ipv4/xfrm4_policy.c
103948+++ b/net/ipv4/xfrm4_policy.c
103949@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
103950 fl4->flowi4_tos = iph->tos;
103951 }
103952
103953-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
103954+static int xfrm4_garbage_collect(struct dst_ops *ops)
103955 {
103956 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
103957
103958- xfrm4_policy_afinfo.garbage_collect(net);
103959+ xfrm_garbage_collect_deferred(net);
103960 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
103961 }
103962
103963@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
103964
103965 static int __net_init xfrm4_net_init(struct net *net)
103966 {
103967- struct ctl_table *table;
103968+ ctl_table_no_const *table = NULL;
103969 struct ctl_table_header *hdr;
103970
103971- table = xfrm4_policy_table;
103972 if (!net_eq(net, &init_net)) {
103973- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103974+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103975 if (!table)
103976 goto err_alloc;
103977
103978 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
103979- }
103980-
103981- hdr = register_net_sysctl(net, "net/ipv4", table);
103982+ hdr = register_net_sysctl(net, "net/ipv4", table);
103983+ } else
103984+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
103985 if (!hdr)
103986 goto err_reg;
103987
103988@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
103989 return 0;
103990
103991 err_reg:
103992- if (!net_eq(net, &init_net))
103993- kfree(table);
103994+ kfree(table);
103995 err_alloc:
103996 return -ENOMEM;
103997 }
103998diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
103999index 3e118df..288a0d1 100644
104000--- a/net/ipv6/addrconf.c
104001+++ b/net/ipv6/addrconf.c
104002@@ -171,7 +171,7 @@ static struct ipv6_devconf ipv6_devconf __read_mostly = {
104003 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
104004 .mtu6 = IPV6_MIN_MTU,
104005 .accept_ra = 1,
104006- .accept_redirects = 1,
104007+ .accept_redirects = 0,
104008 .autoconf = 1,
104009 .force_mld_version = 0,
104010 .mldv1_unsolicited_report_interval = 10 * HZ,
104011@@ -208,7 +208,7 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
104012 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
104013 .mtu6 = IPV6_MIN_MTU,
104014 .accept_ra = 1,
104015- .accept_redirects = 1,
104016+ .accept_redirects = 0,
104017 .autoconf = 1,
104018 .force_mld_version = 0,
104019 .mldv1_unsolicited_report_interval = 10 * HZ,
104020@@ -604,7 +604,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
104021 idx = 0;
104022 head = &net->dev_index_head[h];
104023 rcu_read_lock();
104024- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
104025+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
104026 net->dev_base_seq;
104027 hlist_for_each_entry_rcu(dev, head, index_hlist) {
104028 if (idx < s_idx)
104029@@ -2396,7 +2396,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
104030 p.iph.ihl = 5;
104031 p.iph.protocol = IPPROTO_IPV6;
104032 p.iph.ttl = 64;
104033- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
104034+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
104035
104036 if (ops->ndo_do_ioctl) {
104037 mm_segment_t oldfs = get_fs();
104038@@ -3531,16 +3531,23 @@ static const struct file_operations if6_fops = {
104039 .release = seq_release_net,
104040 };
104041
104042+extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
104043+extern void unregister_ipv6_seq_ops_addr(void);
104044+
104045 static int __net_init if6_proc_net_init(struct net *net)
104046 {
104047- if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
104048+ register_ipv6_seq_ops_addr(&if6_seq_ops);
104049+ if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
104050+ unregister_ipv6_seq_ops_addr();
104051 return -ENOMEM;
104052+ }
104053 return 0;
104054 }
104055
104056 static void __net_exit if6_proc_net_exit(struct net *net)
104057 {
104058 remove_proc_entry("if_inet6", net->proc_net);
104059+ unregister_ipv6_seq_ops_addr();
104060 }
104061
104062 static struct pernet_operations if6_proc_net_ops = {
104063@@ -4156,7 +4163,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
104064 s_ip_idx = ip_idx = cb->args[2];
104065
104066 rcu_read_lock();
104067- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
104068+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
104069 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
104070 idx = 0;
104071 head = &net->dev_index_head[h];
104072@@ -4784,7 +4791,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
104073 rt_genid_bump_ipv6(net);
104074 break;
104075 }
104076- atomic_inc(&net->ipv6.dev_addr_genid);
104077+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
104078 }
104079
104080 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
104081@@ -4804,7 +4811,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
104082 int *valp = ctl->data;
104083 int val = *valp;
104084 loff_t pos = *ppos;
104085- struct ctl_table lctl;
104086+ ctl_table_no_const lctl;
104087 int ret;
104088
104089 /*
104090@@ -4889,7 +4896,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
104091 int *valp = ctl->data;
104092 int val = *valp;
104093 loff_t pos = *ppos;
104094- struct ctl_table lctl;
104095+ ctl_table_no_const lctl;
104096 int ret;
104097
104098 /*
104099diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
104100index 2daa3a1..341066c 100644
104101--- a/net/ipv6/af_inet6.c
104102+++ b/net/ipv6/af_inet6.c
104103@@ -766,7 +766,7 @@ static int __net_init inet6_net_init(struct net *net)
104104 net->ipv6.sysctl.icmpv6_time = 1*HZ;
104105 net->ipv6.sysctl.flowlabel_consistency = 1;
104106 net->ipv6.sysctl.auto_flowlabels = 0;
104107- atomic_set(&net->ipv6.rt_genid, 0);
104108+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
104109
104110 err = ipv6_init_mibs(net);
104111 if (err)
104112diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
104113index 2753319..b7e625c 100644
104114--- a/net/ipv6/datagram.c
104115+++ b/net/ipv6/datagram.c
104116@@ -939,5 +939,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
104117 0,
104118 sock_i_ino(sp),
104119 atomic_read(&sp->sk_refcnt), sp,
104120- atomic_read(&sp->sk_drops));
104121+ atomic_read_unchecked(&sp->sk_drops));
104122 }
104123diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
104124index 06ba3e5..5c08d38 100644
104125--- a/net/ipv6/icmp.c
104126+++ b/net/ipv6/icmp.c
104127@@ -993,7 +993,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
104128
104129 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
104130 {
104131- struct ctl_table *table;
104132+ ctl_table_no_const *table;
104133
104134 table = kmemdup(ipv6_icmp_table_template,
104135 sizeof(ipv6_icmp_table_template),
104136diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
104137index cacb493..3cae894 100644
104138--- a/net/ipv6/ip6_gre.c
104139+++ b/net/ipv6/ip6_gre.c
104140@@ -71,8 +71,8 @@ struct ip6gre_net {
104141 struct net_device *fb_tunnel_dev;
104142 };
104143
104144-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
104145-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly;
104146+static struct rtnl_link_ops ip6gre_link_ops;
104147+static struct rtnl_link_ops ip6gre_tap_ops;
104148 static int ip6gre_tunnel_init(struct net_device *dev);
104149 static void ip6gre_tunnel_setup(struct net_device *dev);
104150 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
104151@@ -1285,7 +1285,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
104152 }
104153
104154
104155-static struct inet6_protocol ip6gre_protocol __read_mostly = {
104156+static struct inet6_protocol ip6gre_protocol = {
104157 .handler = ip6gre_rcv,
104158 .err_handler = ip6gre_err,
104159 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
104160@@ -1646,7 +1646,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
104161 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
104162 };
104163
104164-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
104165+static struct rtnl_link_ops ip6gre_link_ops = {
104166 .kind = "ip6gre",
104167 .maxtype = IFLA_GRE_MAX,
104168 .policy = ip6gre_policy,
104169@@ -1660,7 +1660,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
104170 .fill_info = ip6gre_fill_info,
104171 };
104172
104173-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
104174+static struct rtnl_link_ops ip6gre_tap_ops = {
104175 .kind = "ip6gretap",
104176 .maxtype = IFLA_GRE_MAX,
104177 .policy = ip6gre_policy,
104178diff --git a/net/ipv6/ip6_offload.c b/net/ipv6/ip6_offload.c
104179index 65eda2a..620a102 100644
104180--- a/net/ipv6/ip6_offload.c
104181+++ b/net/ipv6/ip6_offload.c
104182@@ -46,6 +46,7 @@ static int ipv6_gso_pull_exthdrs(struct sk_buff *skb, int proto)
104183 if (unlikely(!pskb_may_pull(skb, len)))
104184 break;
104185
104186+ opth = (void *)skb->data;
104187 proto = opth->nexthdr;
104188 __skb_pull(skb, len);
104189 }
104190diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
104191index d2eeb3b..c186e9a 100644
104192--- a/net/ipv6/ip6_tunnel.c
104193+++ b/net/ipv6/ip6_tunnel.c
104194@@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
104195
104196 static int ip6_tnl_dev_init(struct net_device *dev);
104197 static void ip6_tnl_dev_setup(struct net_device *dev);
104198-static struct rtnl_link_ops ip6_link_ops __read_mostly;
104199+static struct rtnl_link_ops ip6_link_ops;
104200
104201 static int ip6_tnl_net_id __read_mostly;
104202 struct ip6_tnl_net {
104203@@ -1706,7 +1706,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
104204 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
104205 };
104206
104207-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
104208+static struct rtnl_link_ops ip6_link_ops = {
104209 .kind = "ip6tnl",
104210 .maxtype = IFLA_IPTUN_MAX,
104211 .policy = ip6_tnl_policy,
104212diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
104213index 99c9487..63f4d92 100644
104214--- a/net/ipv6/ip6_vti.c
104215+++ b/net/ipv6/ip6_vti.c
104216@@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
104217
104218 static int vti6_dev_init(struct net_device *dev);
104219 static void vti6_dev_setup(struct net_device *dev);
104220-static struct rtnl_link_ops vti6_link_ops __read_mostly;
104221+static struct rtnl_link_ops vti6_link_ops;
104222
104223 static int vti6_net_id __read_mostly;
104224 struct vti6_net {
104225@@ -972,7 +972,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
104226 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
104227 };
104228
104229-static struct rtnl_link_ops vti6_link_ops __read_mostly = {
104230+static struct rtnl_link_ops vti6_link_ops = {
104231 .kind = "vti6",
104232 .maxtype = IFLA_VTI_MAX,
104233 .policy = vti6_policy,
104234diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
104235index 0c28998..d0a2ecd 100644
104236--- a/net/ipv6/ipv6_sockglue.c
104237+++ b/net/ipv6/ipv6_sockglue.c
104238@@ -995,7 +995,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
104239 if (sk->sk_type != SOCK_STREAM)
104240 return -ENOPROTOOPT;
104241
104242- msg.msg_control = optval;
104243+ msg.msg_control = (void __force_kernel *)optval;
104244 msg.msg_controllen = len;
104245 msg.msg_flags = flags;
104246
104247diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
104248index e080fbb..412b3cf 100644
104249--- a/net/ipv6/netfilter/ip6_tables.c
104250+++ b/net/ipv6/netfilter/ip6_tables.c
104251@@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
104252 #endif
104253
104254 static int get_info(struct net *net, void __user *user,
104255- const int *len, int compat)
104256+ int len, int compat)
104257 {
104258 char name[XT_TABLE_MAXNAMELEN];
104259 struct xt_table *t;
104260 int ret;
104261
104262- if (*len != sizeof(struct ip6t_getinfo)) {
104263- duprintf("length %u != %zu\n", *len,
104264+ if (len != sizeof(struct ip6t_getinfo)) {
104265+ duprintf("length %u != %zu\n", len,
104266 sizeof(struct ip6t_getinfo));
104267 return -EINVAL;
104268 }
104269@@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
104270 info.size = private->size;
104271 strcpy(info.name, name);
104272
104273- if (copy_to_user(user, &info, *len) != 0)
104274+ if (copy_to_user(user, &info, len) != 0)
104275 ret = -EFAULT;
104276 else
104277 ret = 0;
104278@@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
104279
104280 switch (cmd) {
104281 case IP6T_SO_GET_INFO:
104282- ret = get_info(sock_net(sk), user, len, 1);
104283+ ret = get_info(sock_net(sk), user, *len, 1);
104284 break;
104285 case IP6T_SO_GET_ENTRIES:
104286 ret = compat_get_entries(sock_net(sk), user, len);
104287@@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
104288
104289 switch (cmd) {
104290 case IP6T_SO_GET_INFO:
104291- ret = get_info(sock_net(sk), user, len, 0);
104292+ ret = get_info(sock_net(sk), user, *len, 0);
104293 break;
104294
104295 case IP6T_SO_GET_ENTRIES:
104296diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
104297index 6f187c8..34b367f 100644
104298--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
104299+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
104300@@ -96,12 +96,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
104301
104302 static int nf_ct_frag6_sysctl_register(struct net *net)
104303 {
104304- struct ctl_table *table;
104305+ ctl_table_no_const *table = NULL;
104306 struct ctl_table_header *hdr;
104307
104308- table = nf_ct_frag6_sysctl_table;
104309 if (!net_eq(net, &init_net)) {
104310- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
104311+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
104312 GFP_KERNEL);
104313 if (table == NULL)
104314 goto err_alloc;
104315@@ -112,9 +111,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
104316 table[2].data = &net->nf_frag.frags.high_thresh;
104317 table[2].extra1 = &net->nf_frag.frags.low_thresh;
104318 table[2].extra2 = &init_net.nf_frag.frags.high_thresh;
104319- }
104320-
104321- hdr = register_net_sysctl(net, "net/netfilter", table);
104322+ hdr = register_net_sysctl(net, "net/netfilter", table);
104323+ } else
104324+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
104325 if (hdr == NULL)
104326 goto err_reg;
104327
104328@@ -122,8 +121,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
104329 return 0;
104330
104331 err_reg:
104332- if (!net_eq(net, &init_net))
104333- kfree(table);
104334+ kfree(table);
104335 err_alloc:
104336 return -ENOMEM;
104337 }
104338diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
104339index 5b7a1ed..d9da205 100644
104340--- a/net/ipv6/ping.c
104341+++ b/net/ipv6/ping.c
104342@@ -240,6 +240,24 @@ static struct pernet_operations ping_v6_net_ops = {
104343 };
104344 #endif
104345
104346+static struct pingv6_ops real_pingv6_ops = {
104347+ .ipv6_recv_error = ipv6_recv_error,
104348+ .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
104349+ .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
104350+ .icmpv6_err_convert = icmpv6_err_convert,
104351+ .ipv6_icmp_error = ipv6_icmp_error,
104352+ .ipv6_chk_addr = ipv6_chk_addr,
104353+};
104354+
104355+static struct pingv6_ops dummy_pingv6_ops = {
104356+ .ipv6_recv_error = dummy_ipv6_recv_error,
104357+ .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
104358+ .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
104359+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
104360+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
104361+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
104362+};
104363+
104364 int __init pingv6_init(void)
104365 {
104366 #ifdef CONFIG_PROC_FS
104367@@ -247,13 +265,7 @@ int __init pingv6_init(void)
104368 if (ret)
104369 return ret;
104370 #endif
104371- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
104372- pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
104373- pingv6_ops.ip6_datagram_recv_specific_ctl =
104374- ip6_datagram_recv_specific_ctl;
104375- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
104376- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
104377- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
104378+ pingv6_ops = &real_pingv6_ops;
104379 return inet6_register_protosw(&pingv6_protosw);
104380 }
104381
104382@@ -262,14 +274,9 @@ int __init pingv6_init(void)
104383 */
104384 void pingv6_exit(void)
104385 {
104386- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
104387- pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
104388- pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
104389- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
104390- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
104391- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
104392 #ifdef CONFIG_PROC_FS
104393 unregister_pernet_subsys(&ping_v6_net_ops);
104394 #endif
104395+ pingv6_ops = &dummy_pingv6_ops;
104396 inet6_unregister_protosw(&pingv6_protosw);
104397 }
104398diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
104399index 2d6f860..b0165f5 100644
104400--- a/net/ipv6/proc.c
104401+++ b/net/ipv6/proc.c
104402@@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
104403 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
104404 goto proc_snmp6_fail;
104405
104406- net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
104407+ net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
104408 if (!net->mib.proc_net_devsnmp6)
104409 goto proc_dev_snmp6_fail;
104410 return 0;
104411diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
104412index 39d4422..b0979547 100644
104413--- a/net/ipv6/raw.c
104414+++ b/net/ipv6/raw.c
104415@@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
104416 {
104417 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
104418 skb_checksum_complete(skb)) {
104419- atomic_inc(&sk->sk_drops);
104420+ atomic_inc_unchecked(&sk->sk_drops);
104421 kfree_skb(skb);
104422 return NET_RX_DROP;
104423 }
104424@@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
104425 struct raw6_sock *rp = raw6_sk(sk);
104426
104427 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
104428- atomic_inc(&sk->sk_drops);
104429+ atomic_inc_unchecked(&sk->sk_drops);
104430 kfree_skb(skb);
104431 return NET_RX_DROP;
104432 }
104433@@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
104434
104435 if (inet->hdrincl) {
104436 if (skb_checksum_complete(skb)) {
104437- atomic_inc(&sk->sk_drops);
104438+ atomic_inc_unchecked(&sk->sk_drops);
104439 kfree_skb(skb);
104440 return NET_RX_DROP;
104441 }
104442@@ -608,7 +608,7 @@ out:
104443 return err;
104444 }
104445
104446-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
104447+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
104448 struct flowi6 *fl6, struct dst_entry **dstp,
104449 unsigned int flags)
104450 {
104451@@ -914,12 +914,15 @@ do_confirm:
104452 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
104453 char __user *optval, int optlen)
104454 {
104455+ struct icmp6_filter filter;
104456+
104457 switch (optname) {
104458 case ICMPV6_FILTER:
104459 if (optlen > sizeof(struct icmp6_filter))
104460 optlen = sizeof(struct icmp6_filter);
104461- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
104462+ if (copy_from_user(&filter, optval, optlen))
104463 return -EFAULT;
104464+ raw6_sk(sk)->filter = filter;
104465 return 0;
104466 default:
104467 return -ENOPROTOOPT;
104468@@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
104469 char __user *optval, int __user *optlen)
104470 {
104471 int len;
104472+ struct icmp6_filter filter;
104473
104474 switch (optname) {
104475 case ICMPV6_FILTER:
104476@@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
104477 len = sizeof(struct icmp6_filter);
104478 if (put_user(len, optlen))
104479 return -EFAULT;
104480- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
104481+ filter = raw6_sk(sk)->filter;
104482+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
104483 return -EFAULT;
104484 return 0;
104485 default:
104486diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
104487index c6557d9..173e728 100644
104488--- a/net/ipv6/reassembly.c
104489+++ b/net/ipv6/reassembly.c
104490@@ -627,12 +627,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
104491
104492 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104493 {
104494- struct ctl_table *table;
104495+ ctl_table_no_const *table = NULL;
104496 struct ctl_table_header *hdr;
104497
104498- table = ip6_frags_ns_ctl_table;
104499 if (!net_eq(net, &init_net)) {
104500- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
104501+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
104502 if (table == NULL)
104503 goto err_alloc;
104504
104505@@ -646,9 +645,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104506 /* Don't export sysctls to unprivileged users */
104507 if (net->user_ns != &init_user_ns)
104508 table[0].procname = NULL;
104509- }
104510+ hdr = register_net_sysctl(net, "net/ipv6", table);
104511+ } else
104512+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
104513
104514- hdr = register_net_sysctl(net, "net/ipv6", table);
104515 if (hdr == NULL)
104516 goto err_reg;
104517
104518@@ -656,8 +656,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104519 return 0;
104520
104521 err_reg:
104522- if (!net_eq(net, &init_net))
104523- kfree(table);
104524+ kfree(table);
104525 err_alloc:
104526 return -ENOMEM;
104527 }
104528diff --git a/net/ipv6/route.c b/net/ipv6/route.c
104529index bafde82..af2c91f 100644
104530--- a/net/ipv6/route.c
104531+++ b/net/ipv6/route.c
104532@@ -2967,7 +2967,7 @@ struct ctl_table ipv6_route_table_template[] = {
104533
104534 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
104535 {
104536- struct ctl_table *table;
104537+ ctl_table_no_const *table;
104538
104539 table = kmemdup(ipv6_route_table_template,
104540 sizeof(ipv6_route_table_template),
104541diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
104542index ca1c7c4..37fba59 100644
104543--- a/net/ipv6/sit.c
104544+++ b/net/ipv6/sit.c
104545@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
104546 static void ipip6_dev_free(struct net_device *dev);
104547 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
104548 __be32 *v4dst);
104549-static struct rtnl_link_ops sit_link_ops __read_mostly;
104550+static struct rtnl_link_ops sit_link_ops;
104551
104552 static int sit_net_id __read_mostly;
104553 struct sit_net {
104554@@ -484,11 +484,11 @@ static void ipip6_tunnel_uninit(struct net_device *dev)
104555 */
104556 static int ipip6_err_gen_icmpv6_unreach(struct sk_buff *skb)
104557 {
104558- const struct iphdr *iph = (const struct iphdr *) skb->data;
104559+ int ihl = ((const struct iphdr *)skb->data)->ihl*4;
104560 struct rt6_info *rt;
104561 struct sk_buff *skb2;
104562
104563- if (!pskb_may_pull(skb, iph->ihl * 4 + sizeof(struct ipv6hdr) + 8))
104564+ if (!pskb_may_pull(skb, ihl + sizeof(struct ipv6hdr) + 8))
104565 return 1;
104566
104567 skb2 = skb_clone(skb, GFP_ATOMIC);
104568@@ -497,7 +497,7 @@ static int ipip6_err_gen_icmpv6_unreach(struct sk_buff *skb)
104569 return 1;
104570
104571 skb_dst_drop(skb2);
104572- skb_pull(skb2, iph->ihl * 4);
104573+ skb_pull(skb2, ihl);
104574 skb_reset_network_header(skb2);
104575
104576 rt = rt6_lookup(dev_net(skb->dev), &ipv6_hdr(skb2)->saddr, NULL, 0, 0);
104577@@ -1659,7 +1659,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
104578 unregister_netdevice_queue(dev, head);
104579 }
104580
104581-static struct rtnl_link_ops sit_link_ops __read_mostly = {
104582+static struct rtnl_link_ops sit_link_ops = {
104583 .kind = "sit",
104584 .maxtype = IFLA_IPTUN_MAX,
104585 .policy = ipip6_policy,
104586diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
104587index 0c56c93..ece50df 100644
104588--- a/net/ipv6/sysctl_net_ipv6.c
104589+++ b/net/ipv6/sysctl_net_ipv6.c
104590@@ -68,7 +68,7 @@ static struct ctl_table ipv6_rotable[] = {
104591
104592 static int __net_init ipv6_sysctl_net_init(struct net *net)
104593 {
104594- struct ctl_table *ipv6_table;
104595+ ctl_table_no_const *ipv6_table;
104596 struct ctl_table *ipv6_route_table;
104597 struct ctl_table *ipv6_icmp_table;
104598 int err;
104599diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
104600index 264c0f2..b6512c6 100644
104601--- a/net/ipv6/tcp_ipv6.c
104602+++ b/net/ipv6/tcp_ipv6.c
104603@@ -102,6 +102,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
104604 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
104605 }
104606
104607+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104608+extern int grsec_enable_blackhole;
104609+#endif
104610+
104611 static void tcp_v6_hash(struct sock *sk)
104612 {
104613 if (sk->sk_state != TCP_CLOSE) {
104614@@ -1333,6 +1337,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
104615 return 0;
104616
104617 reset:
104618+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104619+ if (!grsec_enable_blackhole)
104620+#endif
104621 tcp_v6_send_reset(sk, skb);
104622 discard:
104623 if (opt_skb)
104624@@ -1417,12 +1424,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
104625 TCP_SKB_CB(skb)->sacked = 0;
104626
104627 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
104628- if (!sk)
104629+ if (!sk) {
104630+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104631+ ret = 1;
104632+#endif
104633 goto no_tcp_socket;
104634+ }
104635
104636 process:
104637- if (sk->sk_state == TCP_TIME_WAIT)
104638+ if (sk->sk_state == TCP_TIME_WAIT) {
104639+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104640+ ret = 2;
104641+#endif
104642 goto do_time_wait;
104643+ }
104644
104645 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
104646 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
104647@@ -1479,6 +1494,10 @@ csum_error:
104648 bad_packet:
104649 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
104650 } else {
104651+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104652+ if (!grsec_enable_blackhole || (ret == 1 &&
104653+ (skb->dev->flags & IFF_LOOPBACK)))
104654+#endif
104655 tcp_v6_send_reset(NULL, skb);
104656 }
104657
104658diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
104659index 4836af8..0e52bbd 100644
104660--- a/net/ipv6/udp.c
104661+++ b/net/ipv6/udp.c
104662@@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
104663 udp_ipv6_hash_secret + net_hash_mix(net));
104664 }
104665
104666+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104667+extern int grsec_enable_blackhole;
104668+#endif
104669+
104670 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
104671 {
104672 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
104673@@ -434,7 +438,7 @@ try_again:
104674 if (unlikely(err)) {
104675 trace_kfree_skb(skb, udpv6_recvmsg);
104676 if (!peeked) {
104677- atomic_inc(&sk->sk_drops);
104678+ atomic_inc_unchecked(&sk->sk_drops);
104679 if (is_udp4)
104680 UDP_INC_STATS_USER(sock_net(sk),
104681 UDP_MIB_INERRORS,
104682@@ -701,7 +705,7 @@ csum_error:
104683 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
104684 drop:
104685 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
104686- atomic_inc(&sk->sk_drops);
104687+ atomic_inc_unchecked(&sk->sk_drops);
104688 kfree_skb(skb);
104689 return -1;
104690 }
104691@@ -740,7 +744,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
104692 if (likely(skb1 == NULL))
104693 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
104694 if (!skb1) {
104695- atomic_inc(&sk->sk_drops);
104696+ atomic_inc_unchecked(&sk->sk_drops);
104697 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
104698 IS_UDPLITE(sk));
104699 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
104700@@ -915,6 +919,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
104701 goto csum_error;
104702
104703 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
104704+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104705+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
104706+#endif
104707 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
104708
104709 kfree_skb(skb);
104710diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
104711index 2a0bbda..fcd5396 100644
104712--- a/net/ipv6/xfrm6_policy.c
104713+++ b/net/ipv6/xfrm6_policy.c
104714@@ -130,8 +130,8 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104715 {
104716 struct flowi6 *fl6 = &fl->u.ip6;
104717 int onlyproto = 0;
104718- u16 offset = skb_network_header_len(skb);
104719 const struct ipv6hdr *hdr = ipv6_hdr(skb);
104720+ u16 offset = sizeof(*hdr);
104721 struct ipv6_opt_hdr *exthdr;
104722 const unsigned char *nh = skb_network_header(skb);
104723 u8 nexthdr = nh[IP6CB(skb)->nhoff];
104724@@ -170,8 +170,10 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104725 case IPPROTO_DCCP:
104726 if (!onlyproto && (nh + offset + 4 < skb->data ||
104727 pskb_may_pull(skb, nh + offset + 4 - skb->data))) {
104728- __be16 *ports = (__be16 *)exthdr;
104729+ __be16 *ports;
104730
104731+ nh = skb_network_header(skb);
104732+ ports = (__be16 *)(nh + offset);
104733 fl6->fl6_sport = ports[!!reverse];
104734 fl6->fl6_dport = ports[!reverse];
104735 }
104736@@ -180,8 +182,10 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104737
104738 case IPPROTO_ICMPV6:
104739 if (!onlyproto && pskb_may_pull(skb, nh + offset + 2 - skb->data)) {
104740- u8 *icmp = (u8 *)exthdr;
104741+ u8 *icmp;
104742
104743+ nh = skb_network_header(skb);
104744+ icmp = (u8 *)(nh + offset);
104745 fl6->fl6_icmp_type = icmp[0];
104746 fl6->fl6_icmp_code = icmp[1];
104747 }
104748@@ -192,8 +196,9 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104749 case IPPROTO_MH:
104750 if (!onlyproto && pskb_may_pull(skb, nh + offset + 3 - skb->data)) {
104751 struct ip6_mh *mh;
104752- mh = (struct ip6_mh *)exthdr;
104753
104754+ nh = skb_network_header(skb);
104755+ mh = (struct ip6_mh *)(nh + offset);
104756 fl6->fl6_mh_type = mh->ip6mh_type;
104757 }
104758 fl6->flowi6_proto = nexthdr;
104759@@ -212,11 +217,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104760 }
104761 }
104762
104763-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
104764+static int xfrm6_garbage_collect(struct dst_ops *ops)
104765 {
104766 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
104767
104768- xfrm6_policy_afinfo.garbage_collect(net);
104769+ xfrm_garbage_collect_deferred(net);
104770 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
104771 }
104772
104773@@ -329,19 +334,19 @@ static struct ctl_table xfrm6_policy_table[] = {
104774
104775 static int __net_init xfrm6_net_init(struct net *net)
104776 {
104777- struct ctl_table *table;
104778+ ctl_table_no_const *table = NULL;
104779 struct ctl_table_header *hdr;
104780
104781- table = xfrm6_policy_table;
104782 if (!net_eq(net, &init_net)) {
104783- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
104784+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
104785 if (!table)
104786 goto err_alloc;
104787
104788 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
104789- }
104790+ hdr = register_net_sysctl(net, "net/ipv6", table);
104791+ } else
104792+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
104793
104794- hdr = register_net_sysctl(net, "net/ipv6", table);
104795 if (!hdr)
104796 goto err_reg;
104797
104798@@ -349,8 +354,7 @@ static int __net_init xfrm6_net_init(struct net *net)
104799 return 0;
104800
104801 err_reg:
104802- if (!net_eq(net, &init_net))
104803- kfree(table);
104804+ kfree(table);
104805 err_alloc:
104806 return -ENOMEM;
104807 }
104808diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
104809index e15c16a..7cf07aa 100644
104810--- a/net/ipx/ipx_proc.c
104811+++ b/net/ipx/ipx_proc.c
104812@@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
104813 struct proc_dir_entry *p;
104814 int rc = -ENOMEM;
104815
104816- ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
104817+ ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
104818
104819 if (!ipx_proc_dir)
104820 goto out;
104821diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
104822index 61ceb4c..e788eb8 100644
104823--- a/net/irda/ircomm/ircomm_tty.c
104824+++ b/net/irda/ircomm/ircomm_tty.c
104825@@ -317,10 +317,10 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104826 add_wait_queue(&port->open_wait, &wait);
104827
104828 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
104829- __FILE__, __LINE__, tty->driver->name, port->count);
104830+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104831
104832 spin_lock_irqsave(&port->lock, flags);
104833- port->count--;
104834+ atomic_dec(&port->count);
104835 port->blocked_open++;
104836 spin_unlock_irqrestore(&port->lock, flags);
104837
104838@@ -355,7 +355,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104839 }
104840
104841 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
104842- __FILE__, __LINE__, tty->driver->name, port->count);
104843+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104844
104845 schedule();
104846 }
104847@@ -365,12 +365,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104848
104849 spin_lock_irqsave(&port->lock, flags);
104850 if (!tty_hung_up_p(filp))
104851- port->count++;
104852+ atomic_inc(&port->count);
104853 port->blocked_open--;
104854 spin_unlock_irqrestore(&port->lock, flags);
104855
104856 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
104857- __FILE__, __LINE__, tty->driver->name, port->count);
104858+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104859
104860 if (!retval)
104861 port->flags |= ASYNC_NORMAL_ACTIVE;
104862@@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
104863
104864 /* ++ is not atomic, so this should be protected - Jean II */
104865 spin_lock_irqsave(&self->port.lock, flags);
104866- self->port.count++;
104867+ atomic_inc(&self->port.count);
104868 spin_unlock_irqrestore(&self->port.lock, flags);
104869 tty_port_tty_set(&self->port, tty);
104870
104871 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
104872- self->line, self->port.count);
104873+ self->line, atomic_read(&self->port.count));
104874
104875 /* Not really used by us, but lets do it anyway */
104876 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
104877@@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
104878 tty_kref_put(port->tty);
104879 }
104880 port->tty = NULL;
104881- port->count = 0;
104882+ atomic_set(&port->count, 0);
104883 spin_unlock_irqrestore(&port->lock, flags);
104884
104885 wake_up_interruptible(&port->open_wait);
104886@@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
104887 seq_putc(m, '\n');
104888
104889 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
104890- seq_printf(m, "Open count: %d\n", self->port.count);
104891+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
104892 seq_printf(m, "Max data size: %d\n", self->max_data_size);
104893 seq_printf(m, "Max header size: %d\n", self->max_header_size);
104894
104895diff --git a/net/irda/irproc.c b/net/irda/irproc.c
104896index b9ac598..f88cc56 100644
104897--- a/net/irda/irproc.c
104898+++ b/net/irda/irproc.c
104899@@ -66,7 +66,7 @@ void __init irda_proc_register(void)
104900 {
104901 int i;
104902
104903- proc_irda = proc_mkdir("irda", init_net.proc_net);
104904+ proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
104905 if (proc_irda == NULL)
104906 return;
104907
104908diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
104909index a089b6b..3ca3b60 100644
104910--- a/net/iucv/af_iucv.c
104911+++ b/net/iucv/af_iucv.c
104912@@ -686,10 +686,10 @@ static void __iucv_auto_name(struct iucv_sock *iucv)
104913 {
104914 char name[12];
104915
104916- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
104917+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104918 while (__iucv_get_sock_by_name(name)) {
104919 sprintf(name, "%08x",
104920- atomic_inc_return(&iucv_sk_list.autobind_name));
104921+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104922 }
104923 memcpy(iucv->src_name, name, 8);
104924 }
104925diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
104926index da78793..bdd78cf 100644
104927--- a/net/iucv/iucv.c
104928+++ b/net/iucv/iucv.c
104929@@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
104930 return NOTIFY_OK;
104931 }
104932
104933-static struct notifier_block __refdata iucv_cpu_notifier = {
104934+static struct notifier_block iucv_cpu_notifier = {
104935 .notifier_call = iucv_cpu_notify,
104936 };
104937
104938diff --git a/net/key/af_key.c b/net/key/af_key.c
104939index 1847ec4..26ef732 100644
104940--- a/net/key/af_key.c
104941+++ b/net/key/af_key.c
104942@@ -3049,10 +3049,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
104943 static u32 get_acqseq(void)
104944 {
104945 u32 res;
104946- static atomic_t acqseq;
104947+ static atomic_unchecked_t acqseq;
104948
104949 do {
104950- res = atomic_inc_return(&acqseq);
104951+ res = atomic_inc_return_unchecked(&acqseq);
104952 } while (!res);
104953 return res;
104954 }
104955diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
104956index edb78e6..8dc654a 100644
104957--- a/net/l2tp/l2tp_eth.c
104958+++ b/net/l2tp/l2tp_eth.c
104959@@ -42,12 +42,12 @@ struct l2tp_eth {
104960 struct sock *tunnel_sock;
104961 struct l2tp_session *session;
104962 struct list_head list;
104963- atomic_long_t tx_bytes;
104964- atomic_long_t tx_packets;
104965- atomic_long_t tx_dropped;
104966- atomic_long_t rx_bytes;
104967- atomic_long_t rx_packets;
104968- atomic_long_t rx_errors;
104969+ atomic_long_unchecked_t tx_bytes;
104970+ atomic_long_unchecked_t tx_packets;
104971+ atomic_long_unchecked_t tx_dropped;
104972+ atomic_long_unchecked_t rx_bytes;
104973+ atomic_long_unchecked_t rx_packets;
104974+ atomic_long_unchecked_t rx_errors;
104975 };
104976
104977 /* via l2tp_session_priv() */
104978@@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
104979 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
104980
104981 if (likely(ret == NET_XMIT_SUCCESS)) {
104982- atomic_long_add(len, &priv->tx_bytes);
104983- atomic_long_inc(&priv->tx_packets);
104984+ atomic_long_add_unchecked(len, &priv->tx_bytes);
104985+ atomic_long_inc_unchecked(&priv->tx_packets);
104986 } else {
104987- atomic_long_inc(&priv->tx_dropped);
104988+ atomic_long_inc_unchecked(&priv->tx_dropped);
104989 }
104990 return NETDEV_TX_OK;
104991 }
104992@@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
104993 {
104994 struct l2tp_eth *priv = netdev_priv(dev);
104995
104996- stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
104997- stats->tx_packets = atomic_long_read(&priv->tx_packets);
104998- stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
104999- stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
105000- stats->rx_packets = atomic_long_read(&priv->rx_packets);
105001- stats->rx_errors = atomic_long_read(&priv->rx_errors);
105002+ stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
105003+ stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
105004+ stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
105005+ stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
105006+ stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
105007+ stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
105008 return stats;
105009 }
105010
105011@@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
105012 nf_reset(skb);
105013
105014 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
105015- atomic_long_inc(&priv->rx_packets);
105016- atomic_long_add(data_len, &priv->rx_bytes);
105017+ atomic_long_inc_unchecked(&priv->rx_packets);
105018+ atomic_long_add_unchecked(data_len, &priv->rx_bytes);
105019 } else {
105020- atomic_long_inc(&priv->rx_errors);
105021+ atomic_long_inc_unchecked(&priv->rx_errors);
105022 }
105023 return;
105024
105025 error:
105026- atomic_long_inc(&priv->rx_errors);
105027+ atomic_long_inc_unchecked(&priv->rx_errors);
105028 kfree_skb(skb);
105029 }
105030
105031diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
105032index 1a3c7e0..80f8b0c 100644
105033--- a/net/llc/llc_proc.c
105034+++ b/net/llc/llc_proc.c
105035@@ -247,7 +247,7 @@ int __init llc_proc_init(void)
105036 int rc = -ENOMEM;
105037 struct proc_dir_entry *p;
105038
105039- llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
105040+ llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
105041 if (!llc_proc_dir)
105042 goto out;
105043
105044diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
105045index 927b4ea..88a30e2 100644
105046--- a/net/mac80211/cfg.c
105047+++ b/net/mac80211/cfg.c
105048@@ -540,7 +540,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
105049 ret = ieee80211_vif_use_channel(sdata, chandef,
105050 IEEE80211_CHANCTX_EXCLUSIVE);
105051 }
105052- } else if (local->open_count == local->monitors) {
105053+ } else if (local_read(&local->open_count) == local->monitors) {
105054 local->_oper_chandef = *chandef;
105055 ieee80211_hw_config(local, 0);
105056 }
105057@@ -3286,7 +3286,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
105058 else
105059 local->probe_req_reg--;
105060
105061- if (!local->open_count)
105062+ if (!local_read(&local->open_count))
105063 break;
105064
105065 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
105066@@ -3420,8 +3420,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
105067 if (chanctx_conf) {
105068 *chandef = chanctx_conf->def;
105069 ret = 0;
105070- } else if (local->open_count > 0 &&
105071- local->open_count == local->monitors &&
105072+ } else if (local_read(&local->open_count) > 0 &&
105073+ local_read(&local->open_count) == local->monitors &&
105074 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
105075 if (local->use_chanctx)
105076 *chandef = local->monitor_chandef;
105077diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
105078index 5d102b5..6199fca 100644
105079--- a/net/mac80211/ieee80211_i.h
105080+++ b/net/mac80211/ieee80211_i.h
105081@@ -28,6 +28,7 @@
105082 #include <net/ieee80211_radiotap.h>
105083 #include <net/cfg80211.h>
105084 #include <net/mac80211.h>
105085+#include <asm/local.h>
105086 #include "key.h"
105087 #include "sta_info.h"
105088 #include "debug.h"
105089@@ -1055,7 +1056,7 @@ struct ieee80211_local {
105090 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
105091 spinlock_t queue_stop_reason_lock;
105092
105093- int open_count;
105094+ local_t open_count;
105095 int monitors, cooked_mntrs;
105096 /* number of interfaces with corresponding FIF_ flags */
105097 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
105098diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
105099index 3538e5e..0aa7879 100644
105100--- a/net/mac80211/iface.c
105101+++ b/net/mac80211/iface.c
105102@@ -531,7 +531,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
105103 break;
105104 }
105105
105106- if (local->open_count == 0) {
105107+ if (local_read(&local->open_count) == 0) {
105108 res = drv_start(local);
105109 if (res)
105110 goto err_del_bss;
105111@@ -578,7 +578,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
105112 res = drv_add_interface(local, sdata);
105113 if (res)
105114 goto err_stop;
105115- } else if (local->monitors == 0 && local->open_count == 0) {
105116+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
105117 res = ieee80211_add_virtual_monitor(local);
105118 if (res)
105119 goto err_stop;
105120@@ -687,7 +687,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
105121 atomic_inc(&local->iff_promiscs);
105122
105123 if (coming_up)
105124- local->open_count++;
105125+ local_inc(&local->open_count);
105126
105127 if (hw_reconf_flags)
105128 ieee80211_hw_config(local, hw_reconf_flags);
105129@@ -725,7 +725,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
105130 err_del_interface:
105131 drv_remove_interface(local, sdata);
105132 err_stop:
105133- if (!local->open_count)
105134+ if (!local_read(&local->open_count))
105135 drv_stop(local);
105136 err_del_bss:
105137 sdata->bss = NULL;
105138@@ -891,7 +891,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
105139 }
105140
105141 if (going_down)
105142- local->open_count--;
105143+ local_dec(&local->open_count);
105144
105145 switch (sdata->vif.type) {
105146 case NL80211_IFTYPE_AP_VLAN:
105147@@ -952,7 +952,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
105148 }
105149 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
105150
105151- if (local->open_count == 0)
105152+ if (local_read(&local->open_count) == 0)
105153 ieee80211_clear_tx_pending(local);
105154
105155 /*
105156@@ -995,7 +995,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
105157 if (cancel_scan)
105158 flush_delayed_work(&local->scan_work);
105159
105160- if (local->open_count == 0) {
105161+ if (local_read(&local->open_count) == 0) {
105162 ieee80211_stop_device(local);
105163
105164 /* no reconfiguring after stop! */
105165@@ -1006,7 +1006,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
105166 ieee80211_configure_filter(local);
105167 ieee80211_hw_config(local, hw_reconf_flags);
105168
105169- if (local->monitors == local->open_count)
105170+ if (local->monitors == local_read(&local->open_count))
105171 ieee80211_add_virtual_monitor(local);
105172 }
105173
105174diff --git a/net/mac80211/main.c b/net/mac80211/main.c
105175index e0ab432..36b7b94 100644
105176--- a/net/mac80211/main.c
105177+++ b/net/mac80211/main.c
105178@@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
105179 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
105180 IEEE80211_CONF_CHANGE_POWER);
105181
105182- if (changed && local->open_count) {
105183+ if (changed && local_read(&local->open_count)) {
105184 ret = drv_config(local, changed);
105185 /*
105186 * Goal:
105187diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
105188index 4c5192e..04cc0d8 100644
105189--- a/net/mac80211/pm.c
105190+++ b/net/mac80211/pm.c
105191@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
105192 struct ieee80211_sub_if_data *sdata;
105193 struct sta_info *sta;
105194
105195- if (!local->open_count)
105196+ if (!local_read(&local->open_count))
105197 goto suspend;
105198
105199 ieee80211_scan_cancel(local);
105200@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
105201 cancel_work_sync(&local->dynamic_ps_enable_work);
105202 del_timer_sync(&local->dynamic_ps_timer);
105203
105204- local->wowlan = wowlan && local->open_count;
105205+ local->wowlan = wowlan && local_read(&local->open_count);
105206 if (local->wowlan) {
105207 int err = drv_suspend(local, wowlan);
105208 if (err < 0) {
105209@@ -125,7 +125,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
105210 WARN_ON(!list_empty(&local->chanctx_list));
105211
105212 /* stop hardware - this must stop RX */
105213- if (local->open_count)
105214+ if (local_read(&local->open_count))
105215 ieee80211_stop_device(local);
105216
105217 suspend:
105218diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
105219index 6081329..ab23834 100644
105220--- a/net/mac80211/rate.c
105221+++ b/net/mac80211/rate.c
105222@@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
105223
105224 ASSERT_RTNL();
105225
105226- if (local->open_count)
105227+ if (local_read(&local->open_count))
105228 return -EBUSY;
105229
105230 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
105231diff --git a/net/mac80211/util.c b/net/mac80211/util.c
105232index 725af7a..a21a20a 100644
105233--- a/net/mac80211/util.c
105234+++ b/net/mac80211/util.c
105235@@ -1643,7 +1643,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
105236 }
105237 #endif
105238 /* everything else happens only if HW was up & running */
105239- if (!local->open_count)
105240+ if (!local_read(&local->open_count))
105241 goto wake_up;
105242
105243 /*
105244@@ -1869,7 +1869,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
105245 local->in_reconfig = false;
105246 barrier();
105247
105248- if (local->monitors == local->open_count && local->monitors > 0)
105249+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
105250 ieee80211_add_virtual_monitor(local);
105251
105252 /*
105253diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
105254index 6d77cce..36e2fc3 100644
105255--- a/net/netfilter/Kconfig
105256+++ b/net/netfilter/Kconfig
105257@@ -1096,6 +1096,16 @@ config NETFILTER_XT_MATCH_ESP
105258
105259 To compile it as a module, choose M here. If unsure, say N.
105260
105261+config NETFILTER_XT_MATCH_GRADM
105262+ tristate '"gradm" match support'
105263+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
105264+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
105265+ ---help---
105266+ The gradm match allows to match on grsecurity RBAC being enabled.
105267+ It is useful when iptables rules are applied early on bootup to
105268+ prevent connections to the machine (except from a trusted host)
105269+ while the RBAC system is disabled.
105270+
105271 config NETFILTER_XT_MATCH_HASHLIMIT
105272 tristate '"hashlimit" match support'
105273 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
105274diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
105275index fad5fdb..ba3672a 100644
105276--- a/net/netfilter/Makefile
105277+++ b/net/netfilter/Makefile
105278@@ -136,6 +136,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
105279 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
105280 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
105281 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
105282+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
105283 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
105284 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
105285 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
105286diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
105287index 6582dce..a911da7 100644
105288--- a/net/netfilter/ipset/ip_set_core.c
105289+++ b/net/netfilter/ipset/ip_set_core.c
105290@@ -1921,7 +1921,7 @@ done:
105291 return ret;
105292 }
105293
105294-static struct nf_sockopt_ops so_set __read_mostly = {
105295+static struct nf_sockopt_ops so_set = {
105296 .pf = PF_INET,
105297 .get_optmin = SO_IP_SET,
105298 .get_optmax = SO_IP_SET + 1,
105299diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
105300index 610e19c..08d0c3f 100644
105301--- a/net/netfilter/ipvs/ip_vs_conn.c
105302+++ b/net/netfilter/ipvs/ip_vs_conn.c
105303@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
105304 /* Increase the refcnt counter of the dest */
105305 ip_vs_dest_hold(dest);
105306
105307- conn_flags = atomic_read(&dest->conn_flags);
105308+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
105309 if (cp->protocol != IPPROTO_UDP)
105310 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
105311 flags = cp->flags;
105312@@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
105313
105314 cp->control = NULL;
105315 atomic_set(&cp->n_control, 0);
105316- atomic_set(&cp->in_pkts, 0);
105317+ atomic_set_unchecked(&cp->in_pkts, 0);
105318
105319 cp->packet_xmit = NULL;
105320 cp->app = NULL;
105321@@ -1187,7 +1187,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
105322
105323 /* Don't drop the entry if its number of incoming packets is not
105324 located in [0, 8] */
105325- i = atomic_read(&cp->in_pkts);
105326+ i = atomic_read_unchecked(&cp->in_pkts);
105327 if (i > 8 || i < 0) return 0;
105328
105329 if (!todrop_rate[i]) return 0;
105330diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
105331index 5c34e8d..0d8eb7f 100644
105332--- a/net/netfilter/ipvs/ip_vs_core.c
105333+++ b/net/netfilter/ipvs/ip_vs_core.c
105334@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
105335 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
105336 /* do not touch skb anymore */
105337
105338- atomic_inc(&cp->in_pkts);
105339+ atomic_inc_unchecked(&cp->in_pkts);
105340 ip_vs_conn_put(cp);
105341 return ret;
105342 }
105343@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
105344 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
105345 pkts = sysctl_sync_threshold(ipvs);
105346 else
105347- pkts = atomic_add_return(1, &cp->in_pkts);
105348+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105349
105350 if (ipvs->sync_state & IP_VS_STATE_MASTER)
105351 ip_vs_sync_conn(net, cp, pkts);
105352diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
105353index fd3f444..ab28fa24 100644
105354--- a/net/netfilter/ipvs/ip_vs_ctl.c
105355+++ b/net/netfilter/ipvs/ip_vs_ctl.c
105356@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
105357 */
105358 ip_vs_rs_hash(ipvs, dest);
105359 }
105360- atomic_set(&dest->conn_flags, conn_flags);
105361+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
105362
105363 /* bind the service */
105364 old_svc = rcu_dereference_protected(dest->svc, 1);
105365@@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
105366 * align with netns init in ip_vs_control_net_init()
105367 */
105368
105369-static struct ctl_table vs_vars[] = {
105370+static ctl_table_no_const vs_vars[] __read_only = {
105371 {
105372 .procname = "amemthresh",
105373 .maxlen = sizeof(int),
105374@@ -1989,7 +1989,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
105375 " %-7s %-6d %-10d %-10d\n",
105376 &dest->addr.in6,
105377 ntohs(dest->port),
105378- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
105379+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
105380 atomic_read(&dest->weight),
105381 atomic_read(&dest->activeconns),
105382 atomic_read(&dest->inactconns));
105383@@ -2000,7 +2000,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
105384 "%-7s %-6d %-10d %-10d\n",
105385 ntohl(dest->addr.ip),
105386 ntohs(dest->port),
105387- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
105388+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
105389 atomic_read(&dest->weight),
105390 atomic_read(&dest->activeconns),
105391 atomic_read(&dest->inactconns));
105392@@ -2471,7 +2471,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
105393
105394 entry.addr = dest->addr.ip;
105395 entry.port = dest->port;
105396- entry.conn_flags = atomic_read(&dest->conn_flags);
105397+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
105398 entry.weight = atomic_read(&dest->weight);
105399 entry.u_threshold = dest->u_threshold;
105400 entry.l_threshold = dest->l_threshold;
105401@@ -3010,7 +3010,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
105402 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
105403 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
105404 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
105405- (atomic_read(&dest->conn_flags) &
105406+ (atomic_read_unchecked(&dest->conn_flags) &
105407 IP_VS_CONN_F_FWD_MASK)) ||
105408 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
105409 atomic_read(&dest->weight)) ||
105410@@ -3600,7 +3600,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
105411 {
105412 int idx;
105413 struct netns_ipvs *ipvs = net_ipvs(net);
105414- struct ctl_table *tbl;
105415+ ctl_table_no_const *tbl;
105416
105417 atomic_set(&ipvs->dropentry, 0);
105418 spin_lock_init(&ipvs->dropentry_lock);
105419diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
105420index 547ff33..c8c8117 100644
105421--- a/net/netfilter/ipvs/ip_vs_lblc.c
105422+++ b/net/netfilter/ipvs/ip_vs_lblc.c
105423@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
105424 * IPVS LBLC sysctl table
105425 */
105426 #ifdef CONFIG_SYSCTL
105427-static struct ctl_table vs_vars_table[] = {
105428+static ctl_table_no_const vs_vars_table[] __read_only = {
105429 {
105430 .procname = "lblc_expiration",
105431 .data = NULL,
105432diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
105433index 3f21a2f..a112e85 100644
105434--- a/net/netfilter/ipvs/ip_vs_lblcr.c
105435+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
105436@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
105437 * IPVS LBLCR sysctl table
105438 */
105439
105440-static struct ctl_table vs_vars_table[] = {
105441+static ctl_table_no_const vs_vars_table[] __read_only = {
105442 {
105443 .procname = "lblcr_expiration",
105444 .data = NULL,
105445diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
105446index eadffb2..c2feeae 100644
105447--- a/net/netfilter/ipvs/ip_vs_sync.c
105448+++ b/net/netfilter/ipvs/ip_vs_sync.c
105449@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
105450 cp = cp->control;
105451 if (cp) {
105452 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
105453- pkts = atomic_add_return(1, &cp->in_pkts);
105454+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105455 else
105456 pkts = sysctl_sync_threshold(ipvs);
105457 ip_vs_sync_conn(net, cp->control, pkts);
105458@@ -771,7 +771,7 @@ control:
105459 if (!cp)
105460 return;
105461 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
105462- pkts = atomic_add_return(1, &cp->in_pkts);
105463+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105464 else
105465 pkts = sysctl_sync_threshold(ipvs);
105466 goto sloop;
105467@@ -894,7 +894,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
105468
105469 if (opt)
105470 memcpy(&cp->in_seq, opt, sizeof(*opt));
105471- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
105472+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
105473 cp->state = state;
105474 cp->old_state = cp->state;
105475 /*
105476diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
105477index 56896a4..dfe3806 100644
105478--- a/net/netfilter/ipvs/ip_vs_xmit.c
105479+++ b/net/netfilter/ipvs/ip_vs_xmit.c
105480@@ -1114,7 +1114,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
105481 else
105482 rc = NF_ACCEPT;
105483 /* do not touch skb anymore */
105484- atomic_inc(&cp->in_pkts);
105485+ atomic_inc_unchecked(&cp->in_pkts);
105486 goto out;
105487 }
105488
105489@@ -1206,7 +1206,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
105490 else
105491 rc = NF_ACCEPT;
105492 /* do not touch skb anymore */
105493- atomic_inc(&cp->in_pkts);
105494+ atomic_inc_unchecked(&cp->in_pkts);
105495 goto out;
105496 }
105497
105498diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
105499index a4b5e2a..13b1de3 100644
105500--- a/net/netfilter/nf_conntrack_acct.c
105501+++ b/net/netfilter/nf_conntrack_acct.c
105502@@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
105503 #ifdef CONFIG_SYSCTL
105504 static int nf_conntrack_acct_init_sysctl(struct net *net)
105505 {
105506- struct ctl_table *table;
105507+ ctl_table_no_const *table;
105508
105509 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
105510 GFP_KERNEL);
105511diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
105512index de88c4a..ec84234 100644
105513--- a/net/netfilter/nf_conntrack_core.c
105514+++ b/net/netfilter/nf_conntrack_core.c
105515@@ -1739,6 +1739,10 @@ void nf_conntrack_init_end(void)
105516 #define DYING_NULLS_VAL ((1<<30)+1)
105517 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
105518
105519+#ifdef CONFIG_GRKERNSEC_HIDESYM
105520+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
105521+#endif
105522+
105523 int nf_conntrack_init_net(struct net *net)
105524 {
105525 int ret = -ENOMEM;
105526@@ -1764,7 +1768,11 @@ int nf_conntrack_init_net(struct net *net)
105527 if (!net->ct.stat)
105528 goto err_pcpu_lists;
105529
105530+#ifdef CONFIG_GRKERNSEC_HIDESYM
105531+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
105532+#else
105533 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
105534+#endif
105535 if (!net->ct.slabname)
105536 goto err_slabname;
105537
105538diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
105539index 4e78c57..ec8fb74 100644
105540--- a/net/netfilter/nf_conntrack_ecache.c
105541+++ b/net/netfilter/nf_conntrack_ecache.c
105542@@ -264,7 +264,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
105543 #ifdef CONFIG_SYSCTL
105544 static int nf_conntrack_event_init_sysctl(struct net *net)
105545 {
105546- struct ctl_table *table;
105547+ ctl_table_no_const *table;
105548
105549 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
105550 GFP_KERNEL);
105551diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
105552index 5b3eae7..dd4b8fe 100644
105553--- a/net/netfilter/nf_conntrack_helper.c
105554+++ b/net/netfilter/nf_conntrack_helper.c
105555@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
105556
105557 static int nf_conntrack_helper_init_sysctl(struct net *net)
105558 {
105559- struct ctl_table *table;
105560+ ctl_table_no_const *table;
105561
105562 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
105563 GFP_KERNEL);
105564diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
105565index b65d586..beec902 100644
105566--- a/net/netfilter/nf_conntrack_proto.c
105567+++ b/net/netfilter/nf_conntrack_proto.c
105568@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
105569
105570 static void
105571 nf_ct_unregister_sysctl(struct ctl_table_header **header,
105572- struct ctl_table **table,
105573+ ctl_table_no_const **table,
105574 unsigned int users)
105575 {
105576 if (users > 0)
105577diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
105578index f641751..d3c5b51 100644
105579--- a/net/netfilter/nf_conntrack_standalone.c
105580+++ b/net/netfilter/nf_conntrack_standalone.c
105581@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
105582
105583 static int nf_conntrack_standalone_init_sysctl(struct net *net)
105584 {
105585- struct ctl_table *table;
105586+ ctl_table_no_const *table;
105587
105588 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
105589 GFP_KERNEL);
105590diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
105591index 7a394df..bd91a8a 100644
105592--- a/net/netfilter/nf_conntrack_timestamp.c
105593+++ b/net/netfilter/nf_conntrack_timestamp.c
105594@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
105595 #ifdef CONFIG_SYSCTL
105596 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
105597 {
105598- struct ctl_table *table;
105599+ ctl_table_no_const *table;
105600
105601 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
105602 GFP_KERNEL);
105603diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
105604index daad602..384be13 100644
105605--- a/net/netfilter/nf_log.c
105606+++ b/net/netfilter/nf_log.c
105607@@ -353,7 +353,7 @@ static const struct file_operations nflog_file_ops = {
105608
105609 #ifdef CONFIG_SYSCTL
105610 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
105611-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
105612+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
105613
105614 static int nf_log_proc_dostring(struct ctl_table *table, int write,
105615 void __user *buffer, size_t *lenp, loff_t *ppos)
105616@@ -384,14 +384,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
105617 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
105618 mutex_unlock(&nf_log_mutex);
105619 } else {
105620+ ctl_table_no_const nf_log_table = *table;
105621+
105622 mutex_lock(&nf_log_mutex);
105623 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
105624 lockdep_is_held(&nf_log_mutex));
105625 if (!logger)
105626- table->data = "NONE";
105627+ nf_log_table.data = "NONE";
105628 else
105629- table->data = logger->name;
105630- r = proc_dostring(table, write, buffer, lenp, ppos);
105631+ nf_log_table.data = logger->name;
105632+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
105633 mutex_unlock(&nf_log_mutex);
105634 }
105635
105636diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
105637index c68c1e5..8b5d670 100644
105638--- a/net/netfilter/nf_sockopt.c
105639+++ b/net/netfilter/nf_sockopt.c
105640@@ -43,7 +43,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
105641 }
105642 }
105643
105644- list_add(&reg->list, &nf_sockopts);
105645+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
105646 out:
105647 mutex_unlock(&nf_sockopt_mutex);
105648 return ret;
105649@@ -53,7 +53,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
105650 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
105651 {
105652 mutex_lock(&nf_sockopt_mutex);
105653- list_del(&reg->list);
105654+ pax_list_del((struct list_head *)&reg->list);
105655 mutex_unlock(&nf_sockopt_mutex);
105656 }
105657 EXPORT_SYMBOL(nf_unregister_sockopt);
105658diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
105659index 3250735..1fac969 100644
105660--- a/net/netfilter/nfnetlink_log.c
105661+++ b/net/netfilter/nfnetlink_log.c
105662@@ -80,7 +80,7 @@ static int nfnl_log_net_id __read_mostly;
105663 struct nfnl_log_net {
105664 spinlock_t instances_lock;
105665 struct hlist_head instance_table[INSTANCE_BUCKETS];
105666- atomic_t global_seq;
105667+ atomic_unchecked_t global_seq;
105668 };
105669
105670 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
105671@@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
105672 /* global sequence number */
105673 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
105674 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
105675- htonl(atomic_inc_return(&log->global_seq))))
105676+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
105677 goto nla_put_failure;
105678
105679 if (data_len) {
105680diff --git a/net/netfilter/nfnetlink_queue_core.c b/net/netfilter/nfnetlink_queue_core.c
105681index 108120f..5b169db 100644
105682--- a/net/netfilter/nfnetlink_queue_core.c
105683+++ b/net/netfilter/nfnetlink_queue_core.c
105684@@ -665,7 +665,7 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)
105685 * returned by nf_queue. For instance, callers rely on -ECANCELED to
105686 * mean 'ignore this hook'.
105687 */
105688- if (IS_ERR(segs))
105689+ if (IS_ERR_OR_NULL(segs))
105690 goto out_err;
105691 queued = 0;
105692 err = 0;
105693diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
105694index 5b5ab9e..fc1015c 100644
105695--- a/net/netfilter/nft_compat.c
105696+++ b/net/netfilter/nft_compat.c
105697@@ -225,7 +225,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
105698 /* We want to reuse existing compat_to_user */
105699 old_fs = get_fs();
105700 set_fs(KERNEL_DS);
105701- t->compat_to_user(out, in);
105702+ t->compat_to_user((void __force_user *)out, in);
105703 set_fs(old_fs);
105704 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
105705 kfree(out);
105706@@ -421,7 +421,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
105707 /* We want to reuse existing compat_to_user */
105708 old_fs = get_fs();
105709 set_fs(KERNEL_DS);
105710- m->compat_to_user(out, in);
105711+ m->compat_to_user((void __force_user *)out, in);
105712 set_fs(old_fs);
105713 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
105714 kfree(out);
105715diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
105716new file mode 100644
105717index 0000000..c566332
105718--- /dev/null
105719+++ b/net/netfilter/xt_gradm.c
105720@@ -0,0 +1,51 @@
105721+/*
105722+ * gradm match for netfilter
105723